HW_8

Joyce Aldrich

2025-11-15

HW_8 Instructions : Do problems 7.2 and 7.5 in Kuhn and Johnson. There are only two but they have many parts. Please submit both a link to your Rpubs and the .rmd file.

7.2

7.2. Friedman (1991) introduced several benchmark data sets create by simulation. One of these simulations used the following nonlinear equation to create data: y = 10 sin(πx1x2) + 20(x3 − 0.5)2 + 10x4 + 5x5 + N(0, σ2) where the x values are random variables uniformly distributed between [0, 1] (there are also 5 other non-informative variables also created in the simulation). The package mlbench contains a function called mlbench.friedman1 that simulates these data:

library(mlbench)
#install.packages("caret")
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
set.seed(200)
trainingData <- mlbench.friedman1(200, sd = 1)
## We convert the 'x' data from a matrix to a data frame
## One reason is that this will give the columns names.
trainingData$x <- data.frame(trainingData$x)
## Look at the data using
featurePlot(trainingData$x, trainingData$y)

## or other methods.

## This creates a list with a vector 'y' and a matrix
## of predictors 'x'. Also simulate a large test set to
## estimate the true error rate with good precision:
testData <- mlbench.friedman1(5000, sd = 1)
testData$x <- data.frame(testData$x)

Tune several models on these data. For example:

Model_1 : K-Nearest Neighbors (KNN)

library(caret)

knnModel <- train(x = trainingData$x,
y = trainingData$y,
method = "knn",
preProc = c("center", "scale"),
tuneLength = 10)

