Created
January 14, 2021 17:57
-
-
Save saimadhu-polamuri/cfc4e1549ba6eca1c9cb85521dfc262b 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
## Ridge regression | |
## two lists to hold alpha values and cross-validation scores | |
alpha = [] | |
ridge_scores = [] | |
## loop over different alpha values | |
for i in range(1,10): | |
ridge_model = Ridge(alpha=0.25*i) | |
ridge_model.fit(X_train, y_train) | |
scores = cross_val_score(ridge_model, X, y, cv=10) | |
average_score = mean(scores)*100 | |
ridge_scores.append(average_score) | |
alpha.append(0.25*i) | |
## printing the scores | |
for i in range(0, len(alpha)): | |
print(str(alpha[i]) + ' -> ' + str(ridge_scores[i])) | |
""" | |
## Outputs | |
0.25 -> 69.12811921100793 | |
0.5 -> 69.1282936467351 | |
0.75 -> 69.12844835069451 | |
1.0 -> 69.12858352574278 | |
1.25 -> 69.12869937241088 | |
1.5 -> 69.12879608893493 | |
1.75 -> 69.12887387128701 | |
2.0 -> 69.128932913205 | |
2.25 -> 69.12897340622241 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment