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(πx_1x_2) + 20(x^3 − 0.5)^2 + 10x_4 + 5x_5 + 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:
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)
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
X1–X5)?In this section, we will be tuning a neural network model. Let’s first remove predictors to ensure that the maximum absolute pairwise correlation between the predictors is less than 0.75.
tooHigh <- findCorrelation(cor(trainingData$x), cutoff = 0.75)
tooHigh
## integer(0)
The output above shows us that none of the predictors have a correlation that is higher than 0.75. Therefore, we retain all of the predictors when the model is fit. Next, we choose a specific candidate set of models to evaluate.
nnetGrid <- expand.grid(.decay = c(0, 0.01, 0.1),
.size = c(1:10),
.bag = FALSE)
Now we use the train function to select the optimal
model using the avNNet method. We also use the
postResample function that was used when the kNN model was
fit earlier in order to get the test set performance values for the
neural network model.
set.seed(100)
ctrl <- trainControl(method = "cv", number = 10)
nnetTune <- train(trainingData$x, trainingData$y,
method = "avNNet",
tuneGrid = nnetGrid,
trControl = ctrl,
preProc = c("center", "scale"),
linout = TRUE,
trace = FALSE,
MaxNWts = 10 * (ncol(trainingData$x) + 1) + 10 + 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.392711 0.7610354 1.897330
## 0.00 2 2.410518 0.7567157 1.907473
## 0.00 3 2.042213 0.8227273 1.629659
## 0.00 4 2.298304 0.8124166 1.753146
## 0.00 5 2.453227 0.7662986 1.833239
## 0.00 6 2.990090 0.7253762 2.099273
## 0.00 7 3.701668 0.6360247 2.617741
## 0.00 8 6.367553 0.4487714 3.545487
## 0.00 9 4.499984 0.5672515 2.914440
## 0.00 10 3.576715 0.6041044 2.498480
## 0.01 1 2.385404 0.7602882 1.887923
## 0.01 2 2.425125 0.7510902 1.935992
## 0.01 3 2.151205 0.8016026 1.701949
## 0.01 4 2.091926 0.8154381 1.676654
## 0.01 5 2.168421 0.8011423 1.742388
## 0.01 6 2.226214 0.8107690 1.792368
## 0.01 7 2.325296 0.7858326 1.838310
## 0.01 8 2.418661 0.7784524 1.921072
## 0.01 9 2.436470 0.7697600 1.937039
## 0.01 10 2.470258 0.7456508 1.983696
## 0.10 1 2.393965 0.7596431 1.894191
## 0.10 2 2.423612 0.7525959 1.935872
## 0.10 3 2.169914 0.7982381 1.726853
## 0.10 4 2.059073 0.8224173 1.648603
## 0.10 5 1.980710 0.8386011 1.591131
## 0.10 6 2.152712 0.8098058 1.693933
## 0.10 7 2.168975 0.8150267 1.692585
## 0.10 8 2.278973 0.7915391 1.827456
## 0.10 9 2.314468 0.7819936 1.782130
## 0.10 10 2.318887 0.7724807 1.854668
##
## 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 = 5, decay = 0.1 and bag = FALSE.
nnetPred <- predict(nnetTune, newdata = testData$x)
postResample(pred = nnetPred, obs = testData$y)
## RMSE Rsquared MAE
## 2.1113946 0.8277558 1.5739006
We use the train function to select the optimal model
using the earth method. We also use the
postResample function that was used when the kNN model was
fit earlier in order to get the test set performance values for the MARS
model.
marsGrid <- expand.grid(.degree = 1:2, .nprune = 2:38)
set.seed(100)
marsTuned <- train(trainingData$x, trainingData$y,
method = "earth",
tuneGrid = marsGrid,
trControl = trainControl(method = "cv"))
## Loading required package: earth
## Loading required package: Formula
## Loading required package: plotmo
## Loading required package: plotrix
## Loading required package: TeachingDemos
marsTuned
## Multivariate Adaptive Regression Spline
##
## 200 samples
## 10 predictor
##
## No pre-processing
## 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.600474
## 1 3 3.572450 0.4912720 2.895811
## 1 4 2.596841 0.7183600 2.106341
## 1 5 2.370161 0.7659777 1.918669
## 1 6 2.276141 0.7881481 1.810001
## 1 7 1.766728 0.8751831 1.390215
## 1 8 1.780946 0.8723243 1.401345
## 1 9 1.665091 0.8819775 1.325515
## 1 10 1.663804 0.8821283 1.327657
## 1 11 1.657738 0.8822967 1.331730
## 1 12 1.653784 0.8827903 1.331504
## 1 13 1.648496 0.8823663 1.316407
## 1 14 1.639073 0.8841742 1.312833
## 1 15 1.639073 0.8841742 1.312833
## 1 16 1.639073 0.8841742 1.312833
## 1 17 1.639073 0.8841742 1.312833
## 1 18 1.639073 0.8841742 1.312833
## 1 19 1.639073 0.8841742 1.312833
## 1 20 1.639073 0.8841742 1.312833
## 1 21 1.639073 0.8841742 1.312833
## 1 22 1.639073 0.8841742 1.312833
## 1 23 1.639073 0.8841742 1.312833
## 1 24 1.639073 0.8841742 1.312833
## 1 25 1.639073 0.8841742 1.312833
## 1 26 1.639073 0.8841742 1.312833
## 1 27 1.639073 0.8841742 1.312833
## 1 28 1.639073 0.8841742 1.312833
## 1 29 1.639073 0.8841742 1.312833
## 1 30 1.639073 0.8841742 1.312833
## 1 31 1.639073 0.8841742 1.312833
## 1 32 1.639073 0.8841742 1.312833
## 1 33 1.639073 0.8841742 1.312833
## 1 34 1.639073 0.8841742 1.312833
## 1 35 1.639073 0.8841742 1.312833
## 1 36 1.639073 0.8841742 1.312833
## 1 37 1.639073 0.8841742 1.312833
## 1 38 1.639073 0.8841742 1.312833
## 2 2 4.327937 0.2544880 3.600474
## 2 3 3.572450 0.4912720 2.895811
## 2 4 2.661826 0.7070510 2.173471
## 2 5 2.404015 0.7578971 1.975387
## 2 6 2.243927 0.7914805 1.783072
## 2 7 1.856336 0.8605482 1.435682
## 2 8 1.754607 0.8763186 1.396841
## 2 9 1.603578 0.8938666 1.261361
## 2 10 1.492421 0.9084998 1.168700
## 2 11 1.317350 0.9292504 1.033926
## 2 12 1.304327 0.9320133 1.019108
## 2 13 1.277510 0.9323681 1.002927
## 2 14 1.269626 0.9350024 1.003346
## 2 15 1.266217 0.9359400 1.013893
## 2 16 1.268470 0.9354868 1.011414
## 2 17 1.268470 0.9354868 1.011414
## 2 18 1.268470 0.9354868 1.011414
## 2 19 1.268470 0.9354868 1.011414
## 2 20 1.268470 0.9354868 1.011414
## 2 21 1.268470 0.9354868 1.011414
## 2 22 1.268470 0.9354868 1.011414
## 2 23 1.268470 0.9354868 1.011414
## 2 24 1.268470 0.9354868 1.011414
## 2 25 1.268470 0.9354868 1.011414
## 2 26 1.268470 0.9354868 1.011414
## 2 27 1.268470 0.9354868 1.011414
## 2 28 1.268470 0.9354868 1.011414
## 2 29 1.268470 0.9354868 1.011414
## 2 30 1.268470 0.9354868 1.011414
## 2 31 1.268470 0.9354868 1.011414
## 2 32 1.268470 0.9354868 1.011414
## 2 33 1.268470 0.9354868 1.011414
## 2 34 1.268470 0.9354868 1.011414
## 2 35 1.268470 0.9354868 1.011414
## 2 36 1.268470 0.9354868 1.011414
## 2 37 1.268470 0.9354868 1.011414
## 2 38 1.268470 0.9354868 1.011414
##
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were nprune = 15 and degree = 2.
marsPred <- predict(marsTuned, newdata = testData$x)
postResample(pred = marsPred, obs = testData$y)
## RMSE Rsquared MAE
## 1.1589948 0.9460418 0.9250230
varImp(marsTuned)
## earth variable importance
##
## Overall
## X1 100.00
## X4 75.24
## X2 48.73
## X5 15.52
## X3 0.00
svmRTuned <- train(trainingData$x, trainingData$y,
method = "svmRadial",
preProc = c("center", "scale"),
tuneLength = 14,
trControl = trainControl(method = "cv"))
svmRTuned
## 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.849240 0.8654699 1.436630
## 16.00 1.834604 0.8673639 1.429807
## 32.00 1.833221 0.8675754 1.428687
## 64.00 1.833221 0.8675754 1.428687
## 128.00 1.833221 0.8675754 1.428687
## 256.00 1.833221 0.8675754 1.428687
## 512.00 1.833221 0.8675754 1.428687
## 1024.00 1.833221 0.8675754 1.428687
## 2048.00 1.833221 0.8675754 1.428687
##
## 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.
svmRPred <- predict(svmRTuned, newdata = testData$x)
postResample(pred = svmRPred, obs = testData$y)
## RMSE Rsquared MAE
## 2.0741473 0.8255848 1.5755185
We have ranked the models that were generated in 7.2a in terms of lowest to highest test set RMSE as shown below:
Test set Rsquared ranking:
varImp shows that MARS selected all 5 informative
predictors. However, X3 has an importance of 0, so that
predictor has no importance to the model.
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.
Which nonlinear regression model gives the optimal resampling and test set performance?
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?
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?
Let’s go ahead and apply the data preprocessing that was applied in the first few parts of Exercise 6.3.
data(ChemicalManufacturingProcess)
Using the methodology explained in Section 3.8, we impute using the code chunk below.
impute <- ChemicalManufacturingProcess %>%
preProcess("knnImpute")
imputed <- predict(impute, ChemicalManufacturingProcess)
Let’s use that nearzerovar function that we used in the
previous problem. Let’s split the data into X and y.
X <- imputed %>% select(-Yield)
y <- imputed$Yield
high_freq_predictors <- X[,-nearZeroVar(X)]
dim(high_freq_predictors)
## [1] 176 56
We create the training and test set in the code chunk below.
set.seed(1)
sample <- sample.split(y, SplitRatio = 0.8)
train_X <- subset(high_freq_predictors, sample == TRUE) %>% as.matrix()
test_X <- subset(high_freq_predictors, sample == FALSE) %>% as.matrix()
train_y <- subset(y, sample == TRUE) %>% as.vector()
test_y <- subset(y, sample == FALSE) %>% as.vector()
dim(train_X)
## [1] 140 56
dim(test_X)
## [1] 36 56
knnModel <- train(x = train_X,
y = train_y,
method = "knn",
preProc = c("center", "scale"),
tuneLength = 10)
knnModel
## k-Nearest Neighbors
##
## 140 samples
## 56 predictor
##
## Pre-processing: centered (56), scaled (56)
## Resampling: Bootstrapped (25 reps)
## Summary of sample sizes: 140, 140, 140, 140, 140, 140, ...
## Resampling results across tuning parameters:
##
## k RMSE Rsquared MAE
## 5 0.8203871 0.3918288 0.6591670
## 7 0.8096613 0.4009935 0.6537854
## 9 0.8080523 0.4037299 0.6545781
## 11 0.8012788 0.4190412 0.6484671
## 13 0.8084688 0.4112808 0.6572026
## 15 0.8112737 0.4124434 0.6599622
## 17 0.8182807 0.4072181 0.6654095
## 19 0.8220471 0.4045265 0.6699249
## 21 0.8207351 0.4122081 0.6697612
## 23 0.8252339 0.4105716 0.6718421
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was k = 11.
knnPred <- predict(knnModel, newdata = test_X)
## The function 'postResample' can be used to get the test set
## perforamnce values
postResample(pred = knnPred, obs = test_y)
## RMSE Rsquared MAE
## 0.6583320 0.4539031 0.5285518
In this section, we will be tuning a neural network model. Let’s first remove predictors to ensure that the maximum absolute pairwise correlation between the predictors is less than 0.75.
tooHigh <- findCorrelation(cor(train_X), cutoff = 0.75)
train_Xnnet <- train_X
The output above shows us that none of the predictors have a correlation that is higher than 0.75. Therefore, we retain all of the predictors when the model is fit. Next, we choose a specific candidate set of models to evaluate.
nnetGrid <- expand.grid(.decay = c(0, 0.01, 0.1),
.size = c(1:10),
.bag = FALSE)
Now we use the train function to select the optimal
model using the avNNet method. We also use the
postResample function that was used when the kNN model was
fit earlier in order to get the test set performance values for the
neural network model.
set.seed(100)
ctrl <- trainControl(method = "cv", number = 10)
nnetTune <- train(train_X, train_y,
method = "avNNet",
tuneGrid = nnetGrid,
trControl = ctrl,
preProc = c("center", "scale"),
linout = TRUE,
trace = FALSE,
MaxNWts = 10 * (ncol(train_X) + 1) + 10 + 1,
maxit = 500)
nnetTune
## Model Averaged Neural Network
##
## 140 samples
## 56 predictor
##
## Pre-processing: centered (56), scaled (56)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 127, 126, 125, 127, 125, 127, ...
## Resampling results across tuning parameters:
##
## decay size RMSE Rsquared MAE
## 0.00 1 1.0383587 0.4124945 0.7395549
## 0.00 2 0.8021403 0.4848498 0.6318406
## 0.00 3 0.7523607 0.5305686 0.6015196
## 0.00 4 0.8261727 0.4693496 0.6389089
## 0.00 5 0.7977515 0.5258618 0.6462726
## 0.00 6 0.7670614 0.5170159 0.6050598
## 0.00 7 0.7677520 0.5005221 0.6185543
## 0.00 8 0.7083751 0.5721998 0.5656157
## 0.00 9 0.7111370 0.5846413 0.5510601
## 0.00 10 0.6371079 0.6323115 0.4985251
## 0.01 1 0.7796390 0.5119196 0.6294281
## 0.01 2 0.7799653 0.5305309 0.6177465
## 0.01 3 0.7025145 0.5991779 0.5560764
## 0.01 4 0.7141511 0.5830925 0.5649898
## 0.01 5 0.6911056 0.5877852 0.5528325
## 0.01 6 0.6263747 0.6463795 0.4988010
## 0.01 7 0.6451253 0.6318417 0.5154260
## 0.01 8 0.6262976 0.6566447 0.5035750
## 0.01 9 0.6495123 0.6305932 0.5195316
## 0.01 10 0.6289784 0.6490827 0.5061199
## 0.10 1 0.7975630 0.5242693 0.6290957
## 0.10 2 0.6829790 0.6132925 0.5494695
## 0.10 3 0.6743380 0.6189074 0.5387519
## 0.10 4 0.6357409 0.6234189 0.5179239
## 0.10 5 0.6210227 0.6438184 0.4891707
## 0.10 6 0.6514375 0.6160659 0.5306190
## 0.10 7 0.6505771 0.6252214 0.5075498
## 0.10 8 0.6457836 0.6224227 0.5205691
## 0.10 9 0.6445693 0.6332342 0.5104517
## 0.10 10 0.6142998 0.6622014 0.4904430
##
## 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 = 10, decay = 0.1 and bag = FALSE.
nnetPred <- predict(nnetTune, newdata = test_X)
postResample(pred = nnetPred, obs = test_y)
## RMSE Rsquared MAE
## 0.6367815 0.5522917 0.5276211
We use the train function to select the optimal model
using the earth method. We also use the
postResample function that was used when the kNN model was
fit earlier in order to get the test set performance values for the MARS
model.
marsGrid <- expand.grid(.degree = 1:2, .nprune = 2:38)
set.seed(100)
marsTuned <- train(train_X, train_y,
method = "earth",
tuneGrid = marsGrid,
trControl = trainControl(method = "cv"))
marsTuned
## Multivariate Adaptive Regression Spline
##
## 140 samples
## 56 predictor
##
## No pre-processing
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 127, 126, 125, 127, 125, 127, ...
## Resampling results across tuning parameters:
##
## degree nprune RMSE Rsquared MAE
## 1 2 0.7731243 0.4679699 0.6207529
## 1 3 0.6695619 0.5968150 0.5350137
## 1 4 0.6273833 0.6519416 0.5091570
## 1 5 0.6339244 0.6346083 0.5078710
## 1 6 0.6648322 0.6125564 0.5408419
## 1 7 0.6575789 0.6212072 0.5241492
## 1 8 0.6602298 0.6116736 0.5271172
## 1 9 0.6399185 0.6389609 0.5320271
## 1 10 0.6404490 0.6430765 0.5309098
## 1 11 0.5993754 0.6745805 0.4925254
## 1 12 0.6065006 0.6684274 0.4952226
## 1 13 0.6079134 0.6641564 0.4930752
## 1 14 0.5968460 0.6725769 0.4901824
## 1 15 0.5949856 0.6739202 0.4877240
## 1 16 0.6020424 0.6691574 0.4946932
## 1 17 0.6020424 0.6691574 0.4946932
## 1 18 0.6020424 0.6691574 0.4946932
## 1 19 0.6020424 0.6691574 0.4946932
## 1 20 0.6020424 0.6691574 0.4946932
## 1 21 0.6020424 0.6691574 0.4946932
## 1 22 0.6020424 0.6691574 0.4946932
## 1 23 0.6020424 0.6691574 0.4946932
## 1 24 0.6020424 0.6691574 0.4946932
## 1 25 0.6020424 0.6691574 0.4946932
## 1 26 0.6020424 0.6691574 0.4946932
## 1 27 0.6020424 0.6691574 0.4946932
## 1 28 0.6020424 0.6691574 0.4946932
## 1 29 0.6020424 0.6691574 0.4946932
## 1 30 0.6020424 0.6691574 0.4946932
## 1 31 0.6020424 0.6691574 0.4946932
## 1 32 0.6020424 0.6691574 0.4946932
## 1 33 0.6020424 0.6691574 0.4946932
## 1 34 0.6020424 0.6691574 0.4946932
## 1 35 0.6020424 0.6691574 0.4946932
## 1 36 0.6020424 0.6691574 0.4946932
## 1 37 0.6020424 0.6691574 0.4946932
## 1 38 0.6020424 0.6691574 0.4946932
## 2 2 0.7731243 0.4679699 0.6207529
## 2 3 0.6589279 0.6118564 0.5313475
## 2 4 0.6293294 0.6456628 0.5095794
## 2 5 0.6473245 0.6261561 0.5333374
## 2 6 0.6196905 0.6550568 0.5000580
## 2 7 0.6019125 0.6616725 0.4864107
## 2 8 0.6021240 0.6677157 0.4962321
## 2 9 0.5783037 0.6848493 0.4856149
## 2 10 0.5845088 0.6848995 0.4856345
## 2 11 0.5916643 0.6820425 0.4881640
## 2 12 0.5785474 0.6980541 0.4818246
## 2 13 0.5749829 0.7019373 0.4775815
## 2 14 0.6080240 0.6612025 0.4873035
## 2 15 0.6440286 0.6393022 0.5009575
## 2 16 0.6586617 0.6400200 0.5022585
## 2 17 0.6646325 0.6384985 0.5036047
## 2 18 0.6598414 0.6450454 0.4971941
## 2 19 0.6700409 0.6339521 0.5049150
## 2 20 0.6774875 0.6232103 0.5095003
## 2 21 0.6973465 0.6103730 0.5214947
## 2 22 0.7300303 0.5836334 0.5393437
## 2 23 0.7477286 0.5691338 0.5502467
## 2 24 0.7861341 0.5323744 0.5761353
## 2 25 0.7902271 0.5303549 0.5794661
## 2 26 0.7902271 0.5303549 0.5794661
## 2 27 0.7961166 0.5279938 0.5817525
## 2 28 0.8148103 0.5290377 0.6006988
## 2 29 0.8165357 0.5294849 0.6033173
## 2 30 0.8165357 0.5294849 0.6033173
## 2 31 0.8165357 0.5294849 0.6033173
## 2 32 0.8165357 0.5294849 0.6033173
## 2 33 0.8165357 0.5294849 0.6033173
## 2 34 0.8165357 0.5294849 0.6033173
## 2 35 0.8165357 0.5294849 0.6033173
## 2 36 0.8165357 0.5294849 0.6033173
## 2 37 0.8165357 0.5294849 0.6033173
## 2 38 0.8165357 0.5294849 0.6033173
##
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were nprune = 13 and degree = 2.
marsPred <- predict(marsTuned, newdata = test_X)
postResample(pred = marsPred, obs = test_y)
## RMSE Rsquared MAE
## 0.8608827 0.3822273 0.6287883
varImp(marsTuned)
## earth variable importance
##
## Overall
## ManufacturingProcess32 100.000
## ManufacturingProcess13 53.132
## ManufacturingProcess28 33.175
## ManufacturingProcess39 29.773
## ManufacturingProcess30 16.508
## ManufacturingProcess31 7.917
## BiologicalMaterial03 7.917
## ManufacturingProcess22 7.917
## ManufacturingProcess02 7.917
## ManufacturingProcess35 7.917
## ManufacturingProcess09 0.000
svmRTuned <- train(train_X, train_y,
method = "svmRadial",
preProc = c("center", "scale"),
tuneLength = 14,
trControl = trainControl(method = "cv"))
svmRTuned
## Support Vector Machines with Radial Basis Function Kernel
##
## 140 samples
## 56 predictor
##
## Pre-processing: centered (56), scaled (56)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 127, 126, 126, 126, 125, 126, ...
## Resampling results across tuning parameters:
##
## C RMSE Rsquared MAE
## 0.25 0.7971637 0.4639220 0.6559147
## 0.50 0.7346726 0.5246702 0.6076236
## 1.00 0.6793790 0.5848941 0.5573639
## 2.00 0.6355369 0.6293706 0.5120458
## 4.00 0.6251688 0.6429718 0.4976226
## 8.00 0.6297398 0.6447173 0.5041725
## 16.00 0.6279340 0.6470162 0.5028551
## 32.00 0.6279340 0.6470162 0.5028551
## 64.00 0.6279340 0.6470162 0.5028551
## 128.00 0.6279340 0.6470162 0.5028551
## 256.00 0.6279340 0.6470162 0.5028551
## 512.00 0.6279340 0.6470162 0.5028551
## 1024.00 0.6279340 0.6470162 0.5028551
## 2048.00 0.6279340 0.6470162 0.5028551
##
## Tuning parameter 'sigma' was held constant at a value of 0.01478142
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were sigma = 0.01478142 and C = 4.
svmRPred <- predict(svmRTuned, newdata = test_X)
postResample(pred = svmRPred, obs = test_y)
## RMSE Rsquared MAE
## 0.5976901 0.5624685 0.4623860
varImp(svmRTuned)
## loess r-squared variable importance
##
## only 20 most important variables shown (out of 56)
##
## Overall
## ManufacturingProcess32 100.00
## ManufacturingProcess13 98.03
## BiologicalMaterial06 86.76
## ManufacturingProcess09 84.29
## BiologicalMaterial03 79.41
## ManufacturingProcess17 79.32
## ManufacturingProcess31 76.95
## BiologicalMaterial02 69.88
## BiologicalMaterial12 69.71
## ManufacturingProcess36 67.83
## ManufacturingProcess06 57.40
## ManufacturingProcess11 55.01
## BiologicalMaterial04 54.73
## BiologicalMaterial11 45.83
## ManufacturingProcess29 45.61
## BiologicalMaterial08 44.90
## BiologicalMaterial01 44.41
## ManufacturingProcess33 43.41
## ManufacturingProcess30 41.97
## BiologicalMaterial09 40.99
The nonlinear regression model that gives the optimal resampling and test set performance is the support vector machines model. It has the lowest RMSE value of 0.598 and the highest Rsquared of 0.562. Since this Rsquared is above 0.5, we can assume that the model is doing better than just taking a guess.
The top 20 most important predictors are shown in the “Support Vector
Machines” subsection of “Question 7.5 Model Fitting”. Out of the top 20,
11 of the predictors are manufacturing process related while 9 are
biological. Note also that the top 2 predictors are manufacturing
process related, which indicate that process variables dominate the
list. In Homework 7, the top 6 predictors were manufacturing processes
(32, 09, 13, 17, 36, 11), while the next 4 top predictors were
biological (02, 08, 06, 12). In the model for this homework,
ManufacturingProcess32 still reigns out as the top
predictor, with ManufacturingProcesses’s 13, 09, and 17
still being in the top 6. ManufacturingProcess31 is more
important than 36 and 11 in this homework’s model, however. Also in the
SVM model, BiologicalMaterial03 beats out 02, 12, and 08,
with the top BiologicalMaterial being 06
instead of 02 like in Homework 7.
top_10_predictors_row_names <- varImp(svmRTuned)$importance %>%
arrange(desc(Overall)) %>%
head(10) %>%
row.names() %>%
as.vector()
top_10_predictors_df = subset(high_freq_predictors) %>%
select(top_10_predictors_row_names)
## Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
## ℹ Please use `all_of()` or `any_of()` instead.
## # Was:
## data %>% select(top_10_predictors_row_names)
##
## # Now:
## data %>% select(all_of(top_10_predictors_row_names))
##
## See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
top_10_predictors_df$Yield = y
corrplot::corrplot(cor(dplyr::select_if(top_10_predictors_df, is.numeric), use = "na.or.complete"),
method = 'number',
type = 'lower',
diag = FALSE,
number.cex = 0.75,
tl.cex = 0.75)
The plot above shows us the correlations between the top 10 predictors and the yield. Some of the processes above have a negative correlation with yield, while others have a positive yield. As we can see from the output above, Manufacturing Processes 13, 17, 31, and 36 have a negative correlation. This means that yield might increase if these manufacturing processes would decrease, while we would have in increase in all of the other processes, so we would probably have to reallocate resources accordingly. The inverse might also be true too, However, with that being said, there could be another model type that we didn’t explore in this question that gives us a totally different plot. So we should be cognizant of that including the fact that we also have to worry about budgetary constraints, manufacturing hiccups, etc. But based on this plot, we could investigate those four variables that have a negative correlation with yield.