-1

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]))

I tried to run this code but it shows Warning:

glm.fit: algorithm did not converge

It shows :

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
user20650
  • 24,654
  • 5
  • 56
  • 91
  • 2
    https://stats.stackexchange.com/questions/11109/how-to-deal-with-perfect-separation-in-logistic-regression gives a lot of advice – user20650 Jun 23 '20 at 20:42

1 Answers1

0

Without more information on your data it will be hard to help you.

For general advise, see this existing post.

It could be because of the absence of two classes on your y data. Indeed, for instance :

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

Will return the same error. Did you check the balance of y with the function table(df$y) ?

Another solution is to increase the maximum of iteration :

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

However this solution is not useful if you have only no inside your dataset.

Rémi Coulaud
  • 1,684
  • 1
  • 8
  • 19
  • I will put my data and other information now! – Houyuan Bai Jun 23 '20 at 19:45
  • > > Bdata$y <- ifelse(Bdata$y == "y", 1, 0) > > intercept_model<- glm(y~1,family = binomial("logit"),data=Bdata) > > > Warning: glm.fit: algorithm did not converge > > summary(intercept_model) > > 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 – Houyuan Bai Jun 23 '20 at 19:57
  • > 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 – Houyuan Bai Jun 23 '20 at 19:57
  • I put picture of my data in the post, please help me. – Houyuan Bai Jun 23 '20 at 20:01
  • Could you see it know ? – Houyuan Bai Jun 23 '20 at 20:08
  • age marital education occupation default housing contact quarter day duration campaign pdays previous poutcome y 1 56 married 0 0 no no telephone 0 1 261 1 999 0 nonexistent no – Houyuan Bai Jun 23 '20 at 20:09
  • I advise you to read this https://stackoverflow.com/help/minimal-reproducible-example. The idea is to a sample of your data.. – Rémi Coulaud Jun 23 '20 at 20:10
  • What does 100 lines of y will be enough? I didn`t get it . – Houyuan Bai Jun 23 '20 at 20:13
  • sorry it doesn`t help me......... – Houyuan Bai Jun 23 '20 at 20:20
  • Could you show the result of the table function ? – Rémi Coulaud Jun 23 '20 at 20:20
  • It still shows Warning: glm.fit: algorithm did not converge, and still goes for 25 iterations. – Houyuan Bai Jun 23 '20 at 20:29
  • If i try to use maxit = 100, it will show Warning message: glm.fit: The fitting probability is calculated as a value of zero or one – Houyuan Bai Jun 23 '20 at 20:31
  • Could just validate my help and try to use the link in advice and what I tell you to go through this problem ? – Rémi Coulaud Jun 23 '20 at 20:45