Regularization is a technique used to prevent overfitting in regression models by adding a penalty term to the loss function. Ridge Regression and Lasso Regression are two common types of regularization methods. Ridge adds the L2-norm of the coefficient values to the loss function, while Lasso adds the L1-norm.
Example Code for Ridge Regression:
from sklearn.linear_model import Ridge
# Create a Ridge Regression model
ridge_model = Ridge(alpha=0.5) # 'alpha' is the regularization strength
# Fit the model to the data
ridge_model.fit(X, y)
# Get the coefficients
ridge_coefficients = ridge_model.coef_