<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/recursive-partitioning-and-regression-trees-exercises/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2016/12/13/recursive-partitioning-and-regression-trees-exercises/"> 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/tree-538274_960_720.jpg?x61433"><img sizes="(max-width: 150px) 100vw, 150px" alt="tree-538274_960_720" class="wp-image-3232" src="https://i1.wp.com/r-exercises.com/wp-content/uploads/2016/12/tree-538274_960_720-150x150.jpg?resize=150%2C150" data-recalc-dims="1"></a></p>
<p>[For this exercise, we will work using the package rpart. This is a beginner level exercise. Please refer to the help of rpart package]</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2016/12/13/recursive-partitioning-and-regression-trees-solutions/">here</a>.</p>
<p><strong>Exercise 1</strong></p>
<p>Consider the Kyphosis data frame(type help(‘kyphosis’) for more details), that contains:<br>
-Kyphosis:a factor with levels absent present indicating if a kyphosis (a type of deformation) was present after the operation.<br>
-Age:in months.<br>
-Number:the number of vertebrae involved.<br>
-Start:the number of the first (topmost) vertebra operated on.</p>
<p>1) Build a tree to classify Kyphosis from Age, Number and Start. </p>
<p><strong>Exercise 2</strong></p>
<p>Consider the tree build in exercise 1.<br>
1) Which variables are used to explain kyhosis presence?<br>
2) How many observations contains the terminal nodes. </p>
<p><strong>Exercise 3</strong></p>
<p>Consider the Kyphosis data frame.<br>
1)Build a tree using the first 60 observations of kyphosis.<br>
2)Predict the kyphosis presence for the other 21 observations.<br>
3)Which is the misclassification rate (prediction error)</p>
<p><strong>Exercise 4</strong></p>
<p>Consider the iris data frame(type help(‘iris’) for more details).<br>
1)Build a tree to classify Species from the other variables.<br>
2)Plot the trees, add nodes information.</p>
<p><strong>Exercise 5</strong></p>
<p>Consider the tree build in exercise 4.<br>
Prune the the using median complexity parameter (cp) associated to the tree.<br>
Plot in the same window, the pruned and the original tree.</p>
<p><strong>Exercise 6</strong></p>
<p>Consider the tree build in exercise 4.<br>
1)In which terminal nodes is clasified each oobservations of iris?<br>
2)Which Specie has a flower of Petal.Length greater than 2.45 and Petal.Width less than 1.75.</p>
<p><strong>Exercise 7</strong></p>
<p>Consider the car90 data frame(type help(‘car90’) for more details).<br>
1)Build a tree to predict Price from the other variables.<br>
2)Plot the trees, add nodes information.</p>
<p><strong>Exercise 8</strong></p>
<p>Consider the tree build in exercise 7.<br>
1) Which variables are used to explain the price?<br>
2)Which terminal nodes have a value of mean Price, less tan <code>mean(car90$Price)</code>?</p>
<p><strong>Exercise 9</strong></p>
<p>Consider the car.test.frame data frame (type help(‘car.test.frame’) for more details).<br>
1)Build a tree to explain Mileage using the other variables.<br>
2)Snip the tree in nodes number 2.<br>
3)Plot both tree together</p>
<p><strong>Exercise 10</strong><br>
Consider the tree build in exercise 9.<br>
Which is the depth of the tree (with the root node counted as depth 0).<br>
Set the maximum depth of the final tree on 2 </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/2016/12/13/recursive-partitioning-and-regression-trees-exercises/"> 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/IZ_w6HjlKQs"></a></div>