Last active
March 18, 2022 17:39
-
-
Save kyleziegler/9c7a79b5f1209a1799b43fb13bcc1704 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
from sklearn.model_selection import GridSearchCV | |
from sklearn.ensemble import GradientBoostingClassifier | |
def grid_search_example(): | |
model = GradientBoostingClassifier(random_state=0, n_estimators=50) | |
pg = { | |
'learning_rate':list(np.arange(0.1,0.4,0.1)), | |
'n_estimators': list(range(50,200,50)), | |
'min_samples_split': list(range(2,10,2)) | |
} | |
opt = GridSearchCV(estimator=model, param_grid=pg, scoring='r2', cv=5) | |
opt.fit(X_train, y_train) | |
df = pd.DataFrame(opt.cv_results_) | |
x = df['mean_test_score'].index | |
y = df['mean_test_score'] | |
plot(x,y) | |
print("Validation Score:", opt.best_score_) | |
print("Test Score:", opt.score(X_test, y_test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment