Class OrdinalRegressionLoss<T>
- Namespace
- AiDotNet.LossFunctions
- Assembly
- AiDotNet.dll
Implements the Ordinal Regression Loss function for predicting ordered categories.
public class OrdinalRegressionLoss<T> : LossFunctionBase<T>, ILossFunction<T>
Type Parameters
TThe numeric type used for calculations (e.g., float, double).
- Inheritance
-
OrdinalRegressionLoss<T>
- Implements
- Inherited Members
- Extension Methods
Remarks
For Beginners: Ordinal Regression is used when predicting categories that have a meaningful order. Examples include: - Ratings (poor, fair, good, excellent) - Education levels (elementary, middle, high school, college) - Severity levels (mild, moderate, severe)
Unlike regular classification, ordinal regression takes into account that being off by one category is better than being off by multiple categories. For example, predicting "good" when the actual rating is "fair" is a smaller error than predicting "excellent".
The ordinal regression loss uses a series of binary classifiers, one for each threshold between adjacent categories. For example, with categories [1,2,3,4,5], there are four classifiers:
- Is the rating > 1?
- Is the rating > 2?
- Is the rating > 3?
- Is the rating > 4?
This approach preserves the ordering information in the categories during training.
Constructors
OrdinalRegressionLoss(int)
Initializes a new instance of the OrdinalRegressionLoss class.
public OrdinalRegressionLoss(int numClasses)
Parameters
numClassesintThe number of classes or categories in the ordinal scale.
Methods
CalculateDerivative(Vector<T>, Vector<T>)
Calculates the derivative of the Ordinal Regression Loss function.
public override Vector<T> CalculateDerivative(Vector<T> predicted, Vector<T> actual)
Parameters
predictedVector<T>The predicted values vector.
actualVector<T>The actual (ground truth) values vector, typically integers representing ordinal categories.
Returns
- Vector<T>
A vector containing the derivatives of the ordinal regression loss with respect to each prediction.
CalculateLoss(Vector<T>, Vector<T>)
Calculates the Ordinal Regression Loss between predicted and actual values.
public override T CalculateLoss(Vector<T> predicted, Vector<T> actual)
Parameters
predictedVector<T>The predicted values vector.
actualVector<T>The actual (ground truth) values vector, typically integers representing ordinal categories.
Returns
- T
The ordinal regression loss value.