Logistic Regression

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#loading the data

df <- read.csv("Insurance.csv")

#splitting the data


set.seed(2)
library(caTools)
split <- sample.split(df, SplitRatio = 0.8)
train <- subset(df, split==TRUE)
test <- subset(df,split==FALSE)

#checking for outliers


boxplot(train$Age)
boxplot(train$Vintage)
boxplot(train$Annual_Premium)

# run logistic regression


# use glm() (general linear model) with family = "binomial" to fit a logistic
# regression.
logit.reg <- glm(Response ~ ., data = train, family = "binomial")
options(scipen=999)
summary(logit.reg)

# use predict() with type = "response" to compute predicted probabilities.


logit.reg.pred <- predict(logit.reg, test, type = "response")
head(logit.reg.pred)

# first 10 actual and predicted records


data.frame(actual = test$Response[1:10], predicted = logit.reg.pred[1:10])
install.packages("gains")
library(gains)
gain <- gains(test$Response, logit.reg.pred, groups=length(logit.reg.pred))
head(gain)

You might also like