我是Python和机器学习的新手。我已经在互联网上搜索了我的问题并尝试了人们提出的解决方案,但仍然没有得到答案。如果有人能帮我解决问题,我将不胜感激。
我正在开发我的第一个XGboost模型。我使用xgb.XGBClassifier调整了参数,然后想对模型变量实施单调性。显然,我必须使用下面代码中显示的xgb.train()来实施单调性。
xgb.train() 可以使用 predict() 函数进行预测,但不能使用 predict_proba() 函数。那么我该如何从 xgb.train() 中获取概率值?
我尝试使用 'objective':'multi:softprob' 代替 'objective':'binary:logistic'。然后 score = bst_constr.predict(dtrain)。但是我觉得分数不正确。
非常感谢。
params_constr={
'base_score':0.5,
'learning_rate':0.1,
'max_depth':5,
'min_child_weight':100,
'n_estimators':200,
'nthread':-1,
'objective':'binary:logistic',
'seed':2018,
'eval_metric':'auc'
}
params_constr['monotone_constraints'] = "(1,1,0,1,-1,-1,0,0,1,-1,1,0,1,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,)"
dtrain = xgb.DMatrix(X_train, label = y_train)
bst_constr = xgb.train(params_constr, dtrain)
X_test['score']=bst_constr.predict_proba(X_test)[:,1]
AttributeError: 'Booster' object has no attribute 'predict_proba'
booster=
。您是否尝试将您的booster
传递到XGBClassifier()
实例中,然后对您的数据进行.fit()
调用? - G. Anderson