Skip to content

Instantly share code, notes, and snippets.

@andreachello
Created October 6, 2021 04:51
Show Gist options
  • Save andreachello/04da15cbae3f0498a664c0a0fe9698e9 to your computer and use it in GitHub Desktop.
Save andreachello/04da15cbae3f0498a664c0a0fe9698e9 to your computer and use it in GitHub Desktop.
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