小编Ank*_*eth的帖子

XGBoost 错误 - 未知目标函数 reg:squarederror

我正在为回归任务训练 xgboost 模型,并传递了以下参数 -

params = {'eta':0.4, 'max_depth':5, 'colsample_bytree':0.6, 'objective':'reg:squarederror'}
num_round = 10
xgb_model = xgboost.train(params, dtrain_x, num_round)
Run Code Online (Sandbox Code Playgroud)

在训练阶段,我得到以下错误-

XGBoostError: b'[18:03:23] C:\Users\xgboost\src\objective\objective.cc:23: 未知目标函数 reg:squarederror'

而在docs 中,它显然是一个有效的目标函数。谁能告诉我为什么我会收到这个错误?

信息-我在 Windows 上使用 python 3.7.3,xgboost 版本是 0.82

regression python-3.x xgboost

9
推荐指数
1
解决办法
6292
查看次数

在 Pandas 中的特定行和列中填充 NaN

我有一个看起来像这样的数据框-

>>> df  
     a    d    s  
0  1.0  3.0  2.0  
1  2.0  NaN  4.0  
2  3.0  6.0  NaN  
3  NaN  NaN  3.0  
4  5.0  8.0  NaN  
5  6.0  NaN  NaN  
Run Code Online (Sandbox Code Playgroud)

我必须用“d”列中的平均值替换 NaN,其中“a”列的值 > 2。所以,我写-

>>> df['d'][df['a']>2]  
2    6.0  
4    8.0  
5    NaN  

>>> df['d'][df['a']>2].fillna(df['d'][df['a']>2].mean(), inplace = True)  
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用,它返回相同的数据帧,而不影响“d”列最后一行中的 NaN 值。

请告诉我我在这里做错了什么。我正在使用 pandas 版本 0.21

python pandas

3
推荐指数
1
解决办法
5509
查看次数

如何将 xgboost 的特征重要性图从 Jupyter 笔记本保存到文件

我正在努力将 xgboost 特征重要性图保存到文件中。我在我的 jupyter 笔记本中创建了一个模型并绘制了功能的重要性 -

xgb_model = xgboost.train(best_params, dtrain, num_round)
xgboost.plot_importance(xgb_model)
Run Code Online (Sandbox Code Playgroud)

它向我显示了特征重要性图,但我无法将其保存到文件中。我什至在 中寻找任何保存属性dir(xgboost.plot_importance(xgb_model)),但一无所获。有没有办法做到这一点?

python xgboost jupyter-notebook

3
推荐指数
1
解决办法
2046
查看次数