Member-only story
How to Perform Ordinal Regression / Classification in PyTorch
A simple trick for improving model performance when labels are ordered.
When you have a multiclass classification problem and there is an order to the classes, it is known as an “ordinal regression” problem. An example could be the classification of a student’s performance into categories A > B > C > D > E. The issue in solving this kind of problem using a normal classifier is that the model will assume that the error of misclassifying an A as a D is just as bad as misclassifying A as a B — this is obviously not true since the difference between A and D is much bigger than between A and B. Alternative names for ordinal regression are ordinal classification or even ranking learning; as you might have guessed, these methods let the model know the ordinal relationship of the classes, letting the model learn to rank instead of learning to classify.
This post will demonstrate a simple trick for performing ordinal regression in PyTorch using a custom loss function. Although I’ll walk through the trick for a particular problem, you can apply it to any ordinal regression problem and any other framework.
An example ordinal problem
Let us first find a dataset for testing. I recently wrote a post on how to…