-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdmissionPrediction.R
46 lines (35 loc) · 1.25 KB
/
AdmissionPrediction.R
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
######### COLLEGE ADMISSION PREDICTION USING LOGISTIC REGRESSION ###############
# Lets import the dataset
data <- read.csv("binary.csv")
data
View(data)
# Lets split the data
library(caTools)
split <- sample.split(data,SplitRatio = 0.8)
split
train <- subset(data,split == "TRUE")
test <- subset(data,split == "FALSE")
# Data Munging
# These are categorical variables so,we need to convert them into factors
data$admit <- as.factor(data$admit)
data$rank <- as.factor(data$rank)
# Model Training
# We will train the model using the training data
# Use glm, the general linear model function
# Dependent variable is admit;independent variables are gpa and rank
# The family argument should be binomial to indicate Logistic Regression
logreg <- glm(admit~gpa+rank,data = train,family = "binomial")
# Lets see the model summary
summary(logreg)
# Prediction
pred_log <- predict(logreg,test,type = "response")
pred_log
# Lets see with the train set as well
pred_train <- predict(logreg,train,type = "response")
pred_train
# Lets validate the model
## Confusion Matrix
confmatrix <- table(Actual_Value = test$admit, Predicted_Value = pred_log>0.5)
confmatrix
## Accuracy score
(confmatrix[[1,1]]+confmatrix[[2,2]])/sum(confmatrix)