@@ -48,6 +48,7 @@ summary(lm3)$adj.r.squared # -0.05481489
4848#
4949# ####################
5050# Box-cox transformation: used to increase normality of a dataset
51+ install.packages(" MASS" )
5152library(MASS )
5253
5354# The best lambda
@@ -89,15 +90,30 @@ fert$output <- as.integer(fert$output)
8990fert.glm <- glm(output ~ . , family = binomial(link = " logit" ), data = fert )
9091summary(fert.glm )
9192
93+ # Functions and packages for predicting using logistic regression
94+ score.table = function (p , r , threshold )
95+ {
96+ Pred <- p > threshold
97+ Actual <- r
98+ cat(" Actual vs. Predicted" , fill = T )
99+ table(Actual ,Pred )
100+ }
101+
102+ install.packages(" pROC" )
103+ library(pROC )
92104
93105# Prediction using logistic regression model
94- fert.pred <- predict(fert.glm , type = " response" )
106+ fert.pred <- predict(fert.glm , type = ' response' )
95107# Score table: gives the values of false positive, false negative, true positive and true negative
96108# Based on a specific cut off probability: 0.3 means that R should classify all probabilities of less than 0.3 as false and greater than 0.3 as true
97109score.table(fert.pred ,fert $ output ,0.3 )
98110# ROC plot: Ratio of true positives to false positives
99111# Upper right-hand corner is an ideal curve
100- plot.roc(fert.pred , fert $ output , main = " ROC Curve - Fertility" , col = " blue" )
112+ # Option 1:
113+ MyROC <- roc(fert $ output , fert.pred )
114+ plot(MyROC , main = " ROC Plot - Fertitility" )
115+ # Option 2:
116+ plot.roc(fert $ output , fert.pred , main = " ROC Plot - Fertitility" , col = " blue" )
101117
102118# #####################
103119#
@@ -109,7 +125,7 @@ plot.roc(fert.pred, fert$output, main = "ROC Curve - Fertility", col = "blue")
109125# 1. Split the data into a training set (70%) and testing set (30%)
110126
111127# Use the training set to build your models
112- # 2. Create a general linear regression model with output as the response and all the other attributes as a predictor
128+ # 2. Create a linear regression model with output as the response and all the other attributes as a predictor
113129
114130# 3. Determine correlation between attributes
115131
0 commit comments