module 'xgboost.callback' has no attribute 'print_evaluation'
时间: 2023-11-20 16:06:48 浏览: 311
这个错误通常是因为您正在使用的XGBoost版本不支持print_evaluation()函数。这个函数在旧版本中被弃用了。如果您想使用这个函数,您需要使用支持它的旧版本。您可以通过以下命令安装旧版本的XGBoost:
```shell
pip install xgboost==0.90
```
如果您想使用新版本的XGBoost,您可以使用以下代码替代print_evaluation()函数:
```python
def print_evaluation(model, period=1, show_stdv=True):
results = model.evals_result()
epochs = len(results['validation_0']['error'])
x_axis = range(period, epochs)
fig, ax = plt.subplots()
ax.plot(x_axis, results['validation_0']['error'][period:], label='Train')
if show_stdv:
ax.fill_between(x_axis,
(results['validation_0']['error'] - results['validation_0']['stderr'])[period:],
(results['validation_0']['error'] + results['validation_0']['stderr'])[period:],
alpha=0.1, color='g')
ax.plot(x_axis, results['validation_1']['error'][period:], label='Test')
if show_stdv:
ax.fill_between(x_axis,
(results['validation_1']['error'] - results['validation_1']['stderr'])[period:],
(results['validation_1']['error'] + results['validation_1']['stderr'])[period:],
alpha=0.1, color='r')
ax.legend()
plt.ylabel('Error')
plt.title('XGBoost Error')
plt.show()
```
阅读全文