OrdinalRidgeRegression<T>
Models & Types · AiDotNet.Classification.Ordinal
Ordinal Ridge Regression using the Immediate-Threshold approach with L2 regularization.
Inheritance: ClassifierBase<T> → OrdinalClassifierBase<T> → OrdinalRidgeRegression<T>
Implements: IGeneratedParameterRegistrar<T>, IGradientComputable<T, Matrix<T>, Vector<T>>
For Beginners
This is a variant of ordinal classification that treats the problem as a regression task with specially-designed thresholds. It uses ridge (L2) regularization to prevent overfitting, which adds a penalty for large coefficient values.
How It Works
How it works: Instead of modeling cumulative probabilities like ordinal logistic regression, this approach:
- Treats the ordinal labels as numeric targets
- Learns a linear function f(X) = β·X
- Uses thresholds to convert predictions back to ordinal classes
Immediate-Threshold method: After training the regression model, thresholds are placed at the midpoints between consecutive class means in the training data. This gives natural boundaries between classes.
Ridge regularization: Adds λ·||β||² to the loss function, which:
- Prevents coefficients from becoming too large
- Reduces overfitting on noisy data
- Provides a closed-form solution (no iterative optimization needed)
When to use:
- When you want a fast, closed-form solution
- When the ordinal levels are roughly equally spaced
- When you need regularization to handle multicollinearity
References:
- Frank, E. & Hall, M. (2001). “A Simple Approach to Ordinal Classification”
- Chu, W. & Keerthi, S.S. (2007). “Support Vector Ordinal Regression”
Example
// Create ordinal ridge regression with L2 regularization
// Prepare training data: 6 samples with 2 features, ordinal labels
var features = new Matrix<double>(6, 2);
features[0, 0] = 1.0; features[0, 1] = 0.5;
features[1, 0] = 1.5; features[1, 1] = 1.0;
features[2, 0] = 2.0; features[2, 1] = 1.5;
features[3, 0] = 2.5; features[3, 1] = 2.0;
features[4, 0] = 3.0; features[4, 1] = 2.5;
features[5, 0] = 3.5; features[5, 1] = 3.0;
var labels = new Vector<double>(new double[] { 0, 0, 1, 1, 2, 2 });
// Train with closed-form ridge solution and immediate-threshold method
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new OrdinalRidgeRegression<double>())
.Build(features, labels);
// Predict ordinal class using learned thresholds
var newSample = new Matrix<double>(1, 2);
newSample[0, 0] = 2.2; newSample[0, 1] = 1.8;
var prediction = result.Predict(newSample);
// Result is available in the returned value
Constructors
| Constructor | Summary |
|---|---|
OrdinalRidgeRegression(double alpha, bool fitIntercept) |
Initializes a new instance of OrdinalRidgeRegression. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
Gets feature importance based on coefficient magnitude. |
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
Creates a new instance with the specified parameters. |
Matrix<T> PredictCumulativeProbabilities(Matrix<T> features) |
Predicts cumulative probabilities P(Y ≤ k). |
Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T> lossFunction) |
Computes gradients for the model parameters. |
Vector<T> Predict(Matrix<T> input) |
Predicts ordinal class labels. |
void ApplyGradients(Vector<T> gradients, T learningRate) |
Applies gradients to update model parameters. |
void Train(Matrix<T> x, Vector<T> y) |
Gets the model type. |