在h2o.randomForest中,假设我有5个输入特征x=c("A","B","C","D","E"(,有没有办法强制算法总是选择A,B和其余特征之一?
在这种情况下,
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 的输入传递。