我正在尝试使用h2o训练决策树模型。我知道在h2o中不存在用于决策树的特定库。
这是我在h2o中使用GBM算法时的代码,但是我可以像这样使用决策树。因为h2o中没有决策树代码。
GBMParametersV3 gbmParams = new GBMParametersV3();
gbmParams.trainingFrame = H2oApi.stringToFrameKey("train");
gbmParams.validationFrame = H2oApi.stringToFrameKey("test");
ColSpecifierV3 responseColumn = new ColSpecifierV3();
responseColumn.columnName = ATT_LABLE_IRIS;
gbmParams.responseColumn = responseColumn;
GBMV3 gbmBody = h2o.train_gbm(gbmParams);
...
那么,如何在h2o中使用决策树算法?
答案 0 :(得分:0)
基于PUBDEV-4324 - Expose Decision Tree as a stand-alone algo in H2O,最直接的方法是使用GBM:
def add_metrics(*args):
values = [(metric, var.get()) for metric, var in data.items() if var.get() == 1]
print(values)
data = {}
top = Tk()
mb= Menubutton ( top, text="Metric List:", relief=RAISED )
mb.menu = Menu ( mb, tearoff = 0 )
mb["menu"] = mb.menu
All_Metric_List = []
for m in dataframe_metrics['name']:
All_Metric_List.append(m)
for metric in All_Metric_List:
var = IntVar()
mb.menu.add_checkbutton(label=metric, variable=var)
data[metric] = var
btn = Button(top, text="Add Metrics:", command=add_metrics)
btn.pack()
mb.pack()
top.mainloop()
可在泰坦尼克号数据集(可在此处使用:titanic_1tree = h2o.gbm(x = predictors, y = response,
training_frame = titanicHex,
ntrees = 1, min_rows = 1, sample_rate = 1,
col_sample_rate = 1,
max_depth = 5,
seed = 1)
)上创建最多5个深度(max_depth = 5
)的决策树
从3.22.0.1(Xia)版本开始,可以从H2O模型中提取树结构:
https://s3.amazonaws.com/h2o-public-test-data/smalldata/gbm_test/titanic.csv