作者:北人南漂记 | 来源:互联网 | 2023-02-04 14:48
我适合一个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_
.
我究竟做错了什么?
1> Vivek Kumar..:
在使用named_steps
dict 创建管道时,您始终可以使用分配给它们的名称.
scaler = sgd_randomized_pipe.best_estimator_.named_steps['scl']
classifier = sgd_randomized_pipe.best_estimator_.named_steps['clf']
然后访问所有像的属性coef_
,intercept_
它们是提供给对应的拟合估计等等.
这是文档中指定的Pipeline公开的形式属性:
named_steps:dict
只读属性,用于按用户名称访问任何步骤参数.键是步骤名称,值是步骤参数.