ndphillips / FFTrees

An R package to create and visualise fast-and-frugal decision trees (FFTs)
https://journal.sjdm.org/17/17217/jdm17217.pdf
135 stars 23 forks source link

Wrong assignement of Cases #229

Closed tkyjsab closed 3 months ago

tkyjsab commented 4 months ago

Hi,

Applying FFtree on enclosed Test dataset to predict disease (binary Diagnosis variable) from 4 parameters, having 5 positive cases and 6 normal cases Using FFtrees v 2.0.0.9000 with R version 4.4.0 Ending up with a tree to predict normal cases rather than positive cases (disease). How can I fix it?

Test Diagnosis Par1 Par2 Par3 Par4 1 1 0.4100000 1486.667 5.200000 2.4 2 1 0.4366667 1525.000 5.266667 1.7 3 0 0.3533333 1534.667 5.800000 1.9 4 0 0.3050000 1533.500 5.566667 1.6 5 1 0.3433333 1519.333 6.233333 1.9 6 0 0.4366667 1517.667 6.433333 2.2 7 1 0.5133333 1501.667 7.333333 2.0 8 0 0.3666667 1507.333 7.200000 2.1 9 0 0.4566667 1534.333 5.266667 1.6 10 0 0.2500000 1544.333 6.466667 2.1 11 1 0.5166667 1478.333 8.133333 3.2

Test$Diagnosis <-as.factor(Test$Diagnosis) summary(Test$Diagnosis)

summary(Test$Diagnosis) 0 1 6 5

Test_fft <- FFTrees(formula = Diagnosis ~ ., data = Test) Test_fft

Test_fft <- FFTrees(formula = Diagnosis ~ ., data = Test) ! Converted criterion to logical (by 'Diagnosis == 0') in 'train' data. ✔ Created an FFTrees object. Ranking 4 cues: ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% | ETA: 0s ✔ Ranked 4 cues (optimizing 'bacc'). ✔ Created 7 FFTs with 'ifan' algorithm (chasing 'bacc'). ✔ Defined 7 FFTs. ✔ Applied 7 FFTs to 'train' data. ✔ Ranked 7 FFTs by 'train' data. ✔ Expressed 7 FFTs in words.

plot(Test_fft)

Test_17072024

hneth commented 4 months ago

Hi @tkyjsab,

I think your problem stems from using a factor variable as your to-be-predicted criterion. FFTrees converts your factor into a logical variable (as the line ! Converted criterion to logical (by 'Diagnosis == 0') in 'train' data. suggests).

An easy fix would be to re-define your criterion as a logical in the desired direction, e.g., Diagnosis <- Diagnosis == 1 prior to generating the FFTs.

Hope this helps — and happy FFTreeing, Hans

tkyjsab commented 4 months ago

Yes indeed, your tip fixed my issue. Thanks for your quick and prompt reply!