我已经用RandomizedSearchCV
匹配了一个Pipeline
对象
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)
我想访问best_estimator_
的coef_
属性,但我不能这样做。我试过用下面的代码访问coef_
。
sgd_randomized_pipe.best_estimator_.coef_
但是我得到了以下的属性错误。。。
AttributeError:“Pipeline”对象没有属性“coef”
scikit学习文档说coef_
是SGDClassifier
的一个属性,这是我的base_estimator_
类。
我做错什么了?
通过使用
named_steps
指令,在生成管道时始终可以使用分配给它们的名称然后访问所有属性,如
coef_
、intercept_
等,这些属性可用于相应的拟合估计器。这是管道公开为specified in the documentation的形式属性:
我认为这应该管用:
我找到了一种方法,通过使用
steps
属性链接索引。。。sgd_randomized_pipe.best_estimator_.steps[1][1].coef_
这是最佳实践,还是有其他方法?
相关问题 更多 >
编程相关推荐