Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.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 sklearn | RFECV+;线性回归给出了';线性回归';对象没有属性';coef'&引用;_Python_Pandas_Dataframe_Machine Learning_Scikit Learn - Fatal编程技术网

Python sklearn | RFECV+;线性回归给出了';线性回归';对象没有属性';coef'&引用;

Python sklearn | RFECV+;线性回归给出了';线性回归';对象没有属性';coef'&引用;,python,pandas,dataframe,machine-learning,scikit-learn,Python,Pandas,Dataframe,Machine Learning,Scikit Learn,我有以下代码: rfe = RFECV(estimator=LinearRegression()) model_all = LinearRegression() pipeline = Pipeline(steps=[('s',rfe),('m',model_all)]) # evaluate model cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1) n_scores = cross_val_score(pipeline,

我有以下代码:

rfe = RFECV(estimator=LinearRegression())
model_all = LinearRegression()
pipeline = Pipeline(steps=[('s',rfe),('m',model_all)])
# evaluate model
cv = RepeatedKFold(n_splits=10, n_repeats=3, random_state=1)
n_scores = cross_val_score(pipeline, X_all, y_all, scoring='neg_root_mean_squared_error', cv=cv, n_jobs=-1, error_score='raise')
# report performance
print('RMSE: {0}'.format(np.mean(n_scores)))
我试图得到线性回归模型的系数来检查特征的重要性:

importance = model_all.coef_
# summarize feature importance
for i,v in enumerate(importance):
    print('Feature: %0d, Score: %.5f' % (i,v))
但它给了我:

AttributeError:“LinearRegression”对象没有属性“coef\ux”


如何得到系数?我还想获得使用RFECV过程选择的列的名称。

这里您可以实例化模型:

model_all = LinearRegression()
这将计算管道的cv分数:

n_scores = cross_val_score(pipeline, X_all, y_all, scoring='neg_root_mean_squared_error', cv=cv, n_jobs=-1, error_score='raise')
model\u all
仍然是vanila
LinearRegression()
对象,并且未安装,因此它没有
coef
属性

# add this
model_all.fit(X_all, y_all)
importance = model_all.coef_

嘿,不适合这里吗?你需要向模型展示一些数据,然后才能计算出系数。请原谅我的无知,我现在还没有这么做吗?否则,如何才能达到低MSE?