# Multicollinearity in Logistic Regression

I have tried building a model on weather dataset (https://www.biz.uiowa.edu/faculty/jledolter/DataMining/dataexercises.html). As i build my models i get the below error which is due to the presence of highly correlated variables.

*Warning messages:
1: glm.fit: algorithm did not converge
2: glm.fit: fitted probabilities numerically 0 or 1 occurred*

R code is below

```
`mydata=read.csv("weather.csv")`
`variable=names(mydata)`
####Missing value Imputation using kNN
library(VIM)
```

# Which variables have missing values

`colnames(mydata)[colSums(is.na(mydata)) > 0]`

```
mydata_imputed=kNN(mydata,variable = colnames(mydata)[colSums(is.na(mydata)) > 0],k=5)
colSums(is.na(mydata_imputed))
mydata_imputed=mydata_imputed[,1:24]
str(mydata_imputed)
#Building model
library(caret)
set.seed(1234)
Index=createDataPartition(mydata_imputed$RainTomorrow,p=0.75,list = FALSE)
Train=mydata_imputed[Index,]
Test=mydata_imputed[-Index,]
unique(mydata_imputed)
LogM1=glm(RainTomorrow~., data = mydata_imputed[,-c(1,2)], family = "binomial")
library(car)
car::vif(LogM1)
LogM2=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,16:17,20:21)], family = "binomial")
names(mydata_imputed)
car::vif(LogM2)
LogM3=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,12,15:17,20:21)], family = "binomial")
car::vif(LogM3)
LogM4=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,12,15:17,20:22)], family = "binomial")
car::vif(LogM4)
LogM5=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,12,13,15:17,20:22)], family = "binomial")
car::vif(LogM5)
LogM6=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,6:7,12,13,15:17,20:22)], family = "binomial")
car::vif(LogM6)
LogM7=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,6:7,9,12,13,15:17,20:22)], family = "binomial")
car::vif(LogM7)
names(mydata_imputed)
LogM8=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,6:7,9,12,13,15:17,19:22)], family = "binomial")
car::vif(LogM8)
names(mydata_imputed)
LogM9=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,6:7,9,12,13,15:18,19:22)], family = "binomial")
car::vif(LogM9)
names(mydata_imputed)
LogM10=glm(RainTomorrow~., data = mydata_imputed[,-c(1:4,6:7,9,12:18,19:22)], family = "binomial")
car::vif(LogM10)
names(mydata_imputed)`
```