<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/intermediate-tree-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2017/01/05/intermediate-tree-2/"> 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/12/bonsai-316573__340.jpg?x61433"><img sizes="(max-width: 150px) 100vw, 150px" alt="" class="wp-image-3558" src="https://i0.wp.com/r-exercises.com/wp-content/uploads/2016/12/bonsai-316573__340-150x150.jpg?resize=150%2C150" data-recalc-dims="1"></a><br>
This is a continuation of the intermediate decision tree <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/01/intermediate-tree-1/">exercise</a>.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/05/intermediate-tree-2-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>
<div>
<aside><img src="http://r-exercises.com/2017/01/05/intermediate-tree-2/"></aside>
<div><strong>Learn more</strong> about decisions tree’s in the online courses <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/regression-machine-learning-with-r/">Regression Machine Learning with R</a> and <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/machine-learning-a-z-hands-on-python-r-in-data-science/">Machine Learning A-Z™: Hands-On Python &amp; R In Data Science</a></div>
</div>
<p><strong>Exercise 1</strong><br>
use the <code>predict()</code> command to make predictions on the Train data. Set the method to “class”. Class returns classifications instead of probability scores. Store this prediction in pred_dec.</p>
<p><strong>Exercise 2</strong><br>
Print out the confusion matrix</p>
<p><strong>Exercise 3</strong><br>
What is the accuracy of the model. Use the confusion matrix.</p>
<p><strong>Exercise 4</strong><br>
What is the misclassification error rate? Refer to Basic_decision_tree exercise to get the formula.</p>
<p><strong>Exercise 5</strong><br>
Lets say we want to find the baseline model to compare our prediction improvement. We create a base model using this code</p>
<p><code><br>
length(Test$class)<br>
base=rep(1,3183)<br>
</code></p>
<p>Use the table() command to create a confusion matrix between the base and Test$class</p>
<p><strong>Exercise 6</strong><br>
What is the number difference between the confusion matrix accuracy of dec and base?</p>
<p><strong>Exercise 7</strong></p>
<p>Remember the predict() command in question 1. We will use the same mode and same command except we will set the method to “regression”. This gives us a probability estimates. Store this in pred_dec_reg</p>
<p><strong>Exercise 8</strong><br>
load the ROCR package.</p>
<p>Use the prediction(), performance() and plot() command to print the ROC curve. Use pred_dec_reg variable from Q7. You can also refer to the previous exercise to see the code.</p>
<p><strong>Exercise 9</strong><br>
plot() the same ROC curve but set colorize=TRUE</p>
<p><strong>Exercise 10</strong><br>
Comment on your findings using ROC curve and accuracy. Is it a good model? Did you notice that ROC prediction() command only takes probability predictions as one of its arguments. Why is that so?</p>
<p>
<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/2017/01/05/intermediate-tree-2/"> 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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/A13lLvOji_s"></a></div>