12wang3 / rrl

The code of NeurIPS 2021 paper "Scalable Rule-Based Representation Learning for Interpretable Classification" and TPAMI paper "Learning Interpretable Rules for Scalable Data Representation and Classification"
MIT License
106 stars 32 forks source link

How to calculate the weights of the rule and class? #15

Closed Joef98 closed 7 months ago

Joef98 commented 7 months ago

I'm a little confused by the output. rrl.txt as follows:

RID final_status_0(b=0.3015) final_status_1(b=-0.0915) Support Rule (-1, 0) 1.6603 -1.6603 0.6216 a_1 & c > 0.002 (-1, 3) -1.4654 1.4654 0.0541 a_3 & b <= 2.324 & d <= 0.013 (-1, 2) -0.6511 0.6511 0.3357 b > 2.324 & d <= 0.013 (-1, 4) 0.6015 -0.6015 0.0356 a_3 & b > 2.324 (-1, 1) 0.5441 -0.5441 0.9325 c > 0.002 (-1, 5) -0.2566 0.2566 0.7992 d <= 0.013 ############################################################

Why are the absolute values of the finalstatus* columns the same? How should I calculate the weight of each rule under different classes?

12wang3 commented 7 months ago
  1. Since you only have two class labels, if one rule contributes to the positive class, then it will also contribute the same to "not being the negative class". This is why, for binary classification, the absolute values of the weights for each class are the same. If you have more than two classes, the absolute values will be different in each rule.

  2. Just find all the activated rules and sum up their corresponding weights and bias along columns. Then you can calcualte the softmax to get probabilities for each class. For example, in your case, if one instance only activates rule 1 and rule 3, then weight and bias sum for class final_status_0 is 1.6603 + -0.6511 + 0.3015 = 1.3107, for class final_status_1 is -1.6603 + 0.6511 + -0.0915 = -1.1007. Therefore, the probabilities are softmax([1.3107, -1.1007]) = [0.9177, 0.0823], i.e., 91.77% for final_status_0 and 8.23% for final_status_1.

Joef98 commented 7 months ago

Thank a lot.