Created
October 6, 2021 04:51
-
-
Save andreachello/04da15cbae3f0498a664c0a0fe9698e9 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.linear_model import RidgeCV | |
from sklearn.metrics import mean_squared_error | |
# root-mean-squared error function | |
def rmse(ytrue, ypredicted): | |
return np.sqrt(mean_squared_error(ytrue, ypredicted)) | |
alphas = [0.005, 0.05, 0.1, 0.3, 1, 3, 5, 10, 15, 30, 80] | |
ridgeCV = RidgeCV(alphas=alphas, | |
cv=4).fit(X_train, y_train) | |
ridgeCV_rmse = rmse(y_test, ridgeCV.predict(X_test)) | |
print("The best alpha is: {} with Root Mean Square Error: {}".format( | |
ridgeCV.alpha_, ridgeCV_rmse)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment