glm.fit Warning Messages in R: algorithm didn’t converge & probabilities 0/1

# 仿真数据

set.seed(6523987)                            # Create example data
x <- rnorm(100)
y <- rep(1, 100)
y[x < 0] <- 0
data <- data.frame(x, y)
head(data)                                   # Head of example data

# 构建模型;

# 为什么在R编程语言中拟合回归模型时会出现glm.fit警告:“算法不收敛,拟合的概率为0或1”。让我们假设我们想用glm函数估计一个二项式模型。

glm(y ~ x, data, family = "binomial")        # Perfect predictions
# Warning messages:
# 1: glm.fit: algorithm did not converge
# 2: glm.fit: fitted probabilities numerically 0 or 1 occurred******************************************************************************Warning message:
"glm.fit: algorithm did not converge"
Warning message:
"glm.fit: fitted probabilities numerically 0 or 1 occurred"Call:  glm(formula = y ~ x, family = "binomial", data = data)Coefficients:
(Intercept)            x  -11.97       734.42  Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:      138
Residual Deviance: 1.938e-07    AIC: 4

这是因为变量x完美地预测了变量y。

当我们回到数据创建过程时,您可以看到这一点。已经指定当x小于0时,y总是0。因此,该模型完美地预测了哪些y值是0,哪些y值是1。

我们可以通过在数据中添加一些随机噪声来说明这个情况:

data_new <- data                             # Add randomness to data
data_new$x <- data_new$x + rnorm(100)

# 重新构建模型;

glm(y ~ x, data_new, family = "binomial")    # No warning message********************************************************************Call:  glm(formula = y ~ x, family = "binomial", data = data_new)Coefficients:
(Intercept)            x  0.09066      1.16241  Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:      138
Residual Deviance: 98.22    AIC: 102.2

这一次,我们在RStudio控制台中没有得到警告消息。

那么怎样才能解决这个问题呢?

这在很大程度上取决于所使用的特定数据集的结构。然而,建议你看一下数据中变量的成对相关性,看看这些相关性中是否有一些不自然的高。

经常发生的情况是,变量被意外地包含到一个模型中(信息泄露)。尝试识别这些变量,并在没有这些变量的情况下再次运行我们的模型,直到警告消息不再出现。

参考:logistic回归报错问题:Warning messages: 1: glm.fit:算法没有聚合 2: glm.fit:拟合機率算出来是数值零或一

参考: glm.fit Warning Messages in R: algorithm didn’t converge & probabilities 0/1

参考:R语言plot函数参数合集

参考:glm

参考:Why am I getting “algorithm did not converge” and “fitted prob numerically 0 or 1” warnings with glm?

glm.fit Warning Messages in R: algorithm didn’t converge probabilities 0/1相关推荐

  1. logistic回归报错问题:Warning messages: 1: glm.fit:算法没有聚合 2: glm.fit:拟合機率算出来是数值零或一

    logistic回归的时候报错问题包括下面两种 Warning: glm.fit: algorithm did not converge Warning: glm.fit: fitted probab ...

  2. R语言使用tryCatch函数调试R代码实战:tryCatch函数运行正常R代码、tryCatch函数运行有错误(error)的R代码示例/tryCatch函数运行有警告(warning)的R代码示例

    R语言使用tryCatch函数调试R代码实战:tryCatch函数运行正常R代码.tryCatch函数运行有错误(error)的R代码示例/tryCatch函数运行有警告(warning)的R代码示例 ...

  3. sybase:SQL Exception and Warning Messages大全

    内容全部来自sybase官方网站: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc39001.0 ...

  4. 译文: C28x Compiler Error and Warning Messages

    C28x Compiler Error and Warning Messages 引言 通常,知道错误和警告的产生以及常见错误的来源是很有帮助的.本文包含错误列表.警告和备注以及常见错误列表及其解决方 ...

  5. PHP模块加载失败:PHP Warning: Module ‘modulename‘ already loaded in Unknown on line 0

    报错问题: PHP Warning: Module 'ftp' already loaded in Unknown on line 0 PHP Warning: Module 'ftp' alread ...

  6. [WARNING] The POM for com.tenyears:base-common:jar:1.0 is invalid, transitive dependen

    很明显,引用的模块,缺少架包. 1 运行 mvn -X dependency:tree>tree.txt mvn -X install mvn -X package等等,只要加上-X就能打印详情 ...

  7. Tinker edge R 烧写 Debian 10 V2.0.5 镜像

    Tinker edge R 烧写 Debian 10 V2.0.5 镜像 遇到问题: 按照官方文件说明烧写最新系统镜像Tinker edge R Debian 10 V2.0.5失败. 解决办法: 进 ...

  8. 解决YOLOV5训练时P、R、mAP等值均为0的问题

    最近用YOLOV5训练自己的数据集,出现了训练失败的情况,比如box,obj,cls,labels等均为nan或0,找了很多办法,其实就是cuda与PyTorch版本的问题 Epoch gpu_mem ...

  9. YOLOV5训练数据集P、R、mAP等均为0的解决方案

    使用YOLOV5训练数据集时,P.R等值均为0 最近在用YOLOV5训练自己的数据集,执行了十几个epochs之后,epoch的主要参数,比如box,obj,cls,labels等均为nan或0,即没 ...

最新文章

  1. UNITY C#内存泄漏
  2. 工业用微型计算机(8)-指令系统(5)
  3. SAP Spartacus的SkipLink功能
  4. 前端学习(781):格式化日期年月日星期
  5. Linux下修改SSH登录端口
  6. jq父级绑定事件的意义_js、jq事件绑定方式总结——以click事件为例
  7. Linux下日志分析的几个常用命令
  8. CentOS 下解决ssh登录 locale 警告
  9. FLASH BUILDER 清除图片缓存
  10. java 数组随机抽取_Java利用数组随机抽取幸运观众
  11. 请自行检查是否安装VC9运行库??
  12. xlua 转webgl 遇到的一些错误
  13. 服务器虚拟化 lpar,HMC与VIOS对新LPAR提供存储与网络虚拟化的支持
  14. android 怎么改变字体颜色,安卓系统字体颜色修改教程
  15. 漂亮MM超级搞笑问答
  16. 办公室装修办公隔断的注意事项
  17. Servlet中的一些面试题 以及参考答案
  18. 网络工程实训eNSP学习记录
  19. IC设计错误案例001:位宽不匹配的错误
  20. postgreSQL中的时间、数字类型模糊查询

热门文章

  1. python中for循环缩进_Python减少循环层次和缩进的技巧分析
  2. win7关闭系统索引服务器,win7系统关闭磁盘索引功能的操作方法
  3. IROS2021|DLL直接点云定位:一种基于点云地图的航空机器人定位方法
  4. mysql length函数无法对字段值为null的筛选
  5. PostgreSQL10.5安装后(Win10)环境变量配置与运行
  6. 第二十七课.深度强化学习(二)
  7. 计算Python的代码块或程序的运行时间
  8. 施一公:优秀博士如何养成(全文) 清华大学演讲
  9. Android的ADT的安装(离线)
  10. 如何安装python3.7.4_银河麒麟安装Python3.7.4以及升级自带OpenSSL