【问题标题】:predicting exact probabilities in rpart decision tree model在 rpart 决策树模型中预测精确概率
【发布时间】:2015-11-09 06:55:27
【问题描述】:

而不是 0 或 1,如何计算 rpart 决策树模型中的 96% 或 43% 等精确概率。 我试过了 预测(模型,数据,类型=“概率”) 但它预测的是 0 或 1

【问题讨论】:

标签: r


【解决方案1】:

在创建rpart 对象期间,您必须在参数中指定method = "class" 以确保分类。一旦你这样做了,你的 predict 方法就会给出type="prob" 的概率。

【讨论】:

  • 我已经尝试过它给我的概率为 0 或 1。我想做的是找到像 .97 或 .80 这样的实际概率
  • @NaziaAfreen 也许您的数据实际上产生的结果是 0 或 1 作为概率,即您有一个完美的拟合,并且没有误报的机会。如果你正确地执行了上述步骤,你应该得到它们的概率。
【解决方案2】:

@Nazia Afreen - 下面是 R 脚本,希望这可能会有所帮助。

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##

【讨论】:

    猜你喜欢
    • 2019-05-24
    • 1970-01-01
    • 2017-05-31
    • 2018-04-25
    • 2015-06-16
    • 2015-01-13
    • 2013-07-11
    • 2013-12-21
    • 2023-01-01
    相关资源
    最近更新 更多