Created
August 3, 2018 20:36
-
-
Save ImadDabbura/2a407ca6fbe78eeb2de5ff3b4da8efae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build logistic model classifier | |
pip_logmod = make_pipeline(StandardScaler(), | |
LogisticRegression(class_weight="balanced")) | |
hyperparam_range = np.arange(0.5, 20.1, 0.5) | |
hyperparam_grid = {"logisticregression__penalty": ["l1", "l2"], | |
"logisticregression__C": hyperparam_range, | |
"logisticregression__fit_intercept": [True, False] | |
} | |
gs_logmodel = GridSearchCV(pip_logmod, | |
hyperparam_grid, | |
scoring="accuracy", | |
cv=2, | |
n_jobs=-1) | |
gs_logmodel.fit(X_train, y_train) | |
print(f"\033[1m\033[0mThe best hyperparameters:\n{'-' * 25}") | |
for hyperparam in gs_logmodel.best_params_.keys(): | |
print(hyperparam[hyperparam.find("__") + 2:], ": ", gs_logmodel.best_params_[hyperparam]) | |
print(f"\033[1m\033[94mBest 10-folds CV f1-score: {gs_logmodel.best_score_ * 100:.2f}%.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment