0
我想在python中使用scikit-learn API创建一个xgboost回归模型,指定一个权重列。下面是一个最小的代码示例:sample_weight在XGBregressor中不被识别
from xgboost import XGBRegressor
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
model = XGBRegressor()
model.fit(df[['A','B']],df['D'],sample_weight=df['C'])
当我这样做,我得到下面的输出:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-2d43e3c01bbb> in <module>()
6
7
----> 8 model.fit(df[['A','B']],df['D'],sample_weight=df['C'])
TypeError: fit() got an unexpected keyword argument 'sample_weight'
据我所知道的,语法是正确的,根据文档: https://xgboost.readthedocs.io/en/latest/python/python_api.html#module-xgboost.sklearn
有人报告这个问题的XGBoost开发商前一段时间,它似乎已被固定的,所以我不知道这是为什么仍然发生:
https://github.com/dmlc/xgboost/pull/1874
如何安装修复此问题的xgboost版本?我正在使用Ubuntu 64位上的Jupyter Notebook和Anaconda。我应该在没有Anaconda的情况下尝试吗?