专家!
我正在测试训练数据集上的逻辑回归模型。我知道“预测”功能可以告诉我发生的独特事件的概率(类型=“响应”)(在这种情况下,一名员工离开公司)。
我也知道在2019年1月发布了一个名为“Tidypredict”的新包,它还预测了事件以95%的间隔发生的可能性。
当我尝试这两种不同的方法时,它显示了同一员工的不同概率。
我研究了这个话题。似乎使用“预测”功能的最佳时机是最终结果已知。因为我们可以比较并找出模型的准确程度。
当结果未知时,使用“Tidypredict”功能。谁能告诉我有什么区别?以下是现有的信息:https://cran.r-project.org/web/packages/tidypredict/tidypredict.pdf
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)
我无法重现你的问题 - 这是一个可重复的例子,说明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 package创建于2019-04-01(v0.2.1)