H2O randomForest列/特征选择

时间:2017-03-24 15:07:05

标签: random-forest h2o

在h2o.randomForest中,假设我有5个输入要素x = c(“A”,“B”,“C”,“D”,“E”),无论如何都要强制算法总是选择A,B和其余功能之一?

1 个答案:

答案 0 :(得分:0)

在这种情况下,h2o.randomForest只是要求您传递正确的x(用于预测的列列表)和y(要进行预测的列名称),因此您将传递的任何内容都将用作输入。

你问的是一个特定于python的问题。您希望如何传递为其编写逻辑所需的列列表。您可以定义以下函数并根据需要使用它。

import random
myframe = ["a","b","c","d","e"] 
//You can also set myframe as column name list
//myframe.remove(_use_response_column_name) this will make it generic
selectedkeys  = ["a","b"]
for item in selectedkeys:
    if item in myframe:
        myframe.remove(item)
selectedkeys.append(random.choice(myframe))    
print(selectedkeys)
print(myframe)

您只需要将选定的密钥作为X的输入传递。