首页 > 解决方案 > 两个预测函数之间的区别

问题描述

专家!

我正在训练数据集上测试逻辑回归模型。我知道“预测”功能可以告诉我一个独特事件发生的概率(type="response")(在这种情况下,一名员工离开了公司)。

我还知道 2019 年 1 月发布了一个名为“Tidypredict”的新包,它还可以预测事件以 95% 的间隔发生的概率。

当我尝试这两种不同的方法时,它显示了同一员工的不同概率。

我研究了这个话题。似乎使用“预测”功能的最佳时机是当最终结果已知时。因为我们可以比较并找出模型的准确度。

当结果未知时使用“Tidypredict”功能。谁能告诉我有什么区别?以下是现成的信息:https ://cran.r-project.org/web/packages/tidypredict/tidypredict.pdf

预测:https ://stat.ethz.ch/R-manual/R-devel/library/stats/html/predict.glm.html

Here is the results for anyone interested: 
test model:         
1         2         3         4         5         6 
0.6633092 0.2440294 0.2031897 0.9038319 0.8374229 0.1735053 
Tidypredict:

    Age         Los Gender Minority test.model       fit
1 xx.xx ThreeToFive   Male Minority  0.6633092 0.7116757
2 xx.xx   ZeroToOne   Male Minority  0.2440294 0.6834286
3 xx.xx   ZeroToOne Female Minority  0.2031897 0.6303713
4 xx.xx TentoTwenty   Male Minority  0.9038319 0.6963801
5 xx.xx ThreeToFive   Male Minority  0.8374229 0.8658365
6 xx.xx   ZeroToOne Female Minority  0.1735053 0.5840209



      #logistic model# 
model1=glm(Leave~.,family="binomial",data=train)
       #Predict function# 
    test.model<-predict(model1,newdata=test1,type="response")
      #Tidypredict function#
       emp_risk<-test1%>%
       tidypredict_to_column(model1)

标签: r

解决方案


我无法重现您的问题 - 这是一个可重现的示例,说明来自的预测predict()tidypredict_to_column(). 我的建议 - 深入研究一个不匹配的特定示例并找出差异。如果您发布可重现的示例,您将获得更具体的帮助:

library(titanic)
library(dplyr)
library(tidypredict)
d <- titanic_train
mod <- glm(Survived ~ Pclass + Sex + Age + SibSp + Parch, data = d, family = "binomial")

d <- d %>% tidypredict_to_column(mod)
d$fit2 <- predict(mod, newdata = d, type = "response")
summary(d$fit - d$fit2)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
#>       0       0       0       0       0       0     177

reprex 包(v0.2.1)于 2019 年 4 月 1 日创建


推荐阅读