Created
August 3, 2018 20:35
-
-
Save ImadDabbura/f225bd94b1dcd929d4b8cf005cb78d4f 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 KNN classifier | |
pip_knn = make_pipeline(StandardScaler(), KNeighborsClassifier()) | |
hyperparam_range = range(1, 20) | |
gs_knn = GridSearchCV(pip_knn, | |
param_grid={"kneighborsclassifier__n_neighbors": hyperparam_range, | |
"kneighborsclassifier__weights": ["uniform", "distance"]}, | |
scoring="f1", | |
cv=10, | |
n_jobs=-1) | |
gs_knn.fit(X_train, y_train) | |
print(f"\033[1m\033[0mThe best hyperparameters:\n{'-' * 25}") | |
for hyperparam in gs_knn.best_params_.keys(): | |
print(hyperparam[hyperparam.find("__") + 2:], ": ", gs_knn.best_params_[hyperparam]) | |
print("\033[1m" + "\033[94m" + "Best 10-folds CV f1-score: {:.2f}%.".format((gs_knn.best_score_) * 100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment