We are committed to bringing you 100% authentic exercise sets. We even try to include as different datasets as possible to give you an understanding of different problems. No more classifying Titanic dataset. R has tons of datasets in its library. This is to encourage you to try as many datasets as possible. We will be comparing two models by checking their accuracy, Area under the curve, ROC performance etc.
It will be helpful to go over Tom Fawcett’s research paper on ‘An introduction to ROC analysis’
Answers to the exercises are available here.
If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
Run the following code. If you do not have ROCR package installed, you can use install.packages() command to install it.
spl=sample.split(df1$Class,SplitRatio = 0.7)
model1=glm(Class~.,data=Train1,family = binomial)
Using the confusion matrix, please state what is the accuracy of this model?
Great. Now let’s see the ROC curve of the model. Use this code below and then use plot() command to plot ROCRperf2
The plot above gives us an idea of the performance of the model. Is this a a good or bad model? State reasons
use the summary function on the model to see the summary. Note that if there are more stars next to a feature, then it is highly corelated with our target variable.
Although we found out the accuracy of the model in Q2, it is still not the best measure. A better measure is area under the curve. AUC takes account of class distribution in the model and is in the range of 0 to 1. 1 being the best and 0 being the worse. It can also be taken as a probability score. If the AUC is 0.70 then that means there is a 0.7 chance of the model to predict positive.
Insert the code below to obtain AUC. What is the AUC score? Is it better than the accuracy obrained at Q2?
Now create another model called model2 and include 11 variables that have atleast a star next to their name.Hint: use the summary() command and intercept does not count.
Now predict the target variable using the Test1 sample using model2 and store it in pred2.
table() command to get the confusion matrix. Note the accuracy.
What is the auc of model2?
Is model2 better than model 1? If so, then why?
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below