Ridge regression
Module: ridge_regression.py
This module implements the RidgeRegressionModel class for ridge regression tasks, extending the base Regression class from the SciREX library.
The implementation uses scikit-learn's Ridge regression model for: - Fitting the ridge regression algorithm - Generating predictions for input features - Evaluating performance using standard regression metrics
Key Features
- Support for fitting a ridge regression model
- Access to model parameters (coefficients, intercept)
- Seamless integration with the SciREX regression pipeline
Classes:
Name | Description |
---|---|
RidgeRegressionModel |
Implements a Ridge Regression model. |
Dependencies
- numpy
- scikit-learn
- scirex.core.ml.supervised.regression.base
Version Info
- 16/Jan/2025: Initial version
RidgeRegressionModel
Bases: Regression
Ridge Regression model implementation using scikit-learn.
This model performs Ridge Regression, which is a linear model that uses L2 regularization. Ridge regression is useful when there is multicollinearity among input features or when there are more predictors than observations.
Attributes:
Name | Type | Description |
---|---|---|
model |
Ridge
|
A scikit-learn Ridge model. |
Source code in scirex/core/ml/supervised/regression/ridge_regression.py
__init__(alpha=1.0, random_state=42)
Initialize the RidgeRegressionModel class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
float
|
Regularization strength; must be a positive float. Defaults to 1.0. |
1.0
|
random_state
|
int
|
Seed for reproducibility where applicable. Defaults to 42. |
42
|
Source code in scirex/core/ml/supervised/regression/ridge_regression.py
fit(X, y)
Fit the Ridge regression model to the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
The input training features (n_samples, n_features). |
required |
y
|
ndarray
|
The target training values (n_samples). |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in scirex/core/ml/supervised/regression/ridge_regression.py
get_model_params()
Get the parameters of the Ridge regression model.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing the model's parameters: - "coefficients": The coefficients (weights) of the linear model. - "intercept": The intercept term of the linear model. |
Source code in scirex/core/ml/supervised/regression/ridge_regression.py
predict(X)
Predict the target values for the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
The input features (n_samples, n_features). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The predicted target values (n_samples,). |