我是 Python 和机器学习的新手。我在网上搜索了我的问题,并尝试了人们建议的解决方案,但仍然没有得到它。如果有人能帮助我,我将非常感激。
我正在开发我的第一个 XGboost 模型。我已经使用 xgb.XGBClassifier 调整了参数,然后想强制模型变量的单调性。看来我必须使用 xgb.train() 来强制单调性,如下面的代码所示。
xgb.train()可以执行predict()函数,但不能执行predict_proba()函数。那么如何从 xgb.train() 获得概率?
我尝试使用 'objective':'multi:softprob' 而不是 'objective':'binary:logistic'。然后得分 = 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'
Run Code Online (Sandbox Code Playgroud)