Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法将XGBRegressionor与sklearn RFE一起使用_Python_Scikit Learn_Xgboost_Feature Selection - Fatal编程技术网

Python 无法将XGBRegressionor与sklearn RFE一起使用

Python 无法将XGBRegressionor与sklearn RFE一起使用,python,scikit-learn,xgboost,feature-selection,Python,Scikit Learn,Xgboost,Feature Selection,帮助,这个简单的代码会产生一个奇怪的错误 from sklearn.feature_selection import RFECV from xgboost.sklearn import XGBRegressor import sklearn.metrics from sklearn.metrics import mean_absolute_error estimator = XGBRegressor() selector = RFECV(estimator, step=1, min_featu

帮助,这个简单的代码会产生一个奇怪的错误

from sklearn.feature_selection import RFECV
from xgboost.sklearn import XGBRegressor
import sklearn.metrics
from sklearn.metrics import mean_absolute_error

estimator = XGBRegressor()
selector = RFECV(estimator, step=1, min_features_to_select=1, cv=10, scoring='neg_mean_absolute_error')
selector = selector.fit(x, y.values.flatten())
我的回归器已经工作正常,但selector.fit不工作。 对于RFE或RFECV,我得到了相同的结果:

~/miniconda2/envs/py3/lib/python3.6/site-packages/xgboost/sklearn.py in coef_(self)
    714                                  .format(self.booster))
    715         b = self.get_booster()
--> 716         coef = np.array(json.loads(b.get_dump(dump_format='json')[0])['weight'])
    717         # Logic for multiclass classification
    718         n_classes = getattr(self, 'n_classes_', None)

KeyError: 'weight'

提前感谢。

我在xgboost版本1.0.2中遇到了同样的问题。降级到0.90版,如下所示解决了该问题

pip show xgboost
pip uninstall xgboost
pip install --upgrade xgboost==0.90
pip show xgboost
在版本0.90中,我得到了以下警告,错误可能与使用(默认)reg:linear作为度量有关。如果您降级到V0.90,则无需执行任何操作并使用现有代码(如果它在升级之前正常工作)

警告:C:/Jenkins/workspace/xgboost-win64_release_0.90/src/objective/regression_obj.cu:152:reg:linear现在被弃用,取而代之的是reg:squaredrror


您可以尝试在XGBR中设置增压器选项:

estimator = XGBRegressor(booster='gbtree')

XGBoost中基本上有两种类型的助推器:线性助推器和树助推器()。有一些属性是它们各自独有的。例如,给出错误的
coef\u
属性仅为线性学习器()定义,而
feature\u importances\u
仅为基于树的学习器定义。

能否将代码重新格式化为20个字符的线宽?我无法在超暗模式下阅读。