-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.R
More file actions
51 lines (36 loc) · 1.23 KB
/
Copy pathanalysis.R
File metadata and controls
51 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# ----------------------------------
# Campaign Analysis (R)
# ----------------------------------
library(dplyr)
library(ggplot2)
library(caret)
# Load data
campaign <- read.csv("Campaign Data.csv")
# ----------------------------------
# Basic EDA
# ----------------------------------
summary(campaign)
str(campaign)
# Missing values
sum(is.na(campaign))
# Boxplots
boxplot(campaign$age, campaign$duration, campaign$campaign, campaign$pdays,
main = "Boxplot",
names = c("Age", "Duration", "Campaign", "Pdays"))
# ----------------------------------
# Train-Test Split
# ----------------------------------
set.seed(1234)
trainIndex <- createDataPartition(campaign$response, p = 0.7, list = FALSE)
data_training <- campaign[trainIndex, ]
data_testing <- campaign[-trainIndex, ]
# ----------------------------------
# Logistic Regression Model
# ----------------------------------
model_campaign <- glm(response ~ ., data = data_training, family = binomial)
summary(model_campaign)
# Predictions
prob <- predict(model_campaign, data_testing, type = "response")
pred <- ifelse(prob > 0.5, 1, 0)
# Confusion Matrix
confusionMatrix(as.factor(pred), as.factor(data_testing$response))