Warning message:“glm.fit: fitted probabilities numerically 0 or 1 occurred“
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Warning message:“glm.fit: fitted probabilities numerically 0 or 1 occurred“相关的知识,希望对你有一定的参考价值。
Warning message:"glm.fit: fitted probabilities numerically 0 or 1 occurred"
目录
Warning message:"glm.fit: fitted probabilities numerically 0 or 1 occurred"
问题:
logistic回归模型成功地拟合了数据,但我们收到了一个警告消息,该消息拟合了发生的概率为0或1。
如果我们用拟合的logistic回归模型对原始dataframe中的观测值的响应值进行预测,我们可以看到几乎所有的预测概率都与0和1没有区别。
#create data frame
df <- data.frame(y = c(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1),
x1 = c(3, 3, 4, 4, 3, 2, 5, 8, 9, 9, 9, 8, 9, 9, 9),
x2 = c(8, 7, 7, 6, 5, 6, 5, 2, 2, 3, 4, 3, 7, 4, 4))
#fit logistic regression model
model <- glm(y ~ x1 + x2, data=df, family=binomial)
#view model summary
summary(model)
#use fitted model to predict response values
df$y_pred = predict(model, df, type="response")
#view updated data frame
df
解决:
logistic回归模型成功地拟合了数据,但我们收到了一个警告消息,该消息拟合了发生的概率为0或1
第一,忽视它;
第二,增加训练数据;
第三,剔除异常值;
完成错误:
Warning message: "glm.fit: fitted probabilities numerically 0 or 1 occurred"
参考:How to Handle: glm.fit: fitted probabilities numerically 0 or 1 occurred
参考:R
以上是关于Warning message:“glm.fit: fitted probabilities numerically 0 or 1 occurred“的主要内容,如果未能解决你的问题,请参考以下文章
R语言message函数warning()函数和stop()函数输出程序运行健康状态信息实战
unused function warning message
Which Clang Warning Is Generating This Message?
CMake Warning at cmake/OpenCVDownload.cmake:202 (message): IPPICV: Download failed: 28;“Timeout