set.seed(200)
simulated <- mlbench.friedman1(200, sd = 1)
simulated <- as.data.frame(cbind(simulated$x, simulated$y))
colnames(simulated)[ncol(simulated)] <- "y"
model1 <- randomForest(y ~ .,
data = simulated,
importance = TRUE,
ntree = 1000)
rfImp1 <- varImp(model1, scale = FALSE)
rfImp1
## Overall
## V1 8.86329776
## V2 6.72851763
## V3 0.84145353
## V4 7.60284159
## V5 2.26864193
## V6 0.11268425
## V7 0.07374772
## V8 -0.07210708
## V9 -0.06913906
## V10 -0.10577619
varImpPlot(model1, type = 1,
main = "Random Forest Variable Importance")
The variable importance results show that V1, V4, V2, V5 and V3 are the
five most important predictors with V1 having the highest importance.
This is consistent with the Friedman simulation, where only the first
five predictors contribute to the response. Predictors V6 through V10
have importance scores close to zero or slightly negative indicating
that they provide little to no predictive value. Therefore, the random
forest successfully identifies the relevant predictors and does not
substantially rely on the irrelevant predictors.
set.seed(200)
simulated2 <- simulated
simulated2$duplicate1 <- simulated2$V1 +
rnorm(nrow(simulated2)) * 0.1
cor(simulated2$V1, simulated2$duplicate1)
## [1] 0.9497025
model2 <- randomForest(y ~ .,
data = simulated2,
importance = TRUE,
ntree = 1000)
rfImp2 <- varImp(model2, scale = FALSE)
rfImp2
## Overall
## V1 5.82920546
## V2 6.19827153
## V3 0.64690600
## V4 7.18846269
## V5 2.18817746
## V6 0.14271410
## V7 0.08390675
## V8 -0.14854947
## V9 -0.09698485
## V10 -0.04244151
## duplicate1 4.08026296
varImpPlot(model2, type = 1,
main = "Importance with One Correlated Predictor")
simulated3 <- simulated2
simulated3$duplicate2 <- simulated3$V1 +
rnorm(nrow(simulated3)) * 0.1
cor(simulated3$V1, simulated3$duplicate2)
## [1] 0.9404384
model3 <- randomForest(y ~ .,
data = simulated3,
importance = TRUE,
ntree = 1000)
rfImp3 <- varImp(model3, scale = FALSE)
rfImp3
## Overall
## V1 4.78623531
## V2 6.40798205
## V3 0.51236907
## V4 7.22049056
## V5 2.10586770
## V6 0.08845493
## V7 -0.01112431
## V8 -0.10081293
## V9 0.05721653
## V10 -0.01556940
## duplicate1 3.00088429
## duplicate2 2.28840573
varImpPlot(model3, type = 1,
main = "Importance with Two Correlated Predictors")
data.frame(
Model = c("Original", "One Duplicate", "Two Duplicates"),
V1_Importance = c(
rfImp1["V1", "Overall"],
rfImp2["V1", "Overall"],
rfImp3["V1", "Overall"]
)
)
## Model V1_Importance
## 1 Original 8.863298
## 2 One Duplicate 5.829205
## 3 Two Duplicates 4.786235
The two additional predictors have correlations of 0.9497 and 0.9404 with V1, indicating strong positive relationships. After adding the first correlated predictor, the importance of V1 decreased from 8.8633 to 5.8292. Adding a second correlated predictor further reduced its importance to 4.7862. This occurs because the correlated predictors contain similar information and can substitute for one another when constructing trees. As a result, the predictive importance is distributed among these variables. This demonstrates that correlated predictors can reduce the individual variable importance of an otherwise important predictor without necessarily reducing the model’s predictive performance.
fit_gbm <- function(dataset) {
set.seed(200)
gbm::gbm(
y ~ .,
data = dataset,
distribution = "gaussian",
n.trees = 150,
interaction.depth = 3,
shrinkage = 0.1,
n.minobsinnode = 10,
bag.fraction = 0.5,
verbose = FALSE
)
}
gbm1 <- fit_gbm(simulated)
gbm2 <- fit_gbm(simulated2)
gbm3 <- fit_gbm(simulated3)
fit_cubist <- function(dataset) {
set.seed(200)
Cubist::cubist(
x = dataset[, names(dataset) != "y"],
y = dataset$y,
committees = 10
)
}
cubist1 <- fit_cubist(simulated)
cubist2 <- fit_cubist(simulated2)
cubist3 <- fit_cubist(simulated3)
gbm_importance <- function(model) {
imp <- summary(model, plotit = FALSE)
imp$rel.inf[imp$var == "V1"]
}
cubist_importance <- function(model) {
imp <- caret::varImp(model, scale = FALSE)
as.numeric(imp["V1", "Overall"])
}
comparison <- data.frame(
Model = c("Original", "One Duplicate", "Two Duplicates"),
GBM = c(
gbm_importance(gbm1),
gbm_importance(gbm2),
gbm_importance(gbm3)
),
Cubist = c(
cubist_importance(cubist1),
cubist_importance(cubist2),
cubist_importance(cubist3)
)
)
knitr::kable(comparison, digits = 4)
| Model | GBM | Cubist |
|---|---|---|
| Original | 22.9521 | 70.5 |
| One Duplicate | 15.7322 | 71.0 |
| Two Duplicates | 14.3084 | 65.5 |
summary(gbm1, las = 1, cBars = 10,
main = "GBM - Original")
## var rel.inf
## V4 V4 29.4489776
## V1 V1 22.9521280
## V2 V2 21.4755882
## V5 V5 12.4520659
## V3 V3 7.1692763
## V7 V7 2.1957113
## V6 V6 1.7679501
## V8 V8 1.0632379
## V9 V9 0.9666963
## V10 V10 0.5083682
summary(gbm2, las = 1, cBars = 11,
main = "GBM - One Duplicate")
## var rel.inf
## V4 V4 29.6822497
## V2 V2 21.2525282
## V1 V1 15.7322081
## V5 V5 12.4175597
## duplicate1 duplicate1 7.9288827
## V3 V3 7.1408088
## V7 V7 1.9409955
## V6 V6 1.3271499
## V8 V8 1.1577503
## V9 V9 0.8102842
## V10 V10 0.6095828
summary(gbm3, las = 1, cBars = 12,
main = "GBM - Two Duplicates")
## var rel.inf
## V4 V4 29.4139794
## V2 V2 21.0696855
## V1 V1 14.3083783
## V5 V5 11.3964309
## V3 V3 7.6284525
## duplicate2 duplicate2 5.3589150
## duplicate1 duplicate1 5.0995283
## V7 V7 2.3567289
## V6 V6 1.1061982
## V8 V8 0.9308627
## V9 V9 0.8414402
## V10 V10 0.4894002
caret::varImp(cubist1, scale = FALSE)
## Overall
## V1 70.5
## V3 41.0
## V2 54.5
## V4 50.0
## V5 47.5
## V6 0.0
## V7 0.0
## V8 0.0
## V9 0.0
## V10 0.0
caret::varImp(cubist2, scale = FALSE)
## Overall
## V1 71.0
## V3 41.5
## V2 54.5
## V4 50.0
## V5 43.5
## V6 0.0
## V7 0.0
## V8 0.0
## V9 0.0
## V10 0.0
## duplicate1 0.0
caret::varImp(cubist3, scale = FALSE)
## Overall
## V1 65.5
## V3 33.0
## V2 62.0
## duplicate2 15.0
## V4 48.5
## V5 39.0
## V6 0.0
## V7 0.0
## V8 0.0
## V9 0.0
## V10 0.0
## duplicate1 0.0
Stochastic gradient boosting showed a similar pattern to random forest. The importance of V1 decreased from 22.9521 to 15.7322 after adding one correlated predictor and further decreased to 14.3084 after adding two correlated predictors. The duplicate predictors also received positive importance scores showing that the predictive information was distributed among correlated variables.
Cubist behaved differently. The importance of V1 remained relatively stable, increasing slightly from 70.5 to 71.0 with one duplicate and decreasing to 65.5 with two duplicates. The first duplicate received zero importance in both models while the second duplicate received an importance score of 15.0. Cubist also assigned zero importance to all five irrelevant predictors.
Overall, random forest and stochastic gradient boosting were more sensitive to correlated predictors in this experiment, while Cubist was better able to retain the importance of the original predictor. These results demonstrate that the effect of multicollinearity on variable importance depends on the modeling technique used.
To examine tree selection bias, I simulated three predictors with different levels of granularity: a binary predictor, a discrete predictor with 10 possible values and a continuous predictor. The response variable is generated independently of all three predictors so none have a true predictive advantage.
set.seed(123)
n <- 200
n_sim <- 500
selected <- character(n_sim)
for (i in seq_len(n_sim)) {
sim_data <- data.frame(
Binary = sample(0:1, n, replace = TRUE),
Discrete = sample(1:10, n, replace = TRUE),
Continuous = runif(n),
y = rnorm(n)
)
tree <- rpart(
y ~ .,
data = sim_data,
method = "anova",
control = rpart.control(
cp = 0,
maxdepth = 1,
minsplit = 20,
xval = 0
)
)
selected[i] <- as.character(tree$frame$var[1])
}
selection_results <- as.data.frame(table(selected))
colnames(selection_results) <- c("Predictor", "Frequency")
selection_results$Percentage <-
100 * selection_results$Frequency / n_sim
knitr::kable(selection_results, digits = 2)
| Predictor | Frequency | Percentage |
|---|---|---|
| Binary | 24 | 4.8 |
| Continuous | 336 | 67.2 |
| Discrete | 140 | 28.0 |
ggplot(selection_results,
aes(x = Predictor, y = Percentage, fill = Predictor)) +
geom_col() +
geom_text(
aes(label = paste0(round(Percentage, 1), "%")),
vjust = -0.5
) +
labs(
title = "Regression Tree Selection Bias",
x = "Predictor Type",
y = "Selection Percentage"
) +
scale_y_continuous(limits = c(0, 105)) +
theme_minimal() +
theme(legend.position = "none")
The simulation results demonstrate that regression trees favor predictors with more possible split points. Across 500 simulations, the continuous predictor was selected 67.2% of the time followed by the discrete predictor at 28.0% and the binary predictor at only 4.8%. Since all three predictors were generated independently of the response, none had a true predictive advantage. However, predictors with more possible split points have more opportunities to produce a reduction in prediction error by chance. This explains why the continuous predictor was selected most frequently and demonstrates that traditional regression trees are biased toward predictors with more unique values.
The model on the right uses a higher bagging fraction and learning rate of 0.9. This means that each tree uses a larger portion of the training data and contributes a larger adjustment to the model. Consequently, the model quickly focuses on the strongest predictors concentrating importance among fewer variables. On the other hand, the model on the left uses a bagging fraction and learning rate of 0.1. Each tree is trained using a smaller random subset of the data and makes smaller adjustments. This introduces more randomness into the modeling process and allows a wider range of predictors to contribute to the model.
I would expect the model on the left to generalize better to new samples. Its smaller learning rate allows the model to learn gradually, while the smaller bagging fraction introduces randomness that can help reduce overfitting. The model on the right learns more aggressively and may be more sensitive to patterns specific to the training data. However, cross validation or independent test set performance would be necessary to determine which model actually performs better.
Increasing interaction depth allows each tree to make more complex splits and capture interactions between multiple predictors. This could distribute importance across additional predictors, potentially making the variable importance curve less steep. However, if the additional splits repeatedly involve the same dominant predictors, their importance could increase instead. Therefore, the exact effect depends on the relationships within the data. Increasing interaction depth also increases model complexity and may increase the risk of overfitting.
The ChemicalManufacturingProcess dataset is preprocessed using the same approach as in Exercises 6.3 and 7.5. Median imputation, centering, scaling, and an 80/20 training and testing split are used to maintain consistency with the previous analysis.
data(ChemicalManufacturingProcess)
set.seed(624)
chemIndex <- createDataPartition(
ChemicalManufacturingProcess$Yield,
p = 0.80,
list = FALSE
)
chemTrain <- ChemicalManufacturingProcess[chemIndex, ]
chemTest <- ChemicalManufacturingProcess[-chemIndex, ]
xTrain <- chemTrain[, names(chemTrain) != "Yield"]
yTrain <- chemTrain$Yield
xTest <- chemTest[, names(chemTest) != "Yield"]
yTest <- chemTest$Yield
dim(chemTrain)
## [1] 144 58
dim(chemTest)
## [1] 32 58
sum(is.na(xTrain))
## [1] 99
sum(is.na(xTest))
## [1] 7
set.seed(624)
chemCtrl <- trainControl(
method = "cv",
number = 10,
allowParallel = FALSE
)
chemPreprocess <- c("medianImpute", "center", "scale")
set.seed(624)
chemCart <- train(
x = xTrain,
y = yTrain,
method = "rpart",
preProcess = chemPreprocess,
trControl = chemCtrl,
tuneLength = 10,
metric = "RMSE"
)
chemCart
## CART
##
## 144 samples
## 57 predictor
##
## Pre-processing: median imputation (57), centered (57), scaled (57)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 130, 130, 130, 130, 129, 130, ...
## Resampling results across tuning parameters:
##
## cp RMSE Rsquared MAE
## 0.01306111 1.584106 0.3308808 1.228277
## 0.01959821 1.558733 0.3404526 1.208852
## 0.02760659 1.566751 0.3186495 1.230346
## 0.02932833 1.574970 0.3213941 1.257920
## 0.02947594 1.574970 0.3213941 1.257920
## 0.04153216 1.601364 0.3062117 1.289273
## 0.05495541 1.620953 0.2832735 1.285468
## 0.07808231 1.534658 0.3141309 1.232552
## 0.08886696 1.498851 0.3367805 1.210432
## 0.37141161 1.776608 0.1996622 1.429008
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was cp = 0.08886696.
set.seed(624)
chemRF <- train(
x = xTrain,
y = yTrain,
method = "rf",
preProcess = chemPreprocess,
trControl = chemCtrl,
tuneGrid = expand.grid(
mtry = c(2, 5, 10, 15, 20, 30, 57)
),
ntree = 500,
importance = TRUE,
metric = "RMSE"
)
chemRF
## Random Forest
##
## 144 samples
## 57 predictor
##
## Pre-processing: median imputation (57), centered (57), scaled (57)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 130, 130, 130, 130, 129, 130, ...
## Resampling results across tuning parameters:
##
## mtry RMSE Rsquared MAE
## 2 1.247329 0.6500804 1.0172429
## 5 1.166131 0.6844735 0.9484924
## 10 1.140110 0.6959871 0.9173673
## 15 1.134139 0.6859544 0.9105834
## 20 1.133403 0.6836571 0.9055369
## 30 1.146981 0.6650226 0.9155579
## 57 1.162697 0.6379825 0.9198839
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was mtry = 20.
set.seed(624)
chemGBM <- train(
x = xTrain,
y = yTrain,
method = "gbm",
preProcess = chemPreprocess,
trControl = chemCtrl,
tuneGrid = expand.grid(
n.trees = c(100, 200, 300),
interaction.depth = c(1, 3, 5),
shrinkage = c(0.01, 0.1),
n.minobsinnode = 10
),
bag.fraction = 0.5,
verbose = FALSE,
metric = "RMSE"
)
chemGBM
## Stochastic Gradient Boosting
##
## 144 samples
## 57 predictor
##
## Pre-processing: median imputation (57), centered (57), scaled (57)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 130, 130, 130, 130, 129, 130, ...
## Resampling results across tuning parameters:
##
## shrinkage interaction.depth n.trees RMSE Rsquared MAE
## 0.01 1 100 1.438943 0.5429302 1.1725003
## 0.01 1 200 1.291415 0.5911600 1.0434175
## 0.01 1 300 1.232401 0.6075431 0.9810417
## 0.01 3 100 1.342600 0.6020024 1.0884552
## 0.01 3 200 1.221633 0.6237785 0.9730079
## 0.01 3 300 1.175071 0.6413064 0.9274748
## 0.01 5 100 1.330011 0.6199302 1.0823659
## 0.01 5 200 1.192489 0.6436823 0.9545866
## 0.01 5 300 1.150188 0.6570875 0.9100203
## 0.10 1 100 1.202425 0.6034202 0.9438778
## 0.10 1 200 1.197771 0.6128518 0.9374087
## 0.10 1 300 1.202264 0.6115917 0.9421847
## 0.10 3 100 1.128696 0.6553252 0.8867757
## 0.10 3 200 1.098761 0.6687201 0.8807293
## 0.10 3 300 1.099011 0.6698090 0.8844976
## 0.10 5 100 1.172273 0.6238978 0.9318985
## 0.10 5 200 1.151481 0.6415326 0.9284186
## 0.10 5 300 1.151449 0.6442795 0.9313032
##
## Tuning parameter 'n.minobsinnode' was held constant at a value of 10
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were n.trees = 200, interaction.depth =
## 3, shrinkage = 0.1 and n.minobsinnode = 10.
set.seed(624)
chemCubist <- train(
x = xTrain,
y = yTrain,
method = "cubist",
preProcess = chemPreprocess,
trControl = chemCtrl,
tuneGrid = expand.grid(
committees = c(1, 10, 20, 50),
neighbors = c(0, 3, 5, 9)
),
metric = "RMSE"
)
chemCubist
## Cubist
##
## 144 samples
## 57 predictor
##
## Pre-processing: median imputation (57), centered (57), scaled (57)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 130, 130, 130, 130, 129, 130, ...
## Resampling results across tuning parameters:
##
## committees neighbors RMSE Rsquared MAE
## 1 0 1.2488261 0.5783182 1.0280703
## 1 3 1.0189994 0.7139189 0.7864399
## 1 5 1.0653957 0.6986405 0.8458404
## 1 9 1.1611371 0.6376550 0.9333935
## 10 0 1.1865374 0.6160431 0.9613163
## 10 3 1.0253199 0.7062002 0.8049226
## 10 5 1.0848603 0.6712710 0.8544244
## 10 9 1.1480364 0.6355057 0.9235183
## 20 0 1.1459429 0.6398869 0.9155220
## 20 3 0.9986320 0.7170248 0.7706770
## 20 5 1.0523657 0.6881659 0.8186269
## 20 9 1.1117508 0.6545276 0.8766236
## 50 0 1.1434164 0.6302182 0.9135694
## 50 3 0.9880079 0.7169630 0.7660098
## 50 5 1.0390369 0.6909248 0.8034349
## 50 9 1.1005943 0.6545815 0.8633493
##
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were committees = 50 and neighbors = 3.
chemModels <- list(
CART = chemCart,
RandomForest = chemRF,
GradientBoosting = chemGBM,
Cubist = chemCubist
)
cvResults <- resamples(chemModels)
summary(cvResults)
##
## Call:
## summary.resamples(object = cvResults)
##
## Models: CART, RandomForest, GradientBoosting, Cubist
## Number of resamples: 10
##
## MAE
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## CART 0.9415783 1.0738451 1.2239231 1.2104317 1.2970522 1.473450
## RandomForest 0.7112360 0.7984969 0.8878594 0.9055369 1.0107977 1.184303
## GradientBoosting 0.5878292 0.7378112 0.9086655 0.8807293 1.0181166 1.135159
## Cubist 0.6269707 0.6893519 0.7400234 0.7660098 0.8312687 1.005125
## NA's
## CART 0
## RandomForest 0
## GradientBoosting 0
## Cubist 0
##
## RMSE
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## CART 1.1802098 1.3344422 1.4668276 1.4988514 1.649388 1.993385 0
## RandomForest 0.8497653 0.9534589 1.1704467 1.1334028 1.281086 1.444665 0
## GradientBoosting 0.6818359 0.8663300 1.1661016 1.0987614 1.221804 1.449054 0
## Cubist 0.7711224 0.8405552 0.9436643 0.9880079 1.090152 1.358985 0
##
## Rsquared
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## CART 0.08860495 0.1854612 0.3550092 0.3367805 0.4584719 0.5806388
## RandomForest 0.57726917 0.6087421 0.6706570 0.6836571 0.7295212 0.8278718
## GradientBoosting 0.43480858 0.5922433 0.6634307 0.6687201 0.7648050 0.8246168
## Cubist 0.52826885 0.6377651 0.7136836 0.7169630 0.8024535 0.8841343
## NA's
## CART 0
## RandomForest 0
## GradientBoosting 0
## Cubist 0
testResults <- do.call(rbind, lapply(
names(chemModels),
function(modelName) {
predictions <- predict(
chemModels[[modelName]],
newdata = xTest
)
metrics <- postResample(
pred = predictions,
obs = yTest
)
data.frame(
Model = modelName,
RMSE = unname(metrics["RMSE"]),
Rsquared = unname(metrics["Rsquared"]),
MAE = unname(metrics["MAE"])
)
}
))
testResults <- testResults[order(testResults$RMSE), ]
knitr::kable(testResults, digits = 4,
caption = "Test Set Performance of Tree Based Models")
| Model | RMSE | Rsquared | MAE | |
|---|---|---|---|---|
| 4 | Cubist | 0.9549 | 0.8054 | 0.6977 |
| 3 | GradientBoosting | 1.2165 | 0.6851 | 0.9123 |
| 2 | RandomForest | 1.2403 | 0.7377 | 0.8990 |
| 1 | CART | 1.5632 | 0.5036 | 1.1913 |
ggplot(testResults, aes(
x = reorder(Model, RMSE),
y = RMSE,
fill = Model
)) +
geom_col() +
geom_text(aes(label = round(RMSE, 4)), vjust = -0.5) +
scale_y_continuous(expand = expansion(mult = c(0, 0.15))) +
labs(
title = "Test Set RMSE by Model",
x = "Model",
y = "RMSE"
) +
theme_minimal() +
theme(legend.position = "none")
comparison87 <- data.frame(
Exercise = c("6.3", "7.5", "7.5", "7.5",
"8.7", "8.7", "8.7", "8.7"),
Model = c("Ridge", "SVM Radial", "Random Forest",
"MARS", "CART", "Random Forest",
"Gradient Boosting", "Cubist"),
Test_RMSE = c(1.4868, 1.1586, 1.2505, 1.2827,
1.5632, 1.2403, 1.2165, 0.9549),
Test_Rsquared = c(0.5058, 0.7424, 0.7181, 0.6705,
0.5036, 0.7377, 0.6851, 0.8054)
)
comparison87 <- comparison87[order(comparison87$Test_RMSE), ]
knitr::kable(comparison87, digits = 4, row.names = FALSE)
| Exercise | Model | Test_RMSE | Test_Rsquared |
|---|---|---|---|
| 8.7 | Cubist | 0.9549 | 0.8054 |
| 7.5 | SVM Radial | 1.1586 | 0.7424 |
| 8.7 | Gradient Boosting | 1.2165 | 0.6851 |
| 8.7 | Random Forest | 1.2403 | 0.7377 |
| 7.5 | Random Forest | 1.2505 | 0.7181 |
| 7.5 | MARS | 1.2827 | 0.6705 |
| 6.3 | Ridge | 1.4868 | 0.5058 |
| 8.7 | CART | 1.5632 | 0.5036 |
Cubist achieved the best predictive performance among the four tree based models with a test RMSE of 0.9549, an R-squared of 0.8054 and an MAE of 0.6977. Stochastic gradient boosting and random forest also performed well with test RMSE values of 1.2165 and 1.2403 respectively. CART had the highest test RMSE of 1.5632. Cubist also achieved the lowest cross validation RMSE of 0.9935 demonstrating consistent performance across cross validation and independent test set evaluation. Compared to the best models from Exercises 6.3 and 7.5, Cubist reduced test RMSE by 35.8% relative to Ridge regression and 17.6% relative to radial SVM. These results suggest that Cubist more effectively captures complex relationships between manufacturing predictors and yield achieving the best predictive performance across all three exercises.
cubistImp <- varImp(chemCubist, scale = TRUE)
rfImp <- varImp(chemRF, scale = TRUE)
gbmImp <- varImp(chemGBM, scale = TRUE)
cartImp <- varImp(chemCart, scale = TRUE)
plot(cubistImp, top = 10, main = "Cubist Variable Importance")
plot(rfImp, top = 10, main = "Random Forest Variable Importance")
plot(gbmImp, top = 10, main = "Gradient Boosting Variable Importance")
plot(cartImp, top = 10, main = "CART Variable Importance")
cubistTop10 <- cubistImp$importance
cubistTop10 <- cubistTop10[
order(cubistTop10$Overall, decreasing = TRUE),
, drop = FALSE
]
head(cubistTop10, 10)
## Overall
## ManufacturingProcess32 100.00000
## ManufacturingProcess17 53.19149
## ManufacturingProcess09 51.06383
## BiologicalMaterial06 44.68085
## BiologicalMaterial03 42.55319
## BiologicalMaterial02 41.48936
## ManufacturingProcess33 34.04255
## ManufacturingProcess04 31.91489
## ManufacturingProcess13 30.85106
## BiologicalMaterial10 18.08511
ManufacturingProcess32 was the most important predictor across all four models, consistent with the results from Exercises 6.3 and 7.5. ManufacturingProcess09, ManufacturingProcess13 and BiologicalMaterial06 were also consistently important. Cubist ranked ManufacturingProcess17 highly, while Random Forest and Gradient Boosting placed greater importance on ManufacturingProcess31 and BiologicalMaterial12.
Cubist shared six of its top ten predictors with both Ridge regression and the previous Random Forest model. Its top ten included six manufacturing and four biological predictors, compared to eight manufacturing and two biological predictors in Ridge. These differences suggest that tree based models may capture nonlinear relationships and interactions that linear models do not capture as effectively. However, manufacturing process variables remain important predictors of yield.
rpart.plot(
chemCart$finalModel,
type = 2,
extra = 101,
fallen.leaves = TRUE,
main = "Regression Tree for Manufacturing Yield"
)
cartParty <- partykit::as.party(chemCart$finalModel)
plot(cartParty)
The regression tree splits on ManufacturingProcess32 at a standardized value of 0.173, resulting in two terminal nodes. The first node contains 83 observations with an average yield of approximately 39%, while the second contains 61 observations with an average yield of approximately 41%. The boxplots show that higher values of ManufacturingProcess32 are associated with higher yield although the distributions overlap. The simple tree structure may explain why CART performed worse than the more complex models.