CUNY DATA624 HW8
CUNY DATA624 HW8
- 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 = 10sin(\pi x_1x_2)+20(x_3-0.5)^2+10x_4+5x_5+N(0,\sigma^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
mlbenchcontains a function calledmlbench.friedman1that simulates these data. Tune several models on these data. Which models appear to give the best performance? Does MARS select the informative predictors (those named X1–X5)? - 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.
- a) Which nonlinear regression model gives the optimal resampling and test set 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?
- 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?
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 = 10sin(\pi x_1x_2)+20(x_3-0.5)^2+10x_4+5x_5+N(0,\sigma^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. Tune several models on these data. Which models appear to give the best performance? Does MARS select the informative predictors (those named X1–X5)?
library(mlbench)
library(caret)
library(earth)
library(kernlab)
library(nnet)
library(dplyr)
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)
ctrl = trainControl(method='cv', number = 10)We’ll first tune all the models we reviewed in this chapter on these data. A discussion on their performance and a review on the selection of predictors by MARS will be addressed after all the code below.
Neural Networks
# pairwise correlations above .75? below code indicates that none should be removed
findCorrelation(cor(trainingData$x), cutoff = .75)## integer(0)
nnetGrid <- expand.grid(.decay = c(0, 0.01, .1),
.size = c(1:10),
.bag = FALSE)
set.seed(200)
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)
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.419793 0.7588010 1.901035
## 0.00 2 2.422816 0.7594582 1.940173
## 0.00 3 2.041362 0.8181359 1.633726
## 0.00 4 1.939450 0.8377746 1.543959
## 0.00 5 2.211702 0.8074118 1.704590
## 0.00 6 3.533742 0.7020449 2.429941
## 0.00 7 4.027692 0.5134682 2.622060
## 0.00 8 5.137822 0.5156341 2.945668
## 0.00 9 4.369035 0.5468500 2.642635
## 0.00 10 3.609575 0.6315288 2.479800
## 0.01 1 2.380815 0.7641956 1.871141
## 0.01 2 2.456920 0.7487966 1.925584
## 0.01 3 2.152609 0.8037272 1.690705
## 0.01 4 1.926277 0.8453339 1.547263
## 0.01 5 2.146963 0.8049558 1.720227
## 0.01 6 2.180892 0.8035828 1.726802
## 0.01 7 2.426249 0.7619762 1.897147
## 0.01 8 2.340684 0.7734668 1.861875
## 0.01 9 2.335967 0.7711315 1.774816
## 0.01 10 2.293204 0.7905997 1.827312
## 0.10 1 2.392293 0.7614554 1.873843
## 0.10 2 2.434407 0.7561433 1.914401
## 0.10 3 2.136585 0.8043175 1.702667
## 0.10 4 2.009687 0.8245223 1.574396
## 0.10 5 2.015258 0.8345995 1.586705
## 0.10 6 2.024669 0.8328084 1.587755
## 0.10 7 2.140729 0.8106139 1.697657
## 0.10 8 2.142751 0.8125229 1.677119
## 0.10 9 2.256561 0.7944028 1.764742
## 0.10 10 2.351316 0.7747074 1.848626
##
## 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.01 and bag = FALSE.
## decay size bag RMSE Rsquared MAE
## 4 0 4 FALSE 1.93945 0.8377746 1.543959
## RMSE Rsquared MAE
## 2.0603961 0.8320659 1.5289913
MARS
marsGrid <- expand.grid(.degree = 1:2, .nprune = 2:38)
set.seed(100)
marsTuned <- train(trainingData$x, trainingData$y,
method = "earth",
tuneGrid = marsGrid,
trControl = ctrl)
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.
## earth variable importance
##
## Overall
## X1 100.00
## X4 85.14
## X2 69.24
## X5 49.31
## X3 40.00
## X9 0.00
## X6 0.00
## X8 0.00
## X7 0.00
## X10 0.00
Predictors selected for MARS in order of importance: X1, X4, X2, X5, X3
## degree nprune RMSE Rsquared MAE
## 53 2 17 1.26847 0.9354868 1.011414
mars_pred <- predict(marsTuned, newdata = testData$x)
postResample(obs = testData$y, pred=mars_pred[,1])## RMSE Rsquared MAE
## 1.1589948 0.9460418 0.9250230
SVM
set.seed(100)
svmRTuned <- train(trainingData$x, trainingData$y,
method = "svmRadial",
preProc = c("center", "scale"),
tuneLength = 14,
trControl = ctrl)
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.530787 0.7922715 2.013175
## 0.50 2.259539 0.8064569 1.789962
## 1.00 2.099807 0.8274221 1.656171
## 2.00 2.002943 0.8412934 1.583791
## 4.00 1.943618 0.8504425 1.546586
## 8.00 1.918690 0.8547623 1.532967
## 16.00 1.920708 0.8536069 1.536132
## 32.00 1.920708 0.8536069 1.536132
## 64.00 1.920708 0.8536069 1.536132
## 128.00 1.920708 0.8536069 1.536132
## 256.00 1.920708 0.8536069 1.536132
## 512.00 1.920708 0.8536069 1.536132
## 1024.00 1.920708 0.8536069 1.536132
## 2048.00 1.920708 0.8536069 1.536132
##
## Tuning parameter 'sigma' was held constant at a value of 0.06509124
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were sigma = 0.06509124 and C = 8.
## sigma C RMSE Rsquared MAE
## 7 0.06509124 16 1.920708 0.8536069 1.536132
## RMSE Rsquared MAE
## 2.0631908 0.8275736 1.5662213
kNN
# using the nearZeroVar function to clarify if any predictors should be removed
# None need to be removed
nearZeroVar(trainingData$x)## integer(0)
set.seed(100)
knnTune <- train(trainingData$x, trainingData$y,
method = "knn",
preProc = c("center", "scale"),
tuneGrid = data.frame(.k = 1:20),
trControl = ctrl)
knnTune## k-Nearest Neighbors
##
## 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:
##
## k RMSE Rsquared MAE
## 1 4.145885 0.3858365 3.400886
## 2 3.480234 0.5147442 2.884806
## 3 3.399791 0.5310430 2.785317
## 4 3.305300 0.5675855 2.690192
## 5 3.294708 0.5741615 2.685061
## 6 3.177043 0.6143090 2.574080
## 7 3.118386 0.6362889 2.533011
## 8 3.115022 0.6476225 2.491541
## 9 3.079720 0.6701072 2.434483
## 10 3.053990 0.6793621 2.450833
## 11 3.087654 0.6827260 2.465405
## 12 3.097555 0.6844193 2.479759
## 13 3.112509 0.6860599 2.478242
## 14 3.117615 0.6926560 2.495885
## 15 3.124561 0.7012335 2.483030
## 16 3.116848 0.7070241 2.491207
## 17 3.139571 0.7022941 2.512573
## 18 3.134526 0.7098078 2.512939
## 19 3.132326 0.7206930 2.520935
## 20 3.139232 0.7261771 2.537920
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was k = 10.
## k RMSE Rsquared MAE
## 11 11 3.087654 0.682726 2.465405
## RMSE Rsquared MAE
## 3.117237 0.662910 2.492072
Discussion of above models
In the above, we can see that the best model to use would be the MARS model. It performs very well on the test set with a relatively low RMSE and high \(R^2\). The MARS model does select informative predictors (X1-X5). In order of importance (most to less important): X1, X4, X2, X5, X3
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.
First, we’ll prep the data in the same way we did in the previous assignment
library(AppliedPredictiveModeling)
library(VIM)
data(ChemicalManufacturingProcess)
cmpImp <- kNN(ChemicalManufacturingProcess, imp_var = FALSE) # kNN imputation
cmp_non_pred <- nearZeroVar(cmpImp) # remove predictors
cmp <- cmpImp[,-cmp_non_pred]
set.seed(8)
trainrows <- createDataPartition(cmp$Yield,
p=0.8,
list=FALSE)
cmp_train <- cmp[trainrows,]
cmp_test <- cmp[-trainrows,]
X_train <- cmp_train[,-1]
Y_train <- cmp_train[,1]
X_test <- cmp_test[,-1]
Y_test <- cmp_test[,1]
# cross validation
ctrl = trainControl(method='cv', number = 10)a) Which nonlinear regression model gives the optimal resampling and test set performance?
Neural Network
rem_pred <- findCorrelation(cor(X_train), cutoff = .75)
X_train_nn <- X_train[,-rem_pred]
X_test_nn <- X_test[,-rem_pred]
nnetGrid <- expand.grid(.decay = c(0, 0.01, .1),
.size = c(1:10),
.bag = FALSE)
set.seed(8) # 8 was set for the previous assignment and should be used here for adequate comparisons
cmp_nn <- train(X_train_nn, Y_train,
method = "avNNet",
tuneGrid = nnetGrid,
trControl = ctrl,
preProc = c("center", "scale"),
linout = TRUE,
trace = FALSE,
MaxNWts = 10 * (ncol(X_train_nn) + 1) + 10 + 1,
maxit = 500)
cmp_nn## Model Averaged Neural Network
##
## 144 samples
## 36 predictor
##
## Pre-processing: centered (36), scaled (36)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 129, 132, 129, 128, 131, 131, ...
## Resampling results across tuning parameters:
##
## decay size RMSE Rsquared MAE
## 0.00 1 1.646689 0.2607029 1.338711
## 0.00 2 2.341428 0.3016326 1.663409
## 0.00 3 2.547852 0.1922623 2.003163
## 0.00 4 2.494055 0.2653553 2.023290
## 0.00 5 1.871920 0.2976837 1.526521
## 0.00 6 2.392597 0.3095554 1.750771
## 0.00 7 2.804210 0.3364546 2.160706
## 0.00 8 4.318392 0.2223018 3.131136
## 0.00 9 4.542755 0.2906573 3.013326
## 0.00 10 8.255174 0.1681032 5.001799
## 0.01 1 1.467398 0.3796687 1.221263
## 0.01 2 1.542072 0.3946523 1.293187
## 0.01 3 2.008597 0.3239218 1.542513
## 0.01 4 1.999885 0.3347167 1.546365
## 0.01 5 1.823309 0.3448246 1.453803
## 0.01 6 1.841038 0.3132353 1.500275
## 0.01 7 1.523368 0.4064366 1.227093
## 0.01 8 1.663864 0.4346829 1.264566
## 0.01 9 1.780080 0.4031975 1.407850
## 0.01 10 2.301473 0.3439729 1.756579
## 0.10 1 1.573102 0.4461353 1.229911
## 0.10 2 1.630502 0.3912080 1.336689
## 0.10 3 1.894497 0.3438132 1.474814
## 0.10 4 2.100041 0.3122634 1.572989
## 0.10 5 2.546931 0.3118386 1.690899
## 0.10 6 1.992375 0.3448676 1.475434
## 0.10 7 2.125840 0.3321779 1.535525
## 0.10 8 2.380304 0.2950136 1.724429
## 0.10 9 2.032025 0.3094133 1.546863
## 0.10 10 2.040718 0.2999304 1.592818
##
## 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 = 1, decay = 0.01 and bag = FALSE.
## decay size bag RMSE Rsquared
## 1 0 1 FALSE 1.646689 0.2607029
## RMSE Rsquared MAE
## 1.1261904 0.6207121 0.8594066
MARS
marsGrid <- expand.grid(.degree = 1:2, .nprune = 2:38)
set.seed(8)
cmp_mars <- train(X_train, Y_train,
method = "earth",
tuneGrid = marsGrid,
trControl = ctrl)
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.
## earth variable importance
##
## only 20 most important variables shown (out of 56)
##
## Overall
## ManufacturingProcess32 100.00
## ManufacturingProcess09 60.16
## ManufacturingProcess13 20.91
## ManufacturingProcess06 0.00
## BiologicalMaterial02 0.00
## BiologicalMaterial08 0.00
## ManufacturingProcess44 0.00
## ManufacturingProcess03 0.00
## ManufacturingProcess40 0.00
## ManufacturingProcess19 0.00
## ManufacturingProcess42 0.00
## ManufacturingProcess31 0.00
## ManufacturingProcess38 0.00
## ManufacturingProcess23 0.00
## ManufacturingProcess27 0.00
## ManufacturingProcess35 0.00
## ManufacturingProcess43 0.00
## ManufacturingProcess28 0.00
## ManufacturingProcess45 0.00
## ManufacturingProcess07 0.00
## degree nprune RMSE Rsquared
## 53 2 17 1.422695 0.5237468
cmp_mars_pred <- predict(cmp_mars, newdata = X_test)
postResample(obs = Y_test, pred=cmp_mars_pred[,1])## RMSE Rsquared MAE
## 1.0774518 0.6474204 0.9030678
SVM
set.seed(8)
cmp_svm <- train(X_train, Y_train,
method = "svmRadial",
preProc = c("center", "scale"),
tuneLength = 14,
trControl = ctrl)
cmp_svm## Support Vector Machines with Radial Basis Function Kernel
##
## 144 samples
## 56 predictor
##
## Pre-processing: centered (56), scaled (56)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 129, 132, 129, 128, 131, 131, ...
## Resampling results across tuning parameters:
##
## C RMSE Rsquared MAE
## 0.25 1.427799 0.4660276 1.1663252
## 0.50 1.333206 0.5171323 1.1058591
## 1.00 1.230212 0.5741459 1.0258995
## 2.00 1.177836 0.5923024 0.9821812
## 4.00 1.157979 0.5886081 0.9593614
## 8.00 1.148464 0.5880650 0.9472594
## 16.00 1.148449 0.5880733 0.9472245
## 32.00 1.148449 0.5880733 0.9472245
## 64.00 1.148449 0.5880733 0.9472245
## 128.00 1.148449 0.5880733 0.9472245
## 256.00 1.148449 0.5880733 0.9472245
## 512.00 1.148449 0.5880733 0.9472245
## 1024.00 1.148449 0.5880733 0.9472245
## 2048.00 1.148449 0.5880733 0.9472245
##
## Tuning parameter 'sigma' was held constant at a value of 0.01553405
## RMSE was used to select the optimal model using the smallest value.
## The final values used for the model were sigma = 0.01553405 and C = 16.
## sigma C RMSE Rsquared
## 4 0.01553405 2 1.177836 0.5923024
## RMSE Rsquared MAE
## 1.0558544 0.6641959 0.8143028
kNN
## integer(0)
set.seed(8)
cmp_knn <- train(X_train, Y_train,
method = "knn",
preProc = c("center", "scale"),
tuneGrid = data.frame(.k = 1:20),
trControl = ctrl)
cmp_knn## k-Nearest Neighbors
##
## 144 samples
## 56 predictor
##
## Pre-processing: centered (56), scaled (56)
## Resampling: Cross-Validated (10 fold)
## Summary of sample sizes: 129, 132, 129, 128, 131, 131, ...
## Resampling results across tuning parameters:
##
## k RMSE Rsquared MAE
## 1 1.491307 0.3943090 1.165705
## 2 1.340997 0.5017895 1.062853
## 3 1.303804 0.5081781 1.061837
## 4 1.302715 0.5132835 1.071034
## 5 1.325938 0.5063409 1.092284
## 6 1.308514 0.5297569 1.061137
## 7 1.309977 0.5449735 1.084252
## 8 1.333167 0.5247293 1.106908
## 9 1.329697 0.5281742 1.106996
## 10 1.317957 0.5443183 1.104274
## 11 1.337913 0.5274922 1.116316
## 12 1.341242 0.5196571 1.123810
## 13 1.333611 0.5280236 1.116561
## 14 1.347327 0.5218331 1.127790
## 15 1.368380 0.5110052 1.138666
## 16 1.371805 0.5043886 1.138327
## 17 1.385625 0.4937404 1.151452
## 18 1.386885 0.4970743 1.149223
## 19 1.388859 0.4933432 1.154776
## 20 1.402640 0.4797332 1.158118
##
## RMSE was used to select the optimal model using the smallest value.
## The final value used for the model was k = 4.
## k RMSE Rsquared
## 4 4 1.302715 0.5132835
## RMSE Rsquared MAE
## 1.3869470 0.4057358 1.0474219
The best model is the support vector machine.
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?
## loess r-squared variable importance
##
## only 20 most important variables shown (out of 56)
##
## Overall
## ManufacturingProcess32 100.00
## ManufacturingProcess13 97.56
## BiologicalMaterial06 93.79
## BiologicalMaterial03 81.77
## ManufacturingProcess17 79.42
## ManufacturingProcess09 78.00
## ManufacturingProcess36 77.08
## BiologicalMaterial12 70.19
## BiologicalMaterial02 69.27
## ManufacturingProcess06 65.84
## ManufacturingProcess31 63.97
## ManufacturingProcess11 52.89
## BiologicalMaterial11 52.06
## BiologicalMaterial04 51.64
## ManufacturingProcess33 51.13
## BiologicalMaterial08 45.81
## ManufacturingProcess29 45.81
## ManufacturingProcess30 45.56
## BiologicalMaterial09 39.03
## ManufacturingProcess27 38.99
For the SVM model when looking at the top 20 most important predictors, manufacturing processes outnumber the biological processes (12 to 8). If we define the most important processes as those where importance is calculated as over 75, manufacturing processes 32, 13, 36, and 17 are most important. Biological Material 6 is also important.
The optimal linear model we selected from the previous assignment as the lasso model, which can be referenced here in question 6.3 part E: (include link to relevant rpubs) The lasso model used only 5 predictors: ManufacturingProcess09 ManufacturingProcess13 ManufacturingProcess17 ManufacturingProcess32 ManufacturingProcess36
Those predictors are of the top 10 predictors for the SVM model, but the two models differ in that they rank these processes in different orders of importance.
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?
For this question, we’ll just take the top 6 predictors for the SVM model.
## loess r-squared variable importance
##
## only 20 most important variables shown (out of 56)
##
## Overall
## ManufacturingProcess32 100.00
## ManufacturingProcess13 97.56
## BiologicalMaterial06 93.79
## BiologicalMaterial03 81.77
## ManufacturingProcess17 79.42
## ManufacturingProcess09 78.00
## ManufacturingProcess36 77.08
## BiologicalMaterial12 70.19
## BiologicalMaterial02 69.27
## ManufacturingProcess06 65.84
## ManufacturingProcess31 63.97
## ManufacturingProcess11 52.89
## BiologicalMaterial11 52.06
## BiologicalMaterial04 51.64
## ManufacturingProcess33 51.13
## BiologicalMaterial08 45.81
## ManufacturingProcess29 45.81
## ManufacturingProcess30 45.56
## BiologicalMaterial09 39.03
## ManufacturingProcess27 38.99
imp_var <- c('ManufacturingProcess32','ManufacturingProcess13',
'BiologicalMaterial06','ManufacturingProcess36',
'ManufacturingProcess17','BiologicalMaterial03')
featurePlot(X_train[,imp_var], Y_train)From the plots above, we can see that each manufacturing process/biological material has different correlations with regard to the yield. Some have negative and others have positive correlation. If the idea is to increase yield, I would assume that and increase/enhancement of that material/process that exhibits a positive correlation would be beneficial. However, I don’t know how the influence of one process/material might affect the other as I doubt it’s as simple as increasing/decreasing one process/material. Each process/material is probably important and even essential to create the final product. I would imagine that the yield may benefit probably from slight adjustments made on these predictors depending on their pos/neg correlations.
## [,1]
## ManufacturingProcess32 0.5964897
## ManufacturingProcess13 -0.5352837
## BiologicalMaterial06 0.4776953
## ManufacturingProcess36 -0.5236767
## ManufacturingProcess17 -0.4522273
## BiologicalMaterial03 0.4544441