Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

r - Training Random forest with case weights

I am working now on a model with a random forest that requires me to take into account case weights. I discovered that the ranger package allows me to do this, so I can grow the forest using it directly. Now, for very specific reasons out of the scope of this question, it would be very useful for me to train my model with the caret package (I can do certain things with a caret object that I cannot do with a ranger object). I know that I can grow the random forest using the ranger method under the caret package, but I have tried to pass the argument for the case weights in the instruction with caret, and I always get an error (I can run it without it though). Put it simple, I grow a forest with ranger under the instruction

model=ranger(Response_variable~.,data=my_data,num.trees = 500,
                   case.weights =my_data$WT,seed=129,probability = TRUE)

and I can run the instruction on caret

 fit.caret_test <- train(Response_variable~.,data = my_data, method = 'ranger', trControl = trainControl(method = "cv", number = 5, classProbs = TRUE), tuneLength = 1, importance='impurity')

but in the latter, I cannot spot the right place where to pass the argument "case.weights =my_data$WT" I use on ranger. Can somebody guide me? Thanks in advance!

question from:https://stackoverflow.com/questions/65852812/training-random-forest-with-case-weights

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...