线性回归模型后,如何将系数与相应的特征配对?
After LinearRegression Model, How to Pair the Coefficients with the corresponding Features?
我建立了我的第一个线性回归模型 (ElasticNet),预测房屋售价。
我想找出与 SalePrice 具有强相关性(负相关和正相关)的特征
在截图中,我列出了所有的系数和特征名称。 我可以使用什么代码来配对这两个值,以便我可以看到每个特征的系数值?
我对编码和数据分析还很陌生。提前致谢!
我的模型:
grid_model = GridSearchCV(estimator = base_elastic_model,
param_grid = param_grid,
scoring = 'neg_mean_squared_error',
cv=5,
verbose=1)
grid_model.fit(scaled_X_train,y_train)
我得到了系数列表:
grid_model.fit(scaled_X_train,y_train)
我得到了与 SalePrice 的系数不为 0 的特征列表
df.columns[coef[coef == 0].index]
如何打印列出的系数和特征名称相互匹配的数据框?
试试这个:
pd.DataFrame(X_train.columns, grid_model.best_estimator_.coef_)
它会给出这样的输出:
-0.003801 feature0
-0.033107 feature1
0.053203 feature2
-0.645900 feature3
-7.474264 feature4
-0.571417 feature5
0.007333 feature6
0.184133 feature7
0.091905 feature8
0.002021 feature9
我建立了我的第一个线性回归模型 (ElasticNet),预测房屋售价。
我想找出与 SalePrice 具有强相关性(负相关和正相关)的特征
在截图中,我列出了所有的系数和特征名称。 我可以使用什么代码来配对这两个值,以便我可以看到每个特征的系数值?
我对编码和数据分析还很陌生。提前致谢!
我的模型:
grid_model = GridSearchCV(estimator = base_elastic_model,
param_grid = param_grid,
scoring = 'neg_mean_squared_error',
cv=5,
verbose=1)
grid_model.fit(scaled_X_train,y_train)
我得到了系数列表:
grid_model.fit(scaled_X_train,y_train)
我得到了与 SalePrice 的系数不为 0 的特征列表
df.columns[coef[coef == 0].index]
如何打印列出的系数和特征名称相互匹配的数据框?
试试这个:
pd.DataFrame(X_train.columns, grid_model.best_estimator_.coef_)
它会给出这样的输出:
-0.003801 feature0
-0.033107 feature1
0.053203 feature2
-0.645900 feature3
-7.474264 feature4
-0.571417 feature5
0.007333 feature6
0.184133 feature7
0.091905 feature8
0.002021 feature9