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 634 forks source link

Caseweights in Ranger Function #1086

Closed njain007 closed 4 years ago

njain007 commented 4 years ago

Hi, I am new to R and exploring RF using ranger function. My variables are mostly categorical and having more than 50+ categories. Randomforest function has a limitation of 53 categories so I explored using ranger. However, when I apply case.weights = "WT", I get the following error.

error in rangerCpp(treetype, dependent.variable.name, data.final, variable.names,  : 
  Not compatible with requested type: [type=character; target=double].

Below is my code. Any help is very much appreciated. Thanks.

random_forest_govt2 <- ranger(CS4_govt ~ CS22 + CS23 +  TA10A + Nchild_adult + Income_person + RO3 + RO5 + COPC + HHEDUC + ED6 + CS10 + CS11 + CS12 + CS8 + CS5 + ID11 + ED7 + ID13 + DISTRICT, data=vill2_govt, importance = "impurity", num.trees = 10000, mtry = 10, case.weights = "WT")
topepo commented 4 years ago

It is hard to tell with out a reproducible example, but I suspect that the problem is that your case weight column is not numeric based on:

Not compatible with requested type: [type=character; target=double].

Also, I'm not the maintainer for ranger so ask questions at https://github.com/imbs-hl/ranger.