arXiv:2606.25769v1 [cs.LG] 24 Jun 2026
Deep Neural Networks with Ordinal Loss for Medical Applications Tal Dvora
Rotem Haba
Gonen Singer
Bar-Ilan University Ramat Gan, Israel [email protected]
Bar-Ilan University Ramat Gan, Israel [email protected]
Bar-Ilan University Ramat Gan, Israel [email protected]
Abstract—In many prediction problems in medical applications, target labels exhibit an inherent ordinal structure, where class ordering reflects clinically meaningful severity levels. The cost associated with misclassification is often non-uniform and asymmetric, as errors between distant ordinal categories may have substantially more severe consequences than errors between adjacent ones, and overestimating disease severity may have different clinical implications than underestimating it. Traditional loss functions such as multi-class cross-entropy treat all misclassifications equally and fail to incorporate this ordering information. Recent advances in ordinal regression aim to address this limitation by integrating rank-based structures into deep learning models. In this work, we introduce the Ordinal Cross-Entropy (OCE) framework, a general and architectureindependent approach for learning from ordinal data. The proposed method extends the standard cross-entropy formulation to account for misclassification severity through an ordinal cost matrix while preserving the probabilistic interpretation and optimization benefits of the conventional loss. We provide a theoretical analysis of the OCE gradient behavior and show that it yields smoother optimization dynamics and improved ordinal consistency. Experiments on benchmark datasets show that our method achieves lower prediction error costs and better calibration compared to existing state-of-the-art ordinal approaches, establishing OCE as a simple yet effective solution for ordinal regression in deep neural networks. Index Terms—Ordinal classification, cost-sensitive learning, asymmetric loss function, medical image analysis.
I. I NTRODUCTION Deep neural networks (DNNs) have become the leading approach for multi-class classification across numerous domains, including medical image analysis [1]–[5], where accurate predictions are often essential for clinical decision-making. The standard framework for multi-class learning relies on the cross-entropy (CE) loss [6] combined with a softmax output layer, which offers stable optimization, probabilistic interpretation, and strong empirical performance. However, CE inherently treats all misclassifications as equally severe and does not incorporate the structure of the output space [7]. In many real-world applications, particularly in medicine, the target labels are ordinal rather than nominal. Disease This work was supported by a research grant from Intuit. © 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works.
stages, severity grades, or risk levels exhibit a natural ordering, and misclassification costs depend not only on the distance between classes but also on the direction of the error. In clinical settings, overestimating disease severity may lead to unnecessary interventions, whereas underestimating severity can result in delayed treatment and substantially worse outcomes. For example, in diabetic retinopathy [8], cancer staging [9], [10], or predict the level of Parkinson’s disease [11], predicting a mild case as severe is less harmful than predicting a severe case as healthy, since the latter combines a larger ordinal distance with a more harmful direction of misclassification, leading to substantially higher clinical risk. To address this gap, several ordinal learning approaches have been proposed. Methods such as CORAL [12] and CORN [13] reformulate the ordinal regression problem into a series of K −1 binary classification subtasks while enforcing rankmonotonicity through shared model weights and ordered bias terms. This design guarantees that the predicted probabilities across the binary tasks are non increasing, ensuring consistent and rank-aware prediction. Unimodal label-regularization techniques [14]–[17] encourage predictions centered around the correct class. Vargas et al. [17] introduce a probabilistic betabased regularization framework that explicitly incorporates ordinal structure into the target labels. Their approach models the ground-truth class as a unimodal distribution generated from a beta density centered on the true ordinal level, effectively smoothing the one-hot target vector in a shape-aware manner that reflects the degree of proximity between classes. As a result, misclassifications to adjacent categories are penalized less severely than errors that span multiple severity levels, aligning the learning objective more closely with the underlying ordinal semantics. The authors apply the beta-regularized loss to both standard softmax classification and a stick-breaking (cumulative probability) formulation [18], reporting consistent gains over Poisson-, binomial-, and exponential-based [14], [16] label smoothing methods across multiple benchmark ordinal image datasets, including diabetic retinopathy grading. Beyond probabilistic label–regularization methods, recent approaches explicitly embed ordinal structure at the architectural level. For instance, OR-DGN [19] introduces a regression branch to learn continuous severity scores alongside classification. Similarly, DGN-AGLD [20] incorporates a dedicated ’variance predictor’ module to model label distributions as asymmetric Gaussians,
aiming to capture the direction of disease progression. While these hybrid strategies effectively leverage ordinal relationships, they inherently increase model complexity, require designing specialized network branches, and necessitate balancing multiple loss functions (e.g., cross-entropy combined with distribution or regression losses). In contrast, our proposed Ordinal Cross-Entropy (OCE) offers a purely loss-based solution. By integrating an ordinal cost matrix directly into the standard cross-entropy formulation, OCE enforces distance-dependent penalties without altering the network architecture, preserving the desirable optimization properties of the original loss. Other approaches, such as weighted cross-entropy (WCE) [21], [22], attempt to incorporate misclassification costs at the class level. Although effective in specific settings, these methods do not fully capture the structure of ordinal misclassification risks, and in particular, they cannot express scenarios in which the direction of the error matters. A notable attempt to integrate ordinal distance is the Ordinal Loss (OL) proposed by Chen et al. [23], in which penalties are determined by the ordinal distance between predicted and true classes. Developed for the specific challenge of grading knee osteoarthritis (OA) severity, the major cause of activity limitation and physical disability in older individuals [24]–[27], this approach addresses a critical limitation of the standard cross-entropy loss, which treats all misclassifications equally regardless of the semantic gap between categories. The authors argue that in clinical ordinal tasks, a “faraway” error (e.g., predicting severe Grade 4 when the truth is healthy Grade 0) is significantly more detrimental than a “nearby” error (e.g., confusing Grade 0 with Grade 1). To mitigate this, the method utilizes an “adjustable ordinal matrix” to define penalty weights that increase as the distance between the predicted rank and the ground truth grows. This mechanism constrains the model’s probability output, ensuring that the likelihood assigned to incorrect classes decreases as they become further removed from the true grade. However, the ordinal loss function does not retain the properties of the cross-entropy; for example, it assumes a linear relationship between the predicted probability and the loss value, instead of the logarithmic relationship in the cross-entropy loss function. These limitations highlight the need for a loss function that is able to: 1) Preserve the desirable optimization properties of crossentropy. 2) Incorporate ordinal relationships and distance-dependent penalties. 3) Encode asymmetric misclassification costs, where the risk of underestimation and overestimation are not equivalent. To address this need, we propose the Ordinal CrossEntropy (OCE) framework, a principled extension of cross-entropy for ordinal classification. OCE integrates a general cost matrix allowing domain experts to specify both distance-dependent and direction-dependent misclassification penalties, while maintaining the logarithmic sensitivity of CE. This enables the model to prioritize avoidance
of clinically dangerous misdiagnoses and learn decision boundaries aligned with real-world risk. As we show through theoretical and empirical evaluation, OCE provides smoother gradient behavior, improved ordinal consistency, and superior performance compared to existing ordinal and cost-sensitive loss formulations. All experiments presented in this paper can be reproduced using the source code available at https://github.com/Taldvora1/ Deep-Neural-Networks-with-Ordinal-Loss-for-Medical-Applications. II. P ROPOSED M ETHOD : O RDINAL C ROSS -E NTROPY (OCE) The use of a cost matrix to encode unequal misclassification penalties is well-established in the cost-sensitive learning literature [28], where the learning objective is explicitly aligned with the real-world consequences of prediction errors. In this section, we introduce the Ordinal Cross-Entropy (OCE) loss, a distance-aware and cost-sensitive extension of the standard cross-entropy loss. OCE is designed to preserve the probabilistic and optimization benefits of cross-entropy while incorporating both ordinal structure and clinically relevant misclassification costs. The use of a cost matrix to encode unequal misclassification penalties is well-established in the cost-sensitive learning literature [28], where the learning objective is explicitly aligned with the real-world consequences of prediction errors. In this section, we introduce the Ordinal Cross-Entropy (OCE) loss, a distance-aware and cost-sensitive extension of the standard cross-entropy loss. OCE is designed to preserve the probabilistic and optimization benefits of cross-entropy while incorporating both ordinal structure and clinically relevant misclassification costs. A. Penalty Matrix and Cost Matrix We define a square cost matrix C ∈ RI×I with non-negative entries ci,j ≥ 0, where ci,j represents the real-world cost incurred when a sample with true class y = vi is predicted as ŷ = vj . Here, {v1 , . . . , vI } denotes the ordered set of ordinal class values (e.g., healthy, mild, moderate, severe), while the indices i and j represent their respective ordinal positions. To model realistic ordinal risk behaviour, the cost increases with the ordinal distance d = |i − j| and may reflect different severities for underestimation and overestimation. Formally: k1 + λ1 · d, if i < j (overestimation), Ci,j = k2 + λ2 · d, if i > j (underestimation), 0, if i = j, where k1 , k2 represent baseline costs and λ1 , λ2 control the growth rate as classes become further apart. In clinical scenarios where underestimation carries greater risk (e.g., diagnosing cancer at a more advanced stage than reality), one may impose: k1 ≤ k2 , λ1 ≤ λ2 , while equality recovers the symmetric case. Transition from Cost Matrix to Penalty Matrix. The cost matrix C captures real-world misclassification costs reflecting clinical risk and domain-specific severity. However, these costs
𝑃𝑒𝑛𝑎𝑙𝑡𝑦 𝑐𝑜𝑠𝑡𝑠 𝑎𝑛𝑑 𝑏𝑒𝑛𝑒𝑓𝑖𝑡𝑠 𝑚𝑎𝑡𝑟𝑖𝑥
𝐶𝑜𝑠𝑡𝑠 𝑚𝑎𝑡𝑟𝑖𝑥 𝒗𝟏
𝒗𝟐
𝒗𝟑
𝒗𝟒
𝒗𝟓
𝒗𝟏
𝒗𝟐
𝒗𝟑
𝒗𝟒
𝒗𝟏
0
4
6
8
10
𝒗𝟏
1
0.4
0.6
0.8
𝒗𝟓 1
𝒗𝟐
4
0
4
6
8
𝒗𝟐
0.4
1
0.4
0.6
0.8
𝒗𝟑
6
4
0
4
6
𝒗𝟑
0.6
0.4
1
0.4
0.6
𝒗𝟒
8
6
4
0
4
𝒗𝟒
0.8
0.6
0.4
1
0.4
𝒗𝟓
10
8
6
4
0
𝒗𝟓
1
0.8
0.6
0.4
1
(a) Symmetric penalty structure 𝑃𝑒𝑛𝑎𝑙𝑡𝑦 𝑐𝑜𝑠𝑡𝑠 𝑎𝑛𝑑 𝑏𝑒𝑛𝑒𝑓𝑖𝑡𝑠 𝑚𝑎𝑡𝑟𝑖𝑥
𝐶𝑜𝑠𝑡𝑠 𝑚𝑎𝑡𝑟𝑖𝑥
of the neural network before the normalization function, zk,i , ∀k ∈ {1, . . . , K}, i ∈ {1, . . . , I}. Assume a normalization softmax function, RI → RI , that maps each vector of a sample k, zk ∈ RI to a vector p̂k ∈ RI such that ezk,i , i = 1, . . . , I, p̂k,i (zk ) = PI zk,j j=1 e (1) I X 0 ≤ p̂k,i ≤ 1, p̂k,i = 1. i=1
𝒗𝟏
𝒗𝟐
𝒗𝟑
𝒗𝟒
𝒗𝟓
𝒗𝟏
𝒗𝟐
𝒗𝟑
𝒗𝟏
0
4
6
8
10
𝒗𝟐
8
0
4
6
8
𝒗𝟑
12
8
0
4
𝒗𝟒
16
12
8
0
𝒗𝟓
20
16
12
8
0
𝒗𝟒
𝒗𝟓
𝒗𝟏
1
0.2
0.3
0.4
0.5
𝒗𝟐
0.4
1
0.2
0.3
0.4
6
𝒗𝟑
0.6
0.4
1
0.2
0.3
4
𝒗𝟒
0.8
0.6
0.4
1
0.2
𝒗𝟓
1
0.8
0.6
0.4
1
Assuming a one-hot encoded target vector yk , where yk,mk = 1 and yk,i = 0 for all i ̸= mk , with mk denoting the index of the true ordinal class of sample k, the OCE loss becomes: ! " OCE = −
(b) Asymmetric penalty structure Fig. 1. Comparison of penalty structures for ordinal misclassification. (a) Symmetric penalties assign equal costs to underestimation and overestimation based on ordinal distance. (b) Asymmetric penalties reflect domain-specific risk. In both cases, a maximum diagonal benefit reinforces correct predictions.
are not directly suitable for use within a probabilistic loss function, as they are not normalized and do not explicitly distinguish between penalties for incorrect predictions and benefits for correct ones. We therefore transform C into a penalty matrix P that can be consistently integrated into the OCE loss. Accordingly, we construct the penalty matrix P by modifying the diagonal and normalizing the scale as follows: Pi,i = max(C), ∀i, and the matrix is normalized to [0, 1] by: P P = . max(C) This transformation preserves the relative misclassification relationships defined by the real-world costs while providing stable optimization dynamics and a clear benefit signal for confident correct predictions. From this point onward, for notational simplicity, we denote the entries of the resulting penalty–reward matrix by cij ; diagonal elements cii represent rewards for correct classification, whereas off-diagonal elements cij for i ̸= j represent misclassification penalties. Figure 1 illustrates both the real-world cost matrix and the derived penalty matrix, including the transition process in the symmetric and asymmetric configurations, for better understanding. B. Ordinal cross-entropy loss The ordinal cross-entropy is a logarithmic function that can be easily optimized using gradient descent methods, similarly to the conventional cross-entropy loss function. In the training process of a neural network, the OCE loss function aims to find the optimal parameters of the network, which minimize OCE. In order to solve the optimization problem using a gradient descent algorithm, we derive the partial derivatives of the OCE with respect to the outputs
K X I X
ezk,i PI zk,j j=1 e k=1 i=1 !# ezk,i +(1 − yk,i ) log 1 − PI . zk,j j=1 e cmk ,i yk,i log
(2)
Under this assumption, the OCE value for a single sample k can be written as: I h X OCEk = − cmk ,mk zk,mk − cmk ,mk log ezk,j j=1
+
I X
cmk ,i log
i=1 i̸=mk
I X
ezk,j − ezk,i
(3)
j=1
I i X − log ezk,j . j=1
Calculating the derivative for zk,v , we get: ∇zk,v OCEk = − cmk ,mk δv,mk + cmk ,mk p̂k,v X X cmk ,i + p̂k,v cmk ,i − p̂k,v 1 − p̂k,i i∈{m / k ,v}
i̸=mk
(4) where δv,mk denotes the Kronecker delta, defined as ( 1, if v = mk , δv,mk = 0, otherwise. Note that the development of Equation (4) is presented in the Appendix. It can be shown that the derivative of OCE in Equation (4) maintains several properties, as follows. Property 1. The gradient for the observed class ∇zk,mk OCEk is non-positive and approaches zero as p̂k,mk increases and the probabilities of unobserved classes decrease. Proof. For v = mk : ∇zk,mk OCEk = − cmk ,mk (1 − p̂k,mk ) X cm ,i k − cmk ,i − p̂k,mk 1 − p̂k,i
(5)
i̸=mk
Since 0 ≤ p̂k,i ≤ 1, ∇zk,mk OCEk is non-positive. It can be seen from the first term, −cmk ,mk (1 − p̂k,mk ), that ∇zk,mk OCEk decreases in magnitude as p̂k,mk increases and the remaining probabilities decrease. From the second term, P c ,i p̂k,mk i̸=mk 1−mp̂kk,i − cmk ,i , we see that ∇zk,mk OCEk
Property 2. The gradient for an unobserved class ∇zk,v OCEk , ∀v ̸= mk , is proportional to p̂k,v P P and isc non,i negative whenever cmk ,mk + i̸=m cmk ,i ≥ i̸=m,v 1−mp̂kk,i . In this case, the gradient increases in magnitude as p̂k,v increases. Proof. For an unobserved class v ̸= mk , the gradient of the OCE loss with respect to zk,v can be written as X X ∇zk,v OCEk = p̂k,v cmk ,i − cmk ,mk + i̸=mk
i̸=mk i̸=v
cmk ,i . 1 − p̂k,i
Since p̂k,v ≥ 0, the sign of the gradient is determined by the bracketed term. Hence, ∇zk,v OCEk is non-negative whenever the bracketed expression is non-negative. Under this condition, the magnitude of the gradient increases as p̂k,v increases, as it appears as a multiplicative factor. Property 3. The gradient satisfies ∇zk,v OCEk = 0 for all v under perfect classification, i.e., when p̂k,mk = 1 and p̂k,v = 0 for all v ̸= mk . Proof. From Property 1, the gradient for the observed class satisfies ∇zk,mk OCEk = 0 when p̂k,mk = 1 and p̂k,v = 0 for all v ̸= mk . From Property 2, the gradient for any unobserved class v ̸= mk is proportional to p̂k,v and therefore equals zero when p̂k,v = 0. Hence, ∇zk,v OCEk = 0 for all v under perfect classification. It can be seen that when the benefit associated with correct classification dominates the penalties of misclassification, namely, cmk ,mk ≫ cmk ,i , ∀i ̸= mk , the condition X X cm ,i k cmk ,mk + cmk ,i ≥ 1 − p̂k,i i̸=mk
i̸=mk i̸=v
is satisfied. Under this condition, the gradient ∇zk,v OCEk , v ̸= mk , is non-negative and increases in magnitude as p̂k,v increases. However, when there exists an unobserved class i ̸= mk , v such that p̂k,i → 1, the above condition no longer holds, and instead X X cm ,i k . cmk ,mk + cmk ,i < 1 − p̂k,i i̸=mk
i̸=mk i̸=v
In this case, the bracketed term in the gradient expression becomes negative, and consequently ∇zk,v OCEk < 0 for that class v ̸= mk . In other words, increasing zk,v , or equivalently the predicted probability p̂k,v , at the expense of a highly confident unobserved class p̂k,i may decrease the OCE value. Figure 2 shows the OCE gradient behavior compared to OL gradient behavior.
OCE Gradient c2, 2 = 1
OCE Gradient c2, 2 = 10
Grad (Class 0) Grad (Class 1) Grad (Class 2 - True)
10
OCE Gradient c2, 2 = 20
Grad (Class 0) Grad (Class 1) Grad (Class 2 - True)
Grad (Class 0) Grad (Class 1) Grad (Class 2 - True)
Gradient Value
5 0 5 10 15 20 0.0
0.2
0.4
0.6
0.8
True Class Probability (p)
1.0
0.0
0.2
0.4
0.6
0.8
True Class Probability (p)
OL Gradient c2, 2 = 1
1.0
0.0
OL Gradient c2, 2 = 10
0.2
0.4
0.6
0.8
1.0
0.8
1.0
True Class Probability (p)
OL Gradient c2, 2 = 20
Grad (Class 0) Grad (Class 1) Grad (Class 2 - True)
4 2
Gradient Value
further decreases in magnitude as p̂k,i , ∀i ̸= mk , decreases. Furthermore, a change in predicted probabilities of unobserved classes with high costs cmk ,i (high risk) has a greater effect than those with low penalty costs.
0
Grad (Class 0) Grad (Class 1) Grad (Class 2 - True)
2 4 Grad (Class 0) Grad (Class 1) Grad (Class 2 - True)
6 0.0
0.2
0.4
0.6
0.8
True Class Probability (p)
1.0
0.0
0.2
0.4
0.6
0.8
True Class Probability (p)
1.0
0.0
0.2
0.4
0.6
True Class Probability (p)
Fig. 2. Visualization of the gradient dynamics for Ordinal Cross-Entropy (OCE) and Ordinal Loss (OL) across different values of the true-class penalty c2,2 . 𝑰𝒏𝒑𝒖𝒕
𝑃𝑒𝑛𝑎𝑙𝑡𝑦 𝑐𝑜𝑠𝑡𝑠 𝑎𝑛𝑑 𝑏𝑒𝑛𝑒𝑓𝑖𝑡𝑠 𝑚𝑎𝑡𝑟𝑖𝑥 𝒗𝟑
𝒗𝟒
𝑜𝑛𝑒 − ℎ𝑜𝑡 𝑣𝑒𝑐𝑡𝑜𝑟
𝑃𝑟𝑒𝑑𝑖𝑐𝑡𝑒𝑑 𝑝𝑟𝑜𝑏𝑎𝑏𝑖𝑙𝑖𝑡𝑖𝑒𝑠
𝐴 𝑓𝑢𝑛𝑑𝑢𝑠 𝑖𝑚𝑎𝑔𝑒 𝑡 𝑓𝑟𝑜𝑚 𝑎 𝑟𝑒𝑡𝑖𝑛𝑎 𝑤𝑖𝑡ℎ 𝑔𝑟𝑎𝑑𝑒 𝑙𝑒𝑣𝑒𝑙 4, 𝑣
𝑝̂ ,
0.12
𝑦,
0
𝑝̂ ,
0.01
𝑦,
0
𝑝̂ ,
0.05
𝑦,
0
𝑝̂ ,
0.82
𝑦,
1
𝑝̂ ,
0
𝑦,
0
𝑝𝑒𝑛𝑎𝑙𝑡𝑦 𝑐𝑜𝑠𝑡𝑠 𝑎𝑛𝑑 𝑏𝑒𝑛𝑓𝑖𝑡 𝑣𝑒𝑐𝑡𝑜𝑟 𝑓𝑜𝑟 𝑠𝑚𝑎𝑝𝑙𝑒 𝑡
𝒗𝟏
𝒗𝟐
𝒗𝟓
𝒗𝟏
1
0.4
0.6
0.8
1
𝒗𝟐
0.4
1
0.4
0.6
0.8
𝒗𝟑
0.6
0.4
1
0.4
0.6
𝒗𝟒
0.8
0.6
0.4
1
0.4
𝑐 ,
1
𝒗𝟓
1
0.8
0.6
0.4
1
𝑐 ,
0.4
𝑐 ,
0.8
𝑐 ,
0.6
𝑐 ,
0.4
𝑐 , 𝑦 , log(𝑝̂ , ) + 1 − 𝑦 , log(1 − 𝑝̂ , ) 𝑜𝑏𝑠𝑒𝑟𝑣𝑒𝑑 𝑐𝑙𝑎𝑠𝑠 𝑐𝑜𝑛𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛 𝑂𝐶𝐸
= 1 ⋅ log(0.82) 𝑢𝑛𝑜𝑏𝑠𝑒𝑟𝑣𝑒𝑑 𝑐𝑙𝑎𝑠𝑠 𝑐𝑜𝑛𝑡𝑟𝑖𝑏𝑢𝑡𝑖𝑜𝑛
= −0.8 ⋅ log 0.88 − 0.6 ⋅ log 0.99 − 0.4 ⋅ log(0.95)
Fig. 3. Illustration of the proposed ordinal cross-entropy loss for a diabetic retinopathy sample with true class 4, using the penalty matrix from 1a.
C. Intuition and Interpretation The OCE loss preserves the logarithmic sensitivity of crossentropy while modifying it to account for the severity of ordinal errors. For the true class mk , the reward for correct prediction is weighted by the corresponding benefit cmk ,mk , whereas for incorrect classes the penalty increases as a function of both the model’s confidence p̂k,i and the associated misclassification cost cmk ,i . Consequently, high-probability and clinically severe mistakes contribute substantially more to the loss than low-risk or near-adjacent errors. Figure 3 illustrates the OCE computation for a retina diagnosed with grade level 4, using the symmetric ordinal penalty matrix presented in Fig. 1a. In this example, correct predictions are rewarded with a benefit value of 10, emphasizing the importance of confident predictions when distinguishing between late-stage and early-stage diagnoses. Figure 4 illustrates how the contributions of individual classes to the OCE loss vary as the predicted probability of the true class p̂t,4 increases. As confidence in the correct class grows, its loss contribution decreases logarithmically, while penalties from unobserved classes diminish accordingly. Notably, the observed class has a dominant influence on the loss, and unobserved classes with higher misclassification costs contribute more strongly, reflecting ordinal distance and task-specific risk.
TABLE I D ISTRIBUTION OF DR G RADES IN THE APTOS 2019 T RAINING S ET DR Grade
Grade Name
Total Images
0 1 2 3 4
No DR Mild DR Moderate DR Severe DR Proliferative DR
1805 370 999 193 295
C. Architectures and Experimental Setup Fig. 4. Contribution of class i to the ordinal cross-entropy for a sample t with observed class v4 , shown for a range of predictive probabilities p̂t,: based on the penalty vector c:,4 from Figure 3.
Severe Normal Mild Proliferative Moderate Fig. 5. Example images from all five diabetic retinopathy (DR) severity levels.
III. E XPERIMENTS AND R ESULTS The primary objective of our experiments is to evaluate whether the proposed OCE loss effectively minimizes the total misclassification cost defined by a task-specific ordinal cost matrix. Standard metrics such as accuracy, AUC, and MAE are reported as complementary indicators, but cost minimization is the central criterion, as it directly reflects the real-world severity of ordinal errors. To assess the robustness of OCE under different risk profiles, we conduct experiments using both symmetric cost matrices, where overestimation and underestimation are penalized equally, and asymmetric cost matrices, which assign different costs to overestimation and underestimation to reflect direction-dependent, applicationspecific risk. A. Dataset The APTOS 2019 Blindness Detection dataset consists of retinal fundus images for automated diabetic retinopathy (DR) grading, released as part of the Kaggle APTOS 2019 Blindness Detection competition. Each image is labeled with an ordinal severity grade from 0 (“No DR”) to 4 (“Proliferative DR”). The training set includes 3,662 labeled RGB images with varying resolutions and substantial variability in acquisition conditions, as well as a strong class imbalance toward the “No DR” class, making the task particularly challenging and well-suited for ordinal and cost-sensitive learning. B. Cost Matrix Figure 1a illustrates the symmetric ordinal cost structure used for direct comparison with existing methods, while Fig. 1b presents an asymmetric variant that assigns different penalties to overestimation and underestimation, reflecting application-specific risk profiles.
To assess the robustness of the proposed OCE loss across different network capacities and feature extraction strategies, we evaluate it on three widely used convolutional architectures: VGG19, InceptionV3, and DenseNet121. All models are initialized with ImageNet pre-trained weights and trained under identical experimental conditions to isolate the effect of the loss function. Training is performed for 25 epochs using the Adam optimizer with a default learning rate of 1e−3 and a batch size of 32. We compare seven loss functions: the proposed Ordinal Cross-Entropy (OCE) with penalty matrix P ; standard crossentropy (CE); cross-entropy with unimodal beta-based label regularisation (CE-β) [17]; cross-entropy with poisson label regularisation (CE-P) [16]; cross-entropy with binomial label regularisation (CE-B) [16]; cross-entropy with exponential label regularisation (CE-E) [15]; and Ordinal Loss (OL) based on distance-aware penalty designs proposed in Chen et al. [23]. For OL, we evaluate several distance-based penalty designs proposed by Chen et al. [23], and report results of the design that achieves the best empirical performance among the evaluated variants. To evaluate asymmetric ordinal risk, we modify only loss functions that explicitly incorporate a penalty matrix. For OCE, we replace the symmetric matrix with the asymmetric design shown in Figure. 1b. For OL, we adapt the distance-based penalty matrix used in the symmetric setting by halving the upper triangular entries, thereby imposing milder penalties on overestimation. For CE and its regularized variants, which do not incorporate penalty matrices into the loss, asymmetry is applied only at the evaluation stage. D. Evaluation Metrics The primary metric for evaluating model performance is the Cost, defined as the average misclassification cost induced by a predefined cost matrix C. In practice, the cost error is computed as the product of the confusion matrix and the cost matrix C, normalized by the total number of samples: N 1 X Cost Error = cyk ,yˆk , N k=1
where yk and ŷk denote the true and predicted class labels of sample k, respectively. This metric directly reflects the severity of ordinal misclassification errors according to their real-world impact.
TABLE II AVERAGE VALIDATION PERFORMANCE ACROSS 5 FOLDS UNDER A SYMMETRIC COST MATRIX . B OLD AND UNDERLINED VALUES INDICATE THE BEST AND SECOND - BEST RESULTS . DenseNet121 OCE (ours) CE-β [17] CE-P [16] CE-B [16] CE-E [15] CE OL [23] InceptionV3 OCE (ours) CE-β [17] CE-P [16] CE-B [16] CE-E [15] CE OL [23] VGG19 OCE (ours) CE-β [17] CE-P [16] CE-B [16] CE-E [15] CE OL [23]
Acc 0.784 0.782 0.756 0.774 0.789 0.781 0.740 Acc 0.772 0.764 0.743 0.739 0.762 0.774 0.734 Acc 0.758 0.759 0.754 0.750 0.759 0.756 0.726
AUC 0.897 0.854 0.860 0.784 0.823 0.896 0.714 AUC 0.878 0.828 0.826 0.694 0.803 0.878 0.662 AUC 0.821 0.859 0.762 0.807 0.845 0.827 0.677
Cost 1.081 1.095 1.219 1.096 1.043 1.098 1.260 Cost 1.147 1.174 1.307 1.263 1.164 1.135 1.307 Cost 1.220 1.268 1.266 1.292 1.249 1.244 1.366
MAE 0.324 0.329 0.366 0.322 0.310 0.330 0.370 MAE 0.345 0.351 0.396 0.371 0.344 0.341 0.387 MAE 0.368 0.393 0.387 0.396 0.383 0.378 0.409
QWK 0.803 0.804 0.766 0.823 0.824 0.798 0.778 QWK 0.791 0.793 0.767 0.802 0.807 0.795 0.761 QWK 0.774 0.720 0.729 0.731 0.732 0.770 0.735
In addition, we report the following complementary evaluation metrics: Accuracy, Area Under the ROC Curve (AUC), Mean Absolute Error (MAE) and Quadratic Weighted Kappa (QWK) [29]. These metrics provide supplementary performance insights; however, they do not replace the cost-based evaluation, which remains the primary criterion in this work. E. Results Table II summarizes the average validation performance across five cross-validation folds for all evaluated architectures under a symmetric cost matrix. Across all architectures, the proposed OCE loss consistently achieves the best or secondbest misclassification Cost, which is the primary evaluation criterion. At the same time, OCE maintains competitive MAE and strong discriminative performance, with accuracy, AUC, and QWK values comparable to the competing loss functions. Table III reports the average validation performance across five cross-validation folds for all evaluated architectures under an asymmetric cost matrix. Across all architectures, the proposed OCE loss consistently achieves the best or secondbest performance in terms of misclassification Cost and MAE, which are the primary criteria under asymmetric risk settings. In addition, OCE maintains competitive and often superior performance in complementary metrics, including accuracy, AUC, and QWK, indicating that explicitly modeling asymmetric ordinal risk does not compromise overall discriminative ability. These results demonstrate the robustness of OCE to asymmetric cost structures and its effectiveness in prioritizing clinically meaningful errors. Overall, the asymmetric setting amplifies the advantage of OCE in minimizing risk-weighted ordinal errors, demonstrat-
TABLE III AVERAGE VALIDATION PERFORMANCE ACROSS 5 FOLDS UNDER AN ASYMMETRIC COST MATRIX . B OLD AND UNDERLINED VALUES INDICATE THE BEST AND SECOND - BEST RESULTS . DenseNet121 OCE (ours) CE-β [17] CE-P [16] CE-B [16] CE-E [15] CE OL [23] InceptionV3 OCE (ours) CE-β [17] CE-P [16] CE-B [16] CE-E [15] CE OL [23] VGG19 OCE (ours) CE-β [17] CE-P [16] CE-B [16] CE-E [15] CE OL [23]
Acc 0.788 0.782 0.756 0.774 0.789 0.781 0.739 Acc 0.774 0.764 0.743 0.739 0.762 0.774 0.695 Acc 0.755 0.759 0.754 0.750 0.759 0.756 0.648
AUC 0.898 0.854 0.860 0.784 0.823 0.896 0.662 AUC 0.880 0.828 0.826 0.694 0.803 0.878 0.644 AUC 0.851 0.859 0.762 0.807 0.845 0.827 0.670
Cost 1.755 1.864 2.113 1.812 1.742 1.883 2.111 Cost 1.860 1.972 2.301 2.031 1.917 1.900 2.623 Cost 2.054 2.288 2.258 2.306 2.246 2.068 3.518
MAE 0.312 0.329 0.366 0.322 0.310 0.330 0.374 MAE 0.340 0.351 0.396 0.371 0.344 0.341 0.447 MAE 0.381 0.393 0.387 0.396 0.383 0.378 0.602
QWK 0.820 0.804 0.766 0.823 0.824 0.798 0.773 QWK 0.800 0.793 0.767 0.802 0.807 0.795 0.703 QWK 0.767 0.720 0.729 0.731 0.732 0.770 0.522
ing its ability to adapt to application-specific misclassification asymmetries without degrading discriminative performance. Figure 6 compares the classification behavior of the DenseNet121 model when trained with the symmetric and asymmetric variants of the OCE loss. The upper triangular region corresponds to overestimation errors (i.e., predicting a higher severity class than the ground truth), while the lower triangular region corresponds to underestimation errors. The asymmetric OCE reduces the magnitude and frequency of underestimation errors while simultaneously encouraging predictions to deviate in the correct ordinal direction. This behavior indicates that the asymmetric formulation imposes a directional preference that aligns model predictions more closely with the ordinal structure of the task, ultimately leading to more clinically meaningful error patterns. The effectiveness of the proposed framework is further supported by evaluation of the impact of the diagonal term cmk ,mk , which represents the benefit for correct classification. When the diagonal of the penalty matrix was set to zero, the average misclassification cost increased by 13.1 % in the symmetric setting and 14.7 % in the asymmetric setting. This confirms that the diagonal term is essential for providing the necessary gradient signal to prioritize correct predictions alongside penalty minimization. IV. C ONCLUSIONS We proposed Ordinal Cross-Entropy (OCE), a simple and general loss function for ordinal classification that extends standard cross-entropy by incorporating distance-aware and asymmetric misclassification costs. OCE preserves the probabilistic interpretation and optimization advantages of crossentropy while enabling explicit modeling of ordinal structure and clinically meaningful risk.
16
-1
0
-1
6
4
3
8
0
1
2 Column Index
3
4
0
0
Row Index 2 1
0
-2 -3
-6
3
2
1
1
-11
4
Row Index 2 1
0
-1
-2
-4
-16
0
0
1
2 Column Index
3
4
Fig. 6. Impact of Asymmetric OCE on Overestimation (left) and Underestimation (right) Errors in DenseNet121
Theoretical analysis showed that OCE induces smooth and stable gradient dynamics, encouraging confident predictions and penalizing high-risk ordinal errors proportionally to their severity and direction. Empirical results demonstrated that OCE consistently achieves lower misclassification cost than state-of-the-art ordinal approaches across multiple architectures, under symmetric and asymmetric risk settings, while maintaining competitive performance on standard metrics. This study has several limitations. First, the evaluation is conducted on a single medical dataset, and additional validation across diverse domains would further strengthen the generality of the findings. Second, the cost matrix parameters are predefined and not learned adaptively, which may limit flexibility in certain applications. Future work will focus on integrating adaptive mechanisms that dynamically adjust the parameters of the OCE loss during training. Such mechanisms may allow the loss function to progressively emphasize clinically critical errors and further improve ordinal consistency and risk-aware performance. ACKNOWLEDGMENT Gemini AI was used for language and grammar editing. R EFERENCES [1] K. He, X. Zhang, S. Ren, and J. Sun, “Deep residual learning for image recognition,” in Proceedings of the IEEE conference on computer vision and pattern recognition, 2016, pp. 770–778. [2] W. Zhu, C. Liu, W. Fan, and X. Xie, “Deeplung: 3d deep convolutional nets for automated pulmonary nodule detection and classification,” arXiv preprint arXiv:1709.05538, 2017. [3] D. Shen, G. Wu, and H.-I. Suk, “Deep learning in medical image analysis,” Annual review of biomedical engineering, vol. 19, no. 1, pp. 221–248, 2017. [4] M. A. Abdou, “Literature review: Efficient deep neural networks techniques for medical image analysis,” Neural Computing and Applications, vol. 34, no. 8, pp. 5791–5812, 2022. [5] C. Chen, N. A. M. Isa, and X. Liu, “A review of convolutional neural network based methods for medical image classification,” Computers in biology and medicine, vol. 185, p. 109507, 2025. [6] X. Geng, Z.-H. Zhou, and K. Smith-Miles, “Automatic age estimation based on facial aging patterns,” IEEE Transactions on pattern analysis and machine intelligence, vol. 29, no. 12, pp. 2234–2240, 2007. [7] L. Bertinetto, R. Mueller, K. Tertikas, S. Samangooei, and N. A. Lord, “Making better mistakes: Leveraging class hierarchies with deep networks,” in Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, 2020, pp. 12 506–12 515. [8] V. Gulshan, L. Peng, M. Coram, M. C. Stumpe, D. Wu, A. Narayanaswamy, S. Venugopalan, K. Widner, T. Madams, J. Cuadros et al., “Development and validation of a deep learning algorithm for detection of diabetic retinopathy in retinal fundus photographs,” jama, vol. 316, no. 22, pp. 2402–2410, 2016.
[9] B. Abraham and M. S. Nair, “Automated grading of prostate cancer using convolutional neural network and ordinal class classifier,” Informatics in Medicine Unlocked, vol. 17, p. 100256, 2019. [10] L. Shen, L. R. Margolies, J. H. Rothstein, E. Fluder, R. McBride, and W. Sieh, “Deep learning to improve breast cancer detection on screening mammography,” Scientific reports, vol. 9, no. 1, p. 12495, 2019. [11] J. Barbero-Gómez, P.-A. Gutiérrez, V.-M. Vargas, J.-A. Vallejo-Casas, and C. Hervás-Martı́nez, “An ordinal cnn approach for the assessment of neurological damage in parkinson’s disease patients,” Expert Systems with Applications, vol. 182, p. 115271, 2021. [12] W. Cao, V. Mirjalili, and S. Raschka, “Rank consistent ordinal regression for neural networks with application to age estimation,” Pattern Recognition Letters, vol. 140, pp. 325–331, 2020. [13] X. Shi, W. Cao, and S. Raschka, “Deep neural networks for rankconsistent ordinal regression based on conditional probabilities,” Pattern Analysis and Applications, vol. 26, no. 3, pp. 941–955, 2023. [14] C. Beckham and C. Pal, “Unimodal probability distributions for deep ordinal classification,” in International Conference on Machine Learning. PMLR, 2017, pp. 411–419. [15] X. Liu, F. Fan, L. Kong, Z. Diao, W. Xie, J. Lu, and J. You, “Unimodal regularized neuron stick-breaking for ordinal classification,” Neurocomputing, vol. 388, pp. 34–44, 2020. [16] J. F. P. da Costa, H. Alonso, and J. S. Cardoso, “The unimodal model for the classification of ordinal data,” Neural Networks, vol. 21, no. 1, pp. 78–91, 2008. [17] V. M. Vargas, P. A. Gutiérrez, and C. Hervás-Martı́nez, “Unimodal regularisation based on beta distribution for deep ordinal regression,” Pattern Recognition, vol. 122, p. 108310, 2022. [18] D. Sloane and S. P. Morgan, “An introduction to categorical data analysis,” Annual review of sociology, vol. 22, no. 1, pp. 351–375, 1996. [19] W. Tang, Z. Yang, and Y. Song, “Disease-grading networks with ordinal regularization for medical imaging,” Neurocomputing, vol. 545, p. 126245, 2023. [20] W. Tang and Z. Yang, “Disease-grading networks with asymmetric gaussian distribution for medical imaging,” IEEE Transactions on Medical Imaging, 2025. [21] Y. S. Aurelio, G. M. De Almeida, C. L. de Castro, and A. P. Braga, “Learning from imbalanced data sets with weighted cross-entropy function,” Neural processing letters, vol. 50, no. 2, pp. 1937–1949, 2019. [22] M. Akil, R. Saouli, R. Kachouri et al., “Fully automatic brain tumor segmentation with deep learning-based selective attention using overlapping patches and multi-class weighted cross-entropy,” Medical image analysis, vol. 63, p. 101692, 2020. [23] P. Chen, L. Gao, X. Shi, K. Allen, and L. Yang, “Fully automatic knee osteoarthritis severity grading using deep neural networks with a novel ordinal loss,” Computerized Medical Imaging and Graphics, vol. 75, pp. 84–92, 2019. [24] P. G. Conaghan, M. Porcheret, S. R. Kingsbury, A. Gammon, A. Soni, M. Hurley, M. P. Rayman, J. Barlow, R. G. Hull, J. Cumming et al., “Impact and therapy of osteoarthritis: the arthritis care oa nation 2012 survey,” Clinical rheumatology, vol. 34, no. 9, pp. 1581–1588, 2015. [25] T. Neogi, “The epidemiology and impact of pain in osteoarthritis,” Osteoarthritis and cartilage, vol. 21, no. 9, pp. 1145–1153, 2013. [26] J. M. Ortman, V. A. Velkoff, and H. Hogan, “An aging nation: The older population in the united states,” U.S. Census Bureau, Economics and Statistics Administration, U.S. Department of Commerce, Washington, DC, USA, Current Population Reports P25-1140, 2014. [27] H. Zhao, L. Ou, Z. Zhang, L. Zhang, K. Liu, and J. Kuang, “The value of deep learning-based x-ray techniques in detecting and classifying kl grades of knee osteoarthritis: a systematic review and meta-analysis,” European Radiology, vol. 35, no. 1, pp. 327–340, 2025. [28] C. Elkan, “The foundations of cost-sensitive learning,” in International joint conference on artificial intelligence, vol. 17, no. 1. Lawrence Erlbaum Associates Ltd, 2001, pp. 973–978. [29] J. de La Torre, D. Puig, and A. Valls, “Weighted kappa loss function for multi-class classification of ordinal data in deep learning,” Pattern Recognition Letters, vol. 105, pp. 144–154, 2018.
A PPENDIX D ERIVATION OF THE OCE G RADIENT In this appendix, we provide the detailed derivation of the gradient expression given in Equation (4).
OCEk
I I I I X X X X = − cmk ,mk zk,mk − cmk ,mk log ezk,j + cmk ,i log ezk,j − ezk,i − log ezk,j . j=1
∇zk,v OCEk
i=1 i̸=mk
j=1
j=1
cm ,m ezk,v = −cmk ,mk ∇zk,v zk,mk + PkI k zk,j j=1 e P P I zk,j zk,i e − e X cmk ,i ∇zk,v X cmk ,i ∇zk,v Ij=1 ezk,j j=1 − + PI PI zk,j − ezk,i zk,j j=1 e j=1 e i̸=mk i̸=mk X cmk ,i (ezk,v − ∇zk,v ezk,i ) X cm ,i ezk,v cm ,m ezk,v k − + = −cmk ,mk ∇zk,v zk,mk + PkI k P PI I z z z zk,j k,j k,j k,i −e j=1 e j=1 e j=1 e i̸=mk i̸=mk = −cmk ,mk ∇zk,v zk,mk + cmk ,mk p̂k,v −
cmk ,i ezk,v
X i∈{m / k ,v}
= −cmk ,mk δv,mk + cmk ,mk p̂k,v − p̂k,v
X i∈{m / k ,v}
( 1, δv,mk = 0,
if v = mk , otherwise.
PI
j=1 e
zk,j − ezk,i
+ p̂k,v
X cmk ,i + p̂k,v cmk ,i 1 − p̂k,i i̸=mk
X i̸=mk
cmk ,i