<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/model-evaluation-exercises-1/"></div></div><div><a data-url="https://www.r-bloggers.com/model-evaluation-exercises-1/" data-counturl="https://www.r-bloggers.com/model-evaluation-exercises-1/" data-count="horizontal" data-text="Model Evaluation Exercises 1" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2016/12/02/model-evaluation-exercise-1/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="http://r-exercises.com/wp-content/uploads/2016/11/model-evaluation.jpg?x61433"><img sizes="(max-width: 210px) 100vw, 210px" alt="model-evaluation" class="wp-image-3052" src="https://i1.wp.com/r-exercises.com/wp-content/uploads/2016/11/model-evaluation-210x300.jpg?resize=210%2C300" data-recalc-dims="1"></a>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 grasp the basics of gauging accuracy of the model.</p>
<p>It will be helpful to go over Tom Fawcett’s <a target="_blank" rel="nofollow" href="http://people.inf.elte.hu/kiss/11dwhdm/roc.pdf">research paper</a> on ‘An introduction to ROC analysis’</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2016/12/02/model-evaluation-exercise-1-2/">here</a>.</p>
<p>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.</p>
<p><strong>Exercise 1</strong></p>
<p>In pattern recognition and classification, we use precision(fraction of retrieved instances that are relevant) and recall(fraction of relevant instances that are retrieved). In other words precision helps us understand whether there is overlap in the model and whether the model can distinguish between the items. Recall,also called sensitivity, helps us gauge how many positives we can identify out of all the positives.</p>
<p>Suppose we design a model to identify iphones from a video that also contain android phones. If the program identifies 5 iphones in a scene containing 7 iphones and some android phones. if 3 of the identification are correct but 2 are actually android phones.<br>
a. What is the precision of the model?<br>
b. What is the recall of the model?</p>
<p><strong>Exercise 2</strong></p>
<p>Suppose we created the model and want to assess how well it predicted. We will compare the actual value from the Test set to the predicted value that is derived from the model.</p>
<p> FALSE TRUE<br>
0 94 23<br>
1 24 100</p>
<p> Using the confusion matrix above, answer the following questions<br>
a. Number of true positives?<br>
b. Number of false negatives?<br>
c. Number of true negatives?<br>
d. Number of false positives?</p>
<p><strong>Exercise 3</strong><br>
Quick way to gauge the accuracy of the model, assuming that the model target class is balanced, is to use the formula (TN+TP)/N. What is the accuracy of the model?</p>
<p><strong>Exercise 4</strong><br>
Quick way to gauge the error rate is to use the formula (FP/FN)/N. What is the overall error rate?</p>
<p><strong>Exercise 5</strong><br>
Sensitivity is defined as TP/(TP+FN). Specificity is defined as TN/(TN+FP). Using that information, answer the following questions<br>
a.What is the sensitivity of the model?<br>
b.What is the specificity of the model?</p>
<p><strong>Exercise 6</strong></p>
<p>There are usually two type of errors, false positive and false negative. False negative error rate is defined as FN/(TP+FN). False positive error rate is defined as FP/(TN+FP). Now answer the following questions:<br>
a. What is the False negative error?<br>
b. What is the False positive error?</p>
<p><strong>Exercise 7</strong></p>
<p>Now suppose this is a model like<br>
that was used to identify iphones from androids in a video(Q1).<br>
a. What is the precision?<br>
b. What is the recall? Hint: Recall is the same as sensitivity.</p>
<p><strong>Exercise 8</strong><br>
Go ahead and run the code below. You may run line by line to see what is happening. In brief, we are loading the housing data, changing the Cont variable to binary class, splitting the data into Train and Test set, Building a model, predicting and comparing actual Cont value in the Test set with predicted value in pred.</p>
<p>attach(housing)<br>
housing$Cont=ifelse(housing$Cont==”High”,1,0)<br>
spl=sample.split(housing$Cont,SplitRatio = 0.7)<br>
Train=housing[spl==TRUE,]<br>
Test=housing[spl==FALSE,]<br>
model 0.5)</p>
<p><strong>Exercise 9</strong><br>
Using the confusion matrix output from your last code, answer the following questions.<br>
a) What is the Precision?<br>
b) What is the recall?</p>
<p><strong>Exercise 10</strong><br>
Using the confusion matrix, answer the follwing questions<br>
c) What is the accuracy of the model?<br>
d) What is the overall error rate?</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/model-evaluation-exercises-1/"></div></div><div><a data-url="https://www.r-bloggers.com/model-evaluation-exercises-1/" data-counturl="https://www.r-bloggers.com/model-evaluation-exercises-1/" data-count="vertical" data-text="Model Evaluation Exercises 1" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-exercises.com/2016/12/02/model-evaluation-exercise-1/"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/SvgNIdMkweg"></a></div>