如运行以下代码:

from sklearn.linear_model import LinearRegression
from skelarn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline

import pandas as pd

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

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