如运行以下代码:
from sklearn.linear_model import LinearRegression
from skelarn.preprocessing import StandardScaler
from sklearn.pipeline import Pipelineimport pandas as pddf = pd.read_csv("dataset.csv")num_pipe = Pipeline([("scaler", StandardScaler()),("lin_reg", LinearRegression())
])df_model = num_pipe.fit(df)df_model.coef_
AttributeError: 'Pipeline' object has no attribute 'coef_'
解决方法:
df_model.name_steps['lin_reg'].coef_
named_steps : dict
Read-only attribute to access any step parameter by user given name. Keys are step names and values are steps parameters.
具体参考:
sklearn.pipeline.Pipeline 官方文档