简体   繁体   English

如何预测第 n 棵树的 H2O GBM model?

[英]How to predict a H2O GBM model for nth tree?

pros_gbm = H2OGradientBoostingEstimator(nfolds=0,seed=1234, keep_cross_validation_predictions = False, ntrees=1000, max_depth=3, learn_rate=0.01, distribution='multinomial') pros_gbm.train(x=predictors, y=target, training_frame=hf_train, validation_frame = hf_test) pros_gbm = H2OGradientBoostingEstimator(nfolds=0,seed=1234, keep_cross_validation_predictions = False, ntrees=1000, max_depth=3, learn_rate=0.01, distribution='multinomial') pros_gbm.train(x=predictors, y=target, training_frame=hf_train,验证帧 = hf_test)

pros_gbm.predict(hf_test) pros_gbm.predict(hf_test)

Currently, I am predicting my test data like above, but how can I predict my test data for the nth tree(out of 1000 trees) of this model?目前,我正在像上面那样预测我的测试数据,但是如何预测我的测试数据对于这个 model 的第 n 棵树(1000 棵树)? is there any option in "predict" for that, or is there any other way? “预测”中是否有任何选项,或者有其他方法吗?

You can get the predicted probabilities (cumulative for each tree) using staged_predict_proba() and the lead node assignments from predict_leaf_node_assignment() .您可以使用staged_predict_proba()和 predict_leaf_node_assignment() 的前导节点分配获得预测概率(每棵树的累积predict_leaf_node_assignment() Here is an example:这是一个例子:

from h2o.estimators import H2OGradientBoostingEstimator

# Import the prostate dataset into H2O:
prostate = h2o.import_file("http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv")

# Set the predictors and response; set the factors:
prostate["CAPSULE"] = prostate["CAPSULE"].asfactor()
predictors = ["ID","AGE","RACE","DPROS","DCAPS","PSA","VOL","GLEASON"]
response = "CAPSULE"

# Build and train the model:
pros_gbm = H2OGradientBoostingEstimator(nfolds=5,
                                        seed=1111,
                                        keep_cross_validation_predictions = True)
pros_gbm.train(x=predictors, y=response, training_frame=prostate)

print(pros_gbm.predict_leaf_node_assignment(prostate[:1, :]))
print(pros_gbm.staged_predict_proba(prostate[:1, :]))

You can also check out the Tree Class if you want details (leaf/split info) for each tree.如果您需要每棵树的详细信息(叶子/拆分信息),您还可以查看Tree Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM