我已将 Pipeline
对象与 RandomizedSearchCV
pipe_sgd = Pipeline([('scl', StandardScaler()),
('clf', SGDClassifier(n_jobs=-1))])
param_dist_sgd = {'clf__loss': ['log'],
'clf__penalty': [None, 'l1', 'l2', 'elasticnet'],
'clf__alpha': np.linspace(0.15, 0.35),
'clf__n_iter': [3, 5, 7]}
sgd_randomized_pipe = RandomizedSearchCV(estimator = pipe_sgd,
param_distributions=param_dist_sgd,
cv=3, n_iter=30, n_jobs=-1)
sgd_randomized_pipe.fit(X_train, y_train)
我想访问 --- 的 coef_
属性 best_estimator_
但我无法这样做。我尝试使用以下代码访问 coef_
。
sgd_randomized_pipe.best_estimator_.coef_
但是我得到以下 AttributeError …
AttributeError: ‘Pipeline’ 对象没有属性 ‘coef_’
scikit-learn 文档说 coef_
是 SGDClassifier
的属性,这是我的类 base_estimator_
我究竟做错了什么?
原文由 spies006 发布,翻译遵循 CC BY-SA 4.0 许可协议
在使用
named_steps
dict 创建管道时,您始终可以使用分配给它们的名称。然后访问所有属性,如
coef_
,intercept_
等可用于相应的拟合估计器。这是 文档中指定 的管道公开的正式属性: