Exercise: How to interpret the tree model!
library(MASS) #this data is in MASS package
sample_index <- sample(nrow(Boston),nrow(Boston)*0.90)
boston_train <- Boston[sample_index,]
boston_test <- Boston[-sample_index,]
library(rpart)
library(rpart.plot)
boston_rpart <- rpart(formula = medv ~ ., data = boston_train)
prp(boston_rpart,digits = 4, extra = 1)
- Based on the tree model above, what is the predicted median housing price (in thousand) given following information:
0.13 |
25 |
5.13 |
0 |
0.45 |
6.76 |
43.4 |
7.98 |
8 |
284 |
19.7 |
395.58 |
9.5 |
25 |
- Calculate the mean squared error (MSE) of the in-sample for this tree model;
- Compare this modelโs out-of-sample performance with the linear regression model with all variables in it.
go to top