我正在尝试使用GridSearchCV方法使用“对数丢失”对logistic回归和SGDClassifier进行超参数调整。但是在打印best_score_时,best_params_属性出现错误,因为它们不属于GridSearchCV方法。我已经安装了更新的scikit软件包(0.20.3)。无法找出原因?还是在Grid Search方法上启动多个模型时出错?有任何指导原则会有所帮助吗?
我已经将sklearn软件包重新安装到最新版本,但仍然没有帮助!
我正尝试在LogisticRegression()方法和SGDClassifier()上检查对数模型损失的逻辑模型性能,因此了解随机梯度下降在度量结果中产生的差异如何。以下是代码段:
from sklearn.model_selection import GridSearchCV
estimator = [logr_w2v, sgd_lr_w2v]
para = {'C' : [0.0001, 0.001, 0.01, 0.1, 1, 5, 10, 100, 1000], 'alpha' : [0.0001, 0.001, 0.01, 0.1, 1, 5, 10, 100, 1000]}
Grid_w2v = GridSearchCV(estimator, param_grid = para, scoring = 'f1', n_jobs= 4, refit = True , cv = 5)
GridSearchCV(cv=5, error_score='raise-deprecating',
estimator=[LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, max_iter=1000, multi_class='warn', n_jobs=4,
penalty='l1', random_state=50, solver='saga', tol=0.0001,
verbose=0, warm_start=False), SGDClassifier(alpha=0.0001, ...dom_state=50, shuffle=True, tol=0.001,
validation_fraction=0.1, verbose=0, warm_start=False)],
fit_params=None, iid='warn', n_jobs=4,
param_grid={'C': [0.0001, 0.001, 0.01, 0.1, 1, 5, 10, 100, 1000], 'alpha': [0.0001, 0.001, 0.01, 0.1, 1, 5, 10, 100, 1000]},
pre_dispatch='2*n_jobs', refit=True, return_train_score='warn',
scoring='f1', verbose=0)
hyperparameter = []
for i in range(len(estimator)):
Grid_w2v.estimator[i].fit(x1_w2v, y_true)
hyperparameter.append((Grid_w2v.estimator[i]).best_params_)
print("the best score value on each estimator is: ",Grid_w2v.best_score_)
我期望上面的循环将在超参数中保存Logisitic回归和SGDClassifier的超参数。但是我遇到了以下错误:
AttributeError Traceback (most recent call last)
<ipython-input-44-b53708a5f29e> in <module>()
AttributeError: 'GridSearchCV' object has no attribute 'best_score_'