# Rough Set Theory and Soft Computing Methods for Building Explainable and Interpretable AI/ML Models
## 4 Methodology
### Classification
#### 4.2.2 MLSpecialReduct
```
0: Decision system \(DS\), indiscernibility relation \(ind\_c\), decision column \(d\), decision value \(d\_value\)
0: B-upper approximation \(CXi\) or \"error\" if \(d\_value\) not found
1:\(X\gets DS.groupby(d)\)
2:\(Xi\leftarrow\) None
3:for\((name,group)\) in \(X\)do
4:if\(name=d\_value\)then
5:\(Xi\leftarrow\) pd.DataFrame\((group)\)
6:endif
7:endfor
8:if\(Xi\
eq\) None then
9:\(CXi\leftarrow\) list\((Xi.index)\)
10:forindex in \(Xi.index\)do
11:\(id\_obj\gets groupe\_ind\_c\_obj(ind\_c,index)\)
12:list_add\(\leftarrow[index\_obj]2\) for \(index\_obj2\) in \(id\_obj\) if \(DS.at[index\_obj2,d]\
eq DS.at[index,d]]\)
13:\(CXi\gets CXi+list\_add\)
14:endfor
15:\(CXi.sort()\)return\(CXi\)
16:elsereturn\"error\"
17:endif
```  
**Algorithm 10** MLSpecialReduct  
```
0: Decision system \(DS\), decision column \(d\)
0: Subset of attributes \(R\)
1:\(C\leftarrow\) list\((DS.columns)\)
2:\(C.remove(d)\)
3:\(dep\_C\gets dependance\_attributs(DS,DS.columns,d)\)
4:\(R\gets[]\)
5:while True do
6:\(T\gets R\)
7:\(attr\gets T.copy()+[d]\)
8:\(dep\_T\gets dependance\_attributs(DS,attr,d)\)
9:\(C\_R\gets diff\_list(C,R)\)
10:\(change\_flag\leftarrow\) False
11:for\(x\) in C\(\_R\)do
12:\(attr2\gets R.copy()+[x,d]\)
13:\(dep\_R\lambda\leftarrow dependance\_attributs(DS,attr2,d)\)
14:if\(dep\_R\lambda>dep\_T\)then
15:\(T\gets R.copy()+[x]\)
16:\(attr3\gets T.copy()+[d]\)
17:\(dep\_T\gets dependance\_attributs(DS,attr3,d)\)
18:\(change\_flag\leftarrow\) True
19:endif
20:endfor
21:if\(-change\_flag\)thenreturn\"error\"
22:endif
23:\(R\gets T.copy()\)
24:\(attr4\gets R.copy()+[d]\)
25:\(dep\_R\gets dependance\_attributs(DS,attr4,d)\)
26:if\(dep\_R=dep\_C\)thenreturn\(R\)
27:endif
28:endwhile
```  
**Algorithm 10** MLSpecialReduct  
```
0: Decision system \(DS\), decision column \(d\)
0: Subset of attributes \(R\)
1:\(C\leftarrow\) list\((DS.columns)\)
2:\(C.remove(d)\)
3:\(dep\_C\gets dependance\_attributs(DS,DS.columns,d)\)
4:\(R\gets[]\)
5:while True do
6:\(T\gets R\)
7:\(attr\gets T.copy()+[d]\)
8:\(dep\_T\gets dependance\_attributs(DS,attr,d)\)
9:\(C\_R\gets diff\_list(C,R)\)
10:\(change\_flag\leftarrow\) False
11:for\(x\) in C\(\_R\)do
12:\(attr2\gets R.copy()+[x,d]\)
13:\(dep\_R\lambda\leftarrow dependance\_attributs(DS,attr2,d)\)
14:if\(dep\_R\lambda>dep\_T\)then
15:\(T\gets R.copy()+[x]\)
16:\(attr3\gets T.copy()+[d]\)
17:\(dep\_T\gets dependance\_attributs(DS,attr3,d)\)
18:\(change\_flag\leftarrow\) True
19:endif
20:endfor
21:if\(-change\_flag\)thenreturn\"error\"
22:endif
23:\(R\gets T.copy()\)
24:\(attr4\gets R.copy()+[d]\)
25:\(dep\_R\gets dependance\_attributs(DS,attr4,d)\)
26:if\(dep\_R=dep\_C\)thenreturn\(R\)
27:endif
28:endwhile
```  
**Algorithm 11** MLSpecialReduct  
```
0: Decision system \(DS\), decision column \(d\)
0: Subset of attributes \(R\)
1:\(C\leftarrow\) list\((DS.columns)\)
2:\(C.remove(d)\)
3:\(dep\_C\gets dependance\_attributs(DS,DS.columns,d)\)
4:\(R\gets[]\)
5:while True do
6:\(T\gets R\)
7:\(attr\gets T.copy()+[d]\)
8:\(dep\_T\gets dependance\_attributs(DS,attr,d)\)
9:\(C\_R\gets diff\_list(C,R)\)
10:\(change\_flag\leftarrow\) False
11:for\(x\) in C\(\_R\)do
12:\(attr2\gets R.copy()+[x,d]\)
13:\(dep\_R\lambda\leftarrow dependance\_attributs(DS,attr2,d)\)
14:if\(dep\_R\lambda>dep\_T\)then
15:\(T\gets R.copy()+[x]\)
16:\(attr3\gets T.copy()+[d]\)
17:\(dep\_T\gets dependance\_attributs(DS,attr3,d)\)
18:\(change\_flag\leftarrow\) True
19:endif
20:endfor
21:if\(-change\_flag\)thenreturn\"error\"
22:endif
23:\(R\gets T.copy()+[d]\)
24:\(attr4\gets R.copy()+[d]\)
25:\(dep\_R\gets dependance\_attributs(DS,attr4,d)\)
26:if\(dep\_R=dep\_C\)thenreturn\(R\)
27:endif
28:endwhile
```  
**Algorithm 12** MLSpecialReduct  
```
0: Decision system \(DS\), decision column \(d\)
1:\(C\leftarrow\) list\((DS.columns)\)
2:\(C.remove(d)\)
3:\(dep\_C\gets dependance\_attributs(DS,DS.columns,d)\)
4:\(R\gets[]\)
5:while True do
6:\(T\gets R\)
7:\(attr\gets T.copy()+[d]\)
8:\(dep\_T\gets dependance\_attributs(DS,attr,d)\)
9:\(C\_R\gets diff\_list(C,R)\)
10:\(change\_flag\leftarrow\) False
11:for\(x\) in C\(\_R\)do
12:\(attr2\gets R.copy()+[x,d]\)
13:\(dep\_R\lambda\leftarrow dependance\_attributs(DS,attr2,d)\)
14:if\(dep\_R\lambda>dep\_T\)then
15:\(T\gets R.copy()+[x]\)
16:\(attr3\gets T.copy()+[d]\)
17:\(dep\_T\gets dependance\_attributs(DS,attr3,d)\)
18:\(change\_flag\leftarrow\) True
19:endif
20:endfor
21:if\(-change\_flag\)thenreturn\"error\"
22:endif
23:\(R\gets T.copy()+[d]\)
24:\(attr4\gets R.copy()+[d]\)
25:\(dep\_R\gets dependance\_attributs(DS,attr4,d)\)
26:if\(dep\_R=dep\_C\)thenreturn\(R\)
27:endif
28:endwhile
```  
**Algorithm 13** MLSpecialReduct  
```
0: Decision system \(DS\), decision column \(d\)
1:\(C\leftarrow\) list\((DS.columns)\)
2:\(C.remove(d)\)
3:\(dep\_C\gets dependance\_attributs(DS,DS.columns,d)\)
4:\(R\gets[]\)
5:while True do
6:\(T\gets R\)
7:\(attr\gets T.copy()+[d]\)
8:\(dep\_T\gets dependance\_attributs(DS,attr,d)\)
9:\(C\_R\gets diff\_list(C,R)\)
10:\(change\_flag\leftarrow\) False
11:for\(x\) in C\(\_R\)do
12:\(attr2\gets R.copy()+[x,d]\)
13:\(dep\_R\lambda\leftarrow dependance\_attributs(DS,attr2,d)\)
14:if\(dep\_R\lambda>dep\_T\)then
15:\(T\gets R.copy()+[x]\)
16:\(attr3\gets T.copy()+[d]\)
17:\(dep\_T\gets dependance\_attributs(DS,attr3,d)\)
18:\(change\_flag\leftarrow\) True
19:endif
20:endfor
21:if\(-change\_flag\)thenreturn\"error\"
22:endif
24:\(R\gets T.copy()+[d]\)
25:\(dep\_R\gets dependance\_attributs(DS,attr4,d)\)
26:if\(dep\_R=dep\_C\)thenreturn\(R\)
27:endif
28:endwhile
```  
**Algorithm 14** MLSpecialReduct  
```
0: Decision system \(DS\), decision column \(d\)
1:\(C\leftarrow\) list\((DS.columns)\)
2:\(C.remove(d)\)
3:\(dep\_C\gets dependance\_attributs(DS,DS.columns,d)\)
4:\(R\gets[]\)
5:while True do
6:\(T\gets R\)
7:\(attr\gets T.copy()+[d]\)
8:\(dep\_T\gets dependance\_attributs(DS,attr,d)\)
9:\(C\_R\gets diff\_list(C,R)\)
10:\(change\_flag\leftarrow\) False
11:for\(x\) in C\(\_R\)do
12:\(attr2\gets R.copy()+[x,d]\)
13:\(dep\_R\lambda\leftarrow dependance\_attributs(DS,attr2,d)\)
14:if\(dep\_R\lambda>dep\_T\)then
15:\(T\gets R.copy()+[x]\)
16:\(attr3\gets T.copy()+[d]\)
17:\(dep\_T\gets dependance\_attributs(DS,attr3,d)\)
18:\(change\_flag\leftarrow\) True
19:endif
20:endfor
21:if\(-change\_flag\)thenreturn\"error\"
22:endif
23:\(R\gets T.copy()+[d]\)
24:\(attr4\gets R.copy()+[d]\)
25:\(dep\_R\gets dependance\_attributs(DS,attr4,d)\)
26:if\(dep\_R=dep\_C\)thenreturn\(R\)

#### 4.2.3 MLVariance Threshold

The **MLVarianceThreshold** technique, an adaptation of the traditional VarianceThreshold method, removes features from a dataset with variance below a specified threshold.