'Error in prune.tree(tree = dt, best = pruned_tree_size, method = "misclass") : misclass only for classification trees
'data.frame': 33510 obs. of 10 variables:
$ model : Factor w/ 92 levels " 1 Series"," 2 Series",..: 3 54 25 72 19 16 37 41 29 29 ...
$ year : int 2009 2019 2014 2016 2016 2017 2019 2017 2019 2015 ...
$ price : int 4675 40950 11472 17998 14399 9980 37990 14000 12299 8484 ...
$ transmission: Factor w/ 3 levels "Automatic","Manual",..: 2 3 3 2 2 2 1 2 2 2 ...
$ mileage : int 70000 19322 83417 30010 45693 70860 1499 20122 4132 25000 ...
$ fuelType : Factor w/ 4 levels "Diesel","Electric",..: 4 4 1 1 1 4 1 1 4 4 ...
$ tax : int 165 150 145 235 20 30 145 30 145 0 ...
$ mpg : num 47.9 34 54.3 44.1 65.7 55.4 40.9 64.2 48.7 65.7 ...
$ engineSize : num 2 3 2.1 2 2.1 1 2 1.5 1.1 1 ...
$ automaker : Factor w/ 4 levels "BMW","Ford","Mercedes",..: 1 1 3 2 3 2 3 2 2 2 ...
mycars_formula = price ~ year + transmission + mileage + fuelType + tax + mpg + engineSize + automaker
dt_mycars <- tree(mycars_formula, data = training_mycars)
cv_mycars <- cv.tree(dt_mycars, FUN=prune.misclass)
pruned_tree_size <- rev(cv_mycars$size)[which.min(rev(cv_mycars$dev))]
p_dt_mycars <- prune.misclass(dt_mycars, best = pruned_tree_size)
Error in prune.tree(tree = dt, best = pruned_tree_size, method = "misclass") :
misclass only for classification trees
Can someone explain to me why I cannot use misclass method? I know that my factor model has too many levels so I exclude it from my formula. if you have a suggetion also about how i can include it as well it would be very helpful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
