而不是0或1,如何在rpart决策树模型中计算精确概率,如96%或43%。 我试过了 预测(模型,数据,类型=“概率”) 但它预测0或1
答案 0 :(得分:5)
在创建rpart
对象期间,您必须在参数中指定method = "class"
以确保分类。一旦你这样做,你的预测方法会给出type="prob"
的概率。
答案 1 :(得分:1)
@Nazia Afreen - 下面是R scriptlet,希望这可能有所帮助。
library(rpart)
model <- rpart(dependent_class_variable ~ independent var1 + var 2 + .., data = "your train data", method = "class")
## to get the probabilities of each record
probilities_ <- predict(model, "your test data without quotes", type = "prob")
## it will yield two probabilities, probability of getting class 1, and
## probability of getting class 2, if you have two class. Sum of both = 1##