警告:glm.fit:算法未收敛

时间:2020-06-23 19:40:42

标签: r model regression

banking_data

library(MASS)
library(randomForest)

Bdata <- read.csv("banking_data.csv")
head(Bdata)
Bdata$y <- ifelse(Bdata$y == "y", 1, 0)
intercept_model<- glm(y~1,family = binomial("logit"),data=Bdata)
summary(intercept_model)
(exp(intercept_model$coefficients[1]))/(1+exp(intercept_model$coefficients[1]))

我尝试运行此代码,但显示警告:

glm.fit:算法未收敛

显示:

Call:
glm(formula = y ~ 1, family = binomial("logit"), data = Bdata)

Deviance Residuals: 
       Min          1Q      Median          3Q         Max  
-2.409e-06  -2.409e-06  -2.409e-06  -2.409e-06  -2.409e-06  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   -26.57    1754.75  -0.015    0.988

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 0.0000e+00  on 41187  degrees of freedom
Residual deviance: 2.3896e-07  on 41187  degrees of freedom
AIC: 2

Number of Fisher Scoring iterations: 25

1 个答案:

答案 0 :(得分:0)

如果没有有关数据的更多信息,将很难为您提供帮助。

有关一般建议,请参阅此existing post

这可能是因为您的y数据上没有两个类。确实,例如:

y <- c(rep(1, 1000))
df <- data.frame(y = y)
reg <- glm(y ~ 1, data = df, family = binomial("logit"))
reg

将返回相同的错误。您是否使用y函数检查了table(df$y)的余额?

另一种解决方案是增加迭代的最大值:

reg <- glm(y ~ 1, data = df, family = binomial("logit"), maxit = 100)
reg

但是,如果您的数据集中只有no,则此解决方案没有用。