OrdinalLogisticRegression<T>

Models & Types · AiDotNet.Classification.Ordinal

Ordinal Logistic Regression (Proportional Odds Model).

Inheritance: ClassifierBase<T> → OrdinalClassifierBase<T> → OrdinalLogisticRegression<T>

Implements: IGeneratedParameterRegistrar<T>, IGradientComputable<T, Matrix<T>, Vector<T>>

For Beginners

Ordinal logistic regression is the standard approach for ordinal data. It’s also known as the “proportional odds model” or “cumulative link model”.

How It Works

How it works: Instead of predicting the class directly, it models the cumulative probability of being in class k or lower:

Where:

  • θₖ = threshold (cutpoint) for class k
  • β = coefficient vector (same for all classes - “proportional odds”)
  • X = feature vector

Key assumption - Proportional Odds: The effect of each feature is the same regardless of which threshold we’re considering. This means moving from 1→2 stars has the same relationship with features as moving from 4→5 stars.

Example: Rating prediction for a restaurant review:

References:

  • McCullagh, P. (1980). “Regression Models for Ordinal Data”

Constructors

Constructor Summary
OrdinalLogisticRegression(IGradientBasedOptimizer<T, Matrix<T>, Vector<T>> optimizer, int maxIterations, double tolerance, double regularization, int? seed) Legacy constructor for backward compatibility with existing code and serialization.
OrdinalLogisticRegression(double learningRate, int maxIterations, double tolerance, double regularization, int? seed) Legacy constructor for backward compatibility with existing code and serialization.

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.
Vector<T> SanitizeParameters(Vector<T> parameters) Sanitizes random parameters to ensure ordinal constraints are satisfied.
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.