我正在尝试使用scikit-learn API在python中创建一个xgboost回归模型,并指定一个权重列。下面是一个最小的代码示例:
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版本?我在64位的Ubuntu上使用Jupyter Notebook和Anaconda。我应该尝试在没有Anaconda的情况下做这件事吗?
发布于 2017-09-17 22:07:31
我可以通过从github安装xgboost来修复这个问题,而不是从pip安装它。我还没有让它与Anaconda一起工作,但下面的技巧为我做到了:
sudo apt-get install python3.6
sudo apt-get install git
git clone –recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4
cd python-package; python3 setup.py installhttps://stackoverflow.com/questions/46264465
复制相似问题