当前位置: 代码迷 >> 综合 >> 解决方式 | AttributeError: ‘Pipeline‘ object has no attribute ‘coef_‘
  详细解决方案

解决方式 | AttributeError: ‘Pipeline‘ object has no attribute ‘coef_‘

热度:87   发布时间:2023-12-21 13:53:42.0

如运行以下代码:

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 官方文档

  相关解决方案