R Trees Flashcards

1
Q

Create Categorical Variable From Contious Var

A

High = ifelse(Sales)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Add Column to data frame

A

Carseats = data.frame(Carseats, High) #Add column to data frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fitting tree model

A

If doing it to categorical variable
tree.carseats = tree(High~.-Sales, Carseats) # Want to fit the model to all variables besides Sales, which we converted to categorical earlier
summary(tree.carseats)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Pruning Decision Trees

A

cv. carseats=cv.tree(tree.carseats, FUN = prune.misclass)
cv. carseats

pick the tree size that has the lowest dev

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

library for decision trees

A

library(tree)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

library for regression trees

A

library(tree) is the same thing as a decision tree except the outcome is a continous variable instead of 0/1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

library for random forest

A

library(randomForest)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how to get variable importance in random forest

A

importance(modeloutput)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

library and function for random forest with boosting

A

library(gbm)

boosted.forest = gbm(y~., data = DF, distribution…etc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what are the tuning parametrs for a boosted regression or decision tree?

A
#Parameters to Boosting Model - Really 3 Tuning Parameters
# 1) The Number of Trees (n.trees), we can overfit if this is too large, want to choose this with CV
# 2) Distribution = 'gaussian' if regression model, 'bernoulli' if classification model
# 3) shrinkage parameter = you can usually leave this at default, but can tweak this using CV, default is .001
# 4) Interaction Depth (d), d = 1 usually works well, but idea is to keep this small can also select this using CV
How well did you know this?
1
Not at all
2
3
4
5
Perfectly