topepo / caret

caret (Classification And Regression Training) R package that contains misc functions for training and plotting classification and regression models
http://topepo.github.io/caret/index.html
1.61k stars 632 forks source link

variable's name gets modified in varImp #1320

Open spono opened 1 year ago

spono commented 1 year ago

I'm working on a binary classification using randomForest on a SpatRaster. The training data includes two binary (0,1) factor variables, one of which is the target of the classification. Once I train the RF model (cls.model) and check the variable importance, I get that the variable's name is modified from comp_cat_cl to comp_cat_cl1:

>   cls.model = train( mg_cl ~ ., method="rf" , data=training_set
                                  , trControl = trainControl(method="repeatedcv", number=10, repeats=3, search="random") )

> varImp(cls.model)$importance
Overall
comp_cat_cl1 100.00000      <------ "1" gets added to the variable's name
pground       29.53763
pzabove2      29.22343

This weird behaviour disappears if I run directly fom randomForest, I get:

    > cls.model2 = randomForest::randomForest( mgnt_cl ~ ., method="rf" , data=training_set)

    > varImp(cls.model2)
    Overall
    comp_cat_cl  7.717525
    pground      5.044546
    pzabove2     5.306768

here the data test_data.txt