# A Comparative Study of Two Rule-Based Explanation Methods for Diabetic Retinopathy Risk Assessment
## 4 Explanation Generation System
```
input :\(R\): The set of decision rules, \(x\): instance to explain, and \(y\): the decision of \(x\) output :\(\delta\): set of counterfactual rules
1\(Q\longleftarrow GetRulesWithDifferentDecision(R,y)\) ;
2\(\delta\longleftarrow\emptyset\);
3\(min\longleftarrow+\infty\);
4 foreachrule \(q\in Q\)do
5\(qlen\longleftarrow nf(q,x)\);
6 if\(qlen<min\)then
7\(\delta\longleftarrow q\);
8\(min\longleftarrow qlen\)
9 else
10 if\(qlen=min\)then
11\(\delta\longleftarrow\delta\cup q\);
12
13 end if
14
15 end for return\(\delta\);
```  
**Algorithm 3**Extraction of counterfactual rules  
The counterfactual examples are useful for the decision maker to understand what changes in the values of the attributes produce a change in the classification label. In Medicine, this knowledge is particularly interesting, as it can tell a patient how she could move to a better category. These instances are obtained from the counterfactual rules \(\delta\) and the original input \(x\). Given a counterfactual rule \(r:q\to y\), and \(x\), we find the instance that needs the minimum changes in \(x\) to satisfy the conditions \(q\). We look at all the attributes in the conditions \(q\) that are not satisfied by \(x\), and then we make the smallest change (up or down) to the values of these attributes to satisfy the conditions in \(q\). Let us take as an example the explanation for the patient \(x\) shown in the first row of Table 1. Using RETIPROGRAM this patient is assigned to class 1. Then, the explanation system will construct the rules in Figure 3. \begin{table}
\begin{tabular}{l l l l l l l l} \hline
**Age** & **Sex** & **EVOL** & **TTM** & **HbA1c** & **CDKEPI** & **MA** & **BMI** & **HTAR** \\ \hline
71.0 & 1 & 14.0 & 2 & 7.4 & 90.07 & 0.0 & 31.05 & 1 \\ \hline — & — & — & — & 6.5 & — & — & — & — \\ — & — & — & 0 & — & — & — & — & — \\ — & — & — & 1 & — & — & — & — & — \\ \hline \end{tabular}
\end{table} 
Table 1: Patient example and counterfactual instances. The activated rule \(r\) is \(R6\) (the applicable one on the given patient). There are four rules that lead to the opposite decision, \(Q=\{R1,R2,R3,R4\}\). Being \(nf(R1,x)=1,nf(R2,x)=1\), \(nf(R3,x)=1\), \(nf(R4,x)=2\), the set of counterfactual rules \(\delta\) are \(\{R1,R2,R3\}\). The final step in the explanation extraction process is to construct the set of counterfactual examples \(\mathbb{C}\). First we take the rule \(R1\) and as its condition \((HbA1c\leq 6.5)\) is false for patient \(x\), we change its values to the smallest below the upper bound of HbA1c, which is 6.5. We repeat this process for the rest of rules in \(\delta\), obtaining two other examples that only make one change in the TTM variable (as the rest of conditions are already satisfied by \(x\)). The obtained counterfactual instances are shown in Table 1 (rows 2-4), in which the empty cells mean that the initial value of that attribute is not changed. We can see that the number of changes in the counterexamples is small. In this example, changing the treatment type would decrease the risk of DR (to class 0); the other option is a decrease of the HbA1c variable, which is the glycated hemoglobin, an indicator of a bad control of the diabetes which affects the blood.