knnModel
## k-Nearest Neighbors 
## 
## 200 samples
##  10 predictor
## 
## Pre-processing: centered (10), scaled (10) 
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 200, 200, 200, 200, 200, 200, ... 
## Resampling results across tuning parameters:
## 
##   k   RMSE      Rsquared   MAE     
##    5  3.466085  0.5121775  2.816838
##    7  3.349428  0.5452823  2.727410
##    9  3.264276  0.5785990  2.660026
##   11  3.214216  0.6024244  2.603767
##   13  3.196510  0.6176570  2.591935
##   15  3.184173  0.6305506  2.577482
##   17  3.183130  0.6425367  2.567787
##   19  3.198752  0.6483184  2.592683
##   21  3.188993  0.6611428  2.588787
##   23  3.200458  0.6638353  2.604529
## 
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was k = 17.
knnPred <- predict(knnModel, newdata = testData$x)
## The function 'postResample' can be used to get the test set
## perforamnce values
postResample(pred = knnPred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 3.2040595 0.6819919 2.5683461

Model_2:Multivariate Adaptive Regression Splines (MARS)

# Define the candidate models to test
marsGrid <- expand.grid(.degree = 1:2, .nprune = 2:38)
# Fix the seed so that the results can be reproduced
set.seed(100)
marsTuned <- train(
  x=trainingData$x,
  y=trainingData$y,
method = "earth",
# Explicitly declare the candidate models to test
preProcess = c("center","scale"),
tuneGrid = marsGrid,
trControl = trainControl(method = "cv")
)
## Loading required package: earth
## Loading required package: Formula
## Loading required package: plotmo
## Loading required package: plotrix
marsTuned
## Multivariate Adaptive Regression Spline 
## 
## 200 samples
##  10 predictor
## 
## Pre-processing: centered (10), scaled (10) 
## Resampling: Cross-Validated (10 fold) 
## Summary of sample sizes: 180, 180, 180, 180, 180, 180, ... 
## Resampling results across tuning parameters:
## 
##   degree  nprune  RMSE      Rsquared   MAE      
##   1        2      4.327937  0.2544880  3.6004742
##   1        3      3.572450  0.4912720  2.8958113
##   1        4      2.596841  0.7183600  2.1063410
##   1        5      2.370161  0.7659777  1.9186686
##   1        6      2.276141  0.7881481  1.8100006
##   1        7      1.766728  0.8751831  1.3902146
##   1        8      1.780946  0.8723243  1.4013449
##   1        9      1.665091  0.8819775  1.3255147
##   1       10      1.663804  0.8821283  1.3276573
##   1       11      1.657738  0.8822967  1.3317299
##   1       12      1.653784  0.8827903  1.3315041
##   1       13      1.648496  0.8823663  1.3164065
##   1       14      1.639073  0.8841742  1.3128329
##   1       15      1.639073  0.8841742  1.3128329
##   1       16      1.639073  0.8841742  1.3128329
##   1       17      1.639073  0.8841742  1.3128329
##   1       18      1.639073  0.8841742  1.3128329
##   1       19      1.639073  0.8841742  1.3128329
##   1       20      1.639073  0.8841742  1.3128329
##   1       21      1.639073  0.8841742  1.3128329
##   1       22      1.639073  0.8841742  1.3128329
##   1       23      1.639073  0.8841742  1.3128329
##   1       24      1.639073  0.8841742  1.3128329
##   1       25      1.639073  0.8841742  1.3128329
##   1       26      1.639073  0.8841742  1.3128329
##   1       27      1.639073  0.8841742  1.3128329
##   1       28      1.639073  0.8841742  1.3128329
##   1       29      1.639073  0.8841742  1.3128329
##   1       30      1.639073  0.8841742  1.3128329
##   1       31      1.639073  0.8841742  1.3128329
##   1       32      1.639073  0.8841742  1.3128329
##   1       33      1.639073  0.8841742  1.3128329
##   1       34      1.639073  0.8841742  1.3128329
##   1       35      1.639073  0.8841742  1.3128329
##   1       36      1.639073  0.8841742  1.3128329
##   1       37      1.639073  0.8841742  1.3128329
##   1       38      1.639073  0.8841742  1.3128329
##   2        2      4.327937  0.2544880  3.6004742
##   2        3      3.572450  0.4912720  2.8958113
##   2        4      2.661826  0.7070510  2.1734709
##   2        5      2.404015  0.7578971  1.9753867
##   2        6      2.243927  0.7914805  1.7830717
##   2        7      1.856336  0.8605482  1.4356822
##   2        8      1.754607  0.8763186  1.3968406
##   2        9      1.653859  0.8870129  1.2813884
##   2       10      1.434159  0.9166537  1.1339203
##   2       11      1.320482  0.9289120  1.0347278
##   2       12      1.317547  0.9306879  1.0359899
##   2       13      1.296910  0.9306902  1.0146112
##   2       14      1.221407  0.9395223  0.9631486
##   2       15      1.230516  0.9390469  0.9761484
##   2       16      1.236911  0.9387407  0.9745362
##   2       17      1.236911  0.9387407  0.9745362
##   2       18      1.236911  0.9387407  0.9745362
##   2       19      1.236911  0.9387407  0.9745362
##   2       20      1.236911  0.9387407  0.9745362
##   2       21      1.236911  0.9387407  0.9745362
##   2       22      1.236911  0.9387407  0.9745362
##   2       23      1.236911  0.9387407  0.9745362
##   2       24      1.236911  0.9387407  0.9745362
##   2       25      1.236911  0.9387407  0.9745362
##   2       26      1.236911  0.9387407  0.9745362
##   2       27      1.236911  0.9387407  0.9745362
##   2       28      1.236911  0.9387407  0.9745362
##   2       29      1.236911  0.9387407  0.9745362
##   2       30      1.236911  0.9387407  0.9745362
##   2       31      1.236911  0.9387407  0.9745362
##   2       32      1.236911  0.9387407  0.9745362
##   2       33      1.236911  0.9387407  0.9745362
##   2       34      1.236911  0.9387407  0.9745362
##   2       35      1.236911  0.9387407  0.9745362
##   2       36      1.236911  0.9387407  0.9745362
##   2       37      1.236911  0.9387407  0.9745362
##   2       38      1.236911  0.9387407  0.9745362
## 
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were nprune = 14 and degree = 2.
mars_Pred <- predict(marsTuned, newdata = testData$x)
## The function 'postResample' can be used to get the test set
## perforamnce values
postResample(pred = mars_Pred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 1.2779993 0.9338365 1.0147070

Model_3: Support Vector Machines (SVMs)

svm_Tuned <- train(
x=trainingData$x,
y=trainingData$y,
method = "svmRadial",
preProc = c("center", "scale"),
tuneLength = 14,
trControl = trainControl(method = "cv"))

svm_Tuned
## Support Vector Machines with Radial Basis Function Kernel 
## 
## 200 samples
##  10 predictor
## 
## Pre-processing: centered (10), scaled (10) 
## Resampling: Cross-Validated (10 fold) 
## Summary of sample sizes: 180, 180, 180, 180, 180, 180, ... 
## Resampling results across tuning parameters:
## 
##   C        RMSE      Rsquared   MAE     
##      0.25  2.490737  0.8009120  1.982118
##      0.50  2.246868  0.8153042  1.774454
##      1.00  2.051872  0.8400992  1.614368
##      2.00  1.949707  0.8534618  1.524201
##      4.00  1.886125  0.8610205  1.465373
##      8.00  1.849220  0.8654721  1.436630
##     16.00  1.834598  0.8673606  1.429762
##     32.00  1.833194  0.8675744  1.428634
##     64.00  1.833194  0.8675744  1.428634
##    128.00  1.833194  0.8675744  1.428634
##    256.00  1.833194  0.8675744  1.428634
##    512.00  1.833194  0.8675744  1.428634
##   1024.00  1.833194  0.8675744  1.428634
##   2048.00  1.833194  0.8675744  1.428634
## 
## Tuning parameter 'sigma' was held constant at a value of 0.06315483
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were sigma = 0.06315483 and C = 32.
svm_Pred <- predict(svm_Tuned, newdata = testData$x)
## The function 'postResample' can be used to get the test set
## perforamnce values
postResample(pred = svm_Pred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 2.0742046 0.8255756 1.5755441

Model_4:Neural Networks

nnetGrid <- expand.grid(
.decay = c(0, 0.01, .1),
.size = c(1:5),
.bag = FALSE)

set.seed(100)

nnetTune <- train(
x=trainingData$x,
y=trainingData$y,
method = "avNNet",
tuneGrid = nnetGrid,
trControl = trainControl(method = "cv"),
## Automatically standardize data prior to modeling
## and prediction
preProc = c("center", "scale"),
linout = TRUE,
trace = FALSE,
MaxNWts = 10 * (ncol(trainingData$x) + 1) + 5 + 1,
maxit = 500)
## Warning: executing %dopar% sequentially: no parallel backend registered
nnetTune
## Model Averaged Neural Network 
## 
## 200 samples
##  10 predictor
## 
## Pre-processing: centered (10), scaled (10) 
## Resampling: Cross-Validated (10 fold) 
## Summary of sample sizes: 180, 180, 180, 180, 180, 180, ... 
## Resampling results across tuning parameters:
## 
##   decay  size  RMSE      Rsquared   MAE     
##   0.00   1     2.435518  0.7513899  1.911881
##   0.00   2     2.433752  0.7550000  1.948642
##   0.00   3     1.996019  0.8333893  1.573741
##   0.00   4     1.988455  0.8360927  1.578655
##   0.00   5     2.132599  0.8114048  1.596225
##   0.01   1     2.385476  0.7602930  1.887838
##   0.01   2     2.438328  0.7544889  1.958866
##   0.01   3     2.048732  0.8232175  1.609293
##   0.01   4     2.051816  0.8227737  1.621138
##   0.01   5     2.098039  0.8261950  1.657384
##   0.10   1     2.393935  0.7596458  1.894179
##   0.10   2     2.493789  0.7401308  1.997616
##   0.10   3     2.173754  0.7968266  1.737418
##   0.10   4     2.034070  0.8227987  1.590931
##   0.10   5     2.060132  0.8240785  1.625409
## 
## Tuning parameter 'bag' was held constant at a value of FALSE
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were size = 4, decay = 0 and bag = FALSE.
nnet_Pred <- predict(nnetTune, newdata = testData$x)
## The function 'postResample' can be used to get the test set
## perforamnce values
postResample(pred = nnet_Pred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 2.3462095 0.7880683 1.7537538

Question: Which models appear to give the best performance? Does MARS select the informative predictors (those named X1–X5)?

  1. Performance Comparison of Models:
postResample(pred = knnPred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 3.2040595 0.6819919 2.5683461
postResample(pred = mars_Pred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 1.2779993 0.9338365 1.0147070
postResample(pred = svm_Pred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 2.0742046 0.8255756 1.5755441
postResample(pred = nnet_Pred, obs = testData$y)
##      RMSE  Rsquared       MAE 
## 2.3462095 0.7880683 1.7537538

Per the output above, noted that the MARS model had the best performance.

mars_vi <- varImp(marsTuned)
mars_vi
## earth variable importance
## 
##    Overall
## X1  100.00
## X4   75.40
## X2   49.00
## X5   15.72
## X3    0.00

Indeed, the MARS model identified the informative predictors (X1–X5), consistent with the structure of the simulated data. Among these, X1 had the greatest influence, followed by X4 and X2. Although X3 and X5 were included, their contributions were comparatively minor.

7.5

7.5. Exercise 6.3 describes data for a chemical manufacturing process. Use the same data imputation, data splitting, and pre-processing steps as before and train several nonlinear regression models.

library(AppliedPredictiveModeling)
data("ChemicalManufacturingProcess")

# Preprocessing
prep_obj <- preProcess(ChemicalManufacturingProcess, 
                       method = c("BoxCox", "knnImpute", "center", "scale")) 

processed_data <- predict(prep_obj, ChemicalManufacturingProcess)
processed_data$Yield <- ChemicalManufacturingProcess$Yield


set.seed(1234) 
ind <- sample(seq_len(nrow(processed_data)), size = floor(0.7 * nrow(processed_data))) 
train <- processed_data[ind, ]
test <- processed_data[-ind, ]
#KNN
knn_Model_2 <- train(Yield~., data = train,
                     method = "knn",
                     preProc = c("center", "scale"),
                     tuneLength = 10)
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
knn_Pred_2 <- predict(knn_Model_2, newdata = test)

# MARS
mars_Tuned_2 <- train(Yield~., data = train,
                      method = "earth",
                      preProcess = c("center","scale"),
                      tuneGrid = marsGrid,
                      trControl = trainControl(method = "cv")
)
mars_Pred_2 <-predict(mars_Tuned_2, newdata = test)

# SVM
svm_Tuned_2 <- train(Yield~., data = train,
                     method = "svmRadial",
                     preProc = c("center", "scale"),
                     tuneLength = 14,
                     trControl = trainControl(method = "cv"))
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in preProcess.default(thresh = 0.95, k = 5, freqCut = 19, uniqueCut =
## 10, : These variables have zero variances: BiologicalMaterial07
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
svm_Pred_2 <- predict(svm_Tuned_2, newdata = test)

# Neural Networks Model
nnet_Tune_2 <- train(Yield~., data = train,
                  method = "avNNet",
                  tuneGrid = nnetGrid,
                  trControl = trainControl(method = "cv"),
                  preProc = c("center", "scale"),
                  linout = TRUE,
                  trace = FALSE,
                  MaxNWts = 10 * (ncol(train) + 1) + 5 + 1,
                  maxit = 500)
nnet_Pred_2 <- predict(nnet_Tune_2 , newdata = test)

(a) Which nonlinear regression model gives the optimal resampling and test set performance?

as.data.frame(rbind(
  "mars" = postResample(pred = mars_Pred_2, obs = test$Yield),
  "svm" = postResample(pred = svm_Pred_2, obs = test$Yield),
  "net" = postResample(pred = nnet_Pred_2, obs = test$Yield),
  "knn" = postResample(pred = knn_Pred_2, obs = test$Yield)
))
##          RMSE  Rsquared       MAE
## mars 1.143137 0.6080421 0.9365946
## svm  1.119109 0.6242347 0.9259233
## net  1.300152 0.5708694 1.0844035
## knn  1.281322 0.5464574 1.0755629

Based on the outputs, the SVM model gives the optimal test performance.

(b) Which predictors are most important in the optimal nonlinear regression model? Do either the biological or process variables dominate the list? How do the top ten important predictors compare to the top ten predictors from the optimal linear model?

varImp(svm_Tuned_2, 10)
## loess r-squared variable importance
## 
##   only 20 most important variables shown (out of 57)
## 
##                        Overall
## ManufacturingProcess32  100.00
## ManufacturingProcess13   75.95
## ManufacturingProcess36   64.61
## BiologicalMaterial12     64.56
## BiologicalMaterial06     64.51
## ManufacturingProcess17   64.04
## BiologicalMaterial03     59.78
## ManufacturingProcess09   59.66
## BiologicalMaterial11     50.12
## ManufacturingProcess06   49.66
## BiologicalMaterial02     49.41
## ManufacturingProcess31   47.63
## ManufacturingProcess33   46.45
## ManufacturingProcess11   40.78
## BiologicalMaterial04     35.76
## BiologicalMaterial08     34.42
## ManufacturingProcess18   32.34
## BiologicalMaterial09     32.01
## ManufacturingProcess29   30.00
## ManufacturingProcess02   28.79

Per the question, the top 10 predictors identified by the SVM (non-linear) model represent the most important features.

When comparing these to the top 10 predictors from the PLS model (Homework 7), the PLS top features were:

ManufacturingProcess32

ManufacturingProcess09

ManufacturingProcess17

ManufacturingProcess13

ManufacturingProcess36

ManufacturingProcess06

BiologicalMaterial02

ManufacturingProcess33

ManufacturingProcess11

BiologicalMaterial06

In the PLS model, 8 of the top 10 predictors were related to ManufacturingProcess, while *2 were BiologicalMaterial.

In contrast, the SVM model shows a more balanced distribution, with 6 ManufacturingProcess features and 4 BiologicalMaterial features.

(c) Explore the relationships between the top predictors and the response for the predictors that are unique to the optimal nonlinear regression model. Do these plots reveal intuition about the biological or process predictors and their relationship with yield?

svm_importance <- varImp(svm_Tuned_2)$importance

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
top_vars <- svm_importance %>%
  tibble::rownames_to_column(var = "Predictor") %>%
  arrange(desc(Overall)) %>%
  slice(1:10) %>%
  pull(Predictor)

featurePlot(x = train[, top_vars],
            y = train$Yield,
            plot = "scatter",
            layout = c(5, 2))

The plots show the relationship between the top 10 predictors and the response variable. For the SVM model (identified as the optimal choice), these predictors exhibit a largely linear association with the response. In addition, this suggests that strategically adjusting biological or process variables either increasing or decreasing them in line with the observed slope can meaningfully optimize yield outcomes.