我对机器学习及其概念很陌生,所以一些澄清会有所帮助。
我正在使用Logistic回归来预测二进制结果(0或1)。我正在使用GridSearchCV进行一些超参数调整,以找到最佳的C
和penalty
参数。
代码:
# Setup hyperparameter grid
c_space = np.logspace(-5, 8, 15)
param_grid = {'C': c_space, 'penalty': ['l1', 'l2']}
# Instantiate logistic regression classifier
logreg = LogisticRegression()
# Instantiate GridSearchCV
logreg_cv = GridSearchCV(logreg, param_grid, cv=5)
# Fit to data
logreg_cv.fit(X_train, y_train)
# Print the tuned parameters and score
print("Tuned Logistic Regression Parameters:
{}".format(logreg_cv.best_params_))
print("Best score is {}".format(logreg_cv.best_score_))
输出:
Tuned Logistic Regression Parameters: {'C': 268.26957952797272, 'penalty': 'l2'}
Best score is 0.7974137931034483