7.2 7.5
#loaded relevant libraries
library(AppliedPredictiveModeling)
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(caTools)
library(elasticnet)
## Loading required package: lars
## Loaded lars 1.3
library(lars)
library(MASS)
library(pls)
##
## Attaching package: 'pls'
## The following object is masked from 'package:caret':
##
## R2
## The following object is masked from 'package:stats':
##
## loadings
library(stats)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::lift() masks caret::lift()
## ✖ dplyr::select() masks MASS::select()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(fpp3)
## Registered S3 method overwritten by 'tsibble':
## method from
## as_tibble.grouped_df dplyr
## ── Attaching packages ──────────────────────────────────────────── fpp3 1.0.1 ──
## ✔ tsibble 1.1.5 ✔ feasts 0.4.1
## ✔ tsibbledata 0.4.1 ✔ fable 0.4.0
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## ✖ lubridate::date() masks base::date()
## ✖ dplyr::filter() masks stats::filter()
## ✖ tsibble::intersect() masks base::intersect()
## ✖ tsibble::interval() masks lubridate::interval()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::lift() masks caret::lift()
## ✖ fabletools::MAE() masks caret::MAE()
## ✖ fabletools::RMSE() masks caret::RMSE()
## ✖ dplyr::select() masks MASS::select()
## ✖ tsibble::setdiff() masks base::setdiff()
## ✖ tsibble::union() masks base::union()
library(fable)
library(ggplot2)
library(e1071)
##
## Attaching package: 'e1071'
##
## The following object is masked from 'package:fabletools':
##
## interpolate
library(lattice)
library(corrplot)
## corrplot 0.95 loaded
##
## Attaching package: 'corrplot'
##
## The following object is masked from 'package:pls':
##
## corrplot
library(VIM)
## Loading required package: colorspace
## Loading required package: grid
## VIM is ready to use.
##
## Suggestions and bug-reports can be submitted at: https://github.com/statistikat/VIM/issues
##
## Attaching package: 'VIM'
##
## The following object is masked from 'package:datasets':
##
## sleep
library(mlbench)
library(kernlab)
##
## Attaching package: 'kernlab'
##
## The following object is masked from 'package:purrr':
##
## cross
##
## The following object is masked from 'package:ggplot2':
##
## alpha
library(earth)
## Loading required package: Formula
## Loading required package: plotmo
## Loading required package: plotrix
library(ggplot2)
models from chapter selected: k-nearest neighbors, SVM, neural network, and MARS
#set seed for consistancy
set.seed(200)
#training data generated
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 column 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 vecotr 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)
a view of the predictors.
Tune several models on this data for example: KNN
set.seed(200) #first try the kNN model
knnModel <- train(x=trainingData$x,
y=trainingData$y,
method= "knn",
preProc = c("center", "scale"),
tuneLength = 10)
summary(knnModel)
## Length Class Mode
## learn 2 -none- list
## k 1 -none- numeric
## theDots 0 -none- list
## xNames 10 -none- character
## problemType 1 -none- character
## tuneValue 1 data.frame list
## obsLevels 1 -none- logical
## param 0 -none- list
knnPred <- predict(knnModel, newdata= testData$x)
#the function postResample can be used to geth the test set performance values
postResample(pred= knnPred, obs=testData$y)
## RMSE Rsquared MAE
## 3.1750657 0.6785946 2.5443169
#models to try: MARS, SVM, neural networks
knn is later shown to have the lowest Rsquared and highest RMSE.
MARS Multivariate Adaptive Regression Splines
set.seed(200)
marsFit <- earth(trainingData$x, trainingData$y) #MARS nominal forward pass and pruning step
#marsFit
summary(marsFit)
## Call: earth(x=trainingData$x, y=trainingData$y)
##
## coefficients
## (Intercept) 18.451984
## h(0.621722-X1) -11.074396
## h(0.601063-X2) -10.744225
## h(X3-0.281766) 20.607853
## h(0.447442-X3) 17.880232
## h(X3-0.447442) -23.282007
## h(X3-0.636458) 15.150350
## h(0.734892-X4) -10.027487
## h(X4-0.734892) 9.092045
## h(0.850094-X5) -4.723407
## h(X5-0.850094) 10.832932
## h(X6-0.361791) -1.956821
##
## Selected 12 of 18 terms, and 6 of 10 predictors
## Termination condition: Reached nk 21
## Importance: X1, X4, X2, X5, X3, X6, X7-unused, X8-unused, X9-unused, ...
## Number of terms at each degree of interaction: 1 11 (additive model)
## GCV 2.540556 RSS 397.9654 GRSq 0.8968524 RSq 0.9183982
#make the model predict the test data
mars_pred <- predict(marsFit, newdata= testData$x)
#how well does it perform?
postResample(pred = mars_pred, obs = testData$y)
## RMSE Rsquared MAE
## 1.8136467 0.8677298 1.3911836
uses 6 out of 10 predictors in the model
SVM model Support Vector Machines
set.seed(200)
svmTuned<-train(x = trainingData$x, y = trainingData$y ,
method = "svmRadial", #for complex, unknown, or non linear data
preProc = c("center", "scale"),
tuneLength = 10, #ten predictors
trControl = trainControl(method = "cv"))
#svmTuned
summary(svmTuned)
## Length Class Mode
## 1 ksvm S4
#predict and assess
svm_pred <- predict(svmTuned, newdata= testData$x)
postResample(pred = svm_pred, obs = testData$y)
## RMSE Rsquared MAE
## 2.0541197 0.8290353 1.5586411
Neural Network
reducing the number of predictors by finding the predictors that are well correlated.
#using correlation threshold to remove pair wise variables that have too high of a correlation avNNet requires that the predictors have been standardized to be on the same scale. can be automatically scaled
set.seed(200)
tooHigh <- findCorrelation(cor(trainingData$x), cutoff = 0.75)
trainXnnet <- trainingData$x[,-tooHigh]
testXnnet <- testData$x[, -tooHigh]
ctrl <- trainControl(
method = "repeatedcv", # Use repeated cross-validation
number = 10, # Number of folds
repeats = 3, # Number of times to repeat
savePredictions = "final", # Save final predictions
classProbs = TRUE # Needed for classification models
)
nnetgrid <- expand.grid(.decay=c(0,.01,.1),
.size = c(1:10),
.bag=FALSE)
nnetTune <- train(trainingData$x, trainingData$y,
method= "avNNet",
tuneGrid = nnetgrid,
trControl = ctrl,
preProc = c("center", "scale"),
linout = TRUE,
trace = FALSE,
MaxNWts = 1000 *(ncol(trainXnnet)+1)+10+1,
maxit = 500
)
## Warning in train.default(trainingData$x, trainingData$y, method = "avNNet", :
## cannnot compute class probabilities for regression
## Warning: executing %dopar% sequentially: no parallel backend registered
#nnetTune
summary(nnetTune)
## Length Class Mode
## model 5 -none- list
## repeats 1 -none- numeric
## bag 1 -none- logical
## seeds 5 -none- numeric
## names 10 -none- character
## terms 3 terms call
## coefnames 10 -none- character
## xlevels 0 -none- list
## xNames 10 -none- character
## problemType 1 -none- character
## tuneValue 3 data.frame list
## obsLevels 1 -none- logical
## param 4 -none- list
nnet_pred <- predict(nnetTune, newdata= testData$x)
postResample(pred = nnet_pred, obs = testData$y)
## RMSE Rsquared MAE
## 1.9536240 0.8507269 1.4904748
all_results<- rbind(
knn = postResample(pred= knnPred, obs=testData$y),
nnet = postResample(pred = nnet_pred, obs = testData$y),
mars = postResample(pred = mars_pred, obs = testData$y),
svm = postResample(pred = svm_pred, obs = testData$y)
)
# Convert to a data frame
results <- as.data.frame(all_results)
# see RMSE and R^2 for chapter models
print(results)
## RMSE Rsquared MAE
## knn 3.175066 0.6785946 2.544317
## nnet 1.953624 0.8507269 1.490475
## mars 1.813647 0.8677298 1.391184
## svm 2.054120 0.8290353 1.558641
MARS overall had the lowest RMSE and the highest R^2. Second best model is the neutral network with Knn being the worst.
Does MARS select the informative predictors? (x1-x5) MARS selected the informative x1, x2,x3,x4,x5 but also added x6.
##7.5
loaded the data from 6.3 and imputate and split and pre process. copied from assignment 7. then fit nonlinear regression models
data("ChemicalManufacturingProcess")
#book mentioned process predictors, which was not found, so process predictors was made from chemical manufacturing process
apropos('processPredictors')
## character(0)
#how many na values?
sum(is.na(ChemicalManufacturingProcess))
## [1] 106
Impute the predictors the impute package is no longer available on CRAN used VIM instead
#imputed with K nearest neighbors set to 5.
imputeCMP <- kNN(ChemicalManufacturingProcess, k = 5)
#imputation removed nas
sum(is.na(imputeCMP))
## [1] 0
imputed with nearest 5 neighbors
#created processPredictors since it does not seem to be available after loading the data
#removed the output and kept the predictors
processPredictors <- select(imputeCMP, -"Yield")
set.seed(987654321)
#splitting the permeability data into a 75% training and a 25% test set
#select indices to use for extracting the training data
train_indice <- createDataPartition(imputeCMP$Yield, p = 0.75, list = FALSE)
# use the indices to select the data
train_cmp <- imputeCMP[train_indice, ] # use as y train_cmp$Yield
test_cmp <- imputeCMP[-train_indice, ] # use as y test_cmp$yield for test
train_cmpp <- processPredictors[train_indice, ] #use as training
test_cmpp <- processPredictors[-train_indice, ] #use as x for test
starting with KNN on the chemical processing
set.seed(200) #first try the kNN model
knnModelc <- train(x=train_cmpp,
y=train_cmp$Yield,
method= "knn",
preProc = c("center", "scale"),
tuneLength = 11)
## 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
summary(knnModelc)
## Length Class Mode
## learn 2 -none- list
## k 1 -none- numeric
## theDots 0 -none- list
## xNames 115 -none- character
## problemType 1 -none- character
## tuneValue 1 data.frame list
## obsLevels 1 -none- logical
## param 0 -none- list
knnPredc <- predict(knnModelc, newdata= test_cmpp)
#the function postResample can be used to get the test set performance values
postResample(pred= knnPredc, obs=test_cmp$Yield)
## RMSE Rsquared MAE
## 1.3259062 0.4534155 1.1184141
#models to try: MARS, SVM, neural networks
knn model performed very poorly on the chemical manufacturing to predict data set.
MARS Multivariate Adaptive Regression Splines
set.seed(200)
marsFitc <- earth(train_cmpp, train_cmp$Yield) #MARS nominal forward pass and pruning step
#marsFit
summary(marsFitc)
## Call: earth(x=train_cmpp, y=train_cmp$Yield)
##
## coefficients
## (Intercept) 40.085944
## h(70.01-BiologicalMaterial03) -0.151157
## h(33.9-ManufacturingProcess13) 1.444267
## h(ManufacturingProcess13-33.9) -0.463041
## h(ManufacturingProcess21- -0.9) -0.439770
## h(10.6-ManufacturingProcess28) 0.080664
## h(ManufacturingProcess28-10.6) 2.402941
## h(ManufacturingProcess31-71.6) -1.851969
## h(155-ManufacturingProcess32) -0.278330
## h(ManufacturingProcess32-155) 0.293364
## h(ManufacturingProcess32-163) -0.362139
## h(62-ManufacturingProcess33) 0.634892
## h(1-ManufacturingProcess37) -0.900714
## h(ManufacturingProcess37-1) -0.775781
## h(7.2-ManufacturingProcess39) -0.165888
## h(ManufacturingProcess39-7.2) -3.851496
##
## Selected 16 of 22 terms, and 9 of 115 predictors
## Termination condition: RSq changed by less than 0.001 at 22 terms
## Importance: ManufacturingProcess32, ManufacturingProcess13, ...
## Number of terms at each degree of interaction: 1 15 (additive model)
## GCV 0.9663837 RSS 74.68243 GRSq 0.72737 RSq 0.8379408
#make the model predict the test data
mars_predc <- predict(marsFitc, newdata= test_cmpp)
#how well does it perform?
postResample(pred = mars_predc, obs = test_cmp$Yield)
## RMSE Rsquared MAE
## 1.2605085 0.5445389 1.0208054
uses 16 out of 388 predictors in the model using 57 terms The MATS model performed better than the knn
SVM model Support Vector Machines
set.seed(200)
svmTunedc<-train(x = train_cmpp, y = train_cmp$Yield ,
method = "svmRadial", #for complex, unknown, or non linear data
preProc = c("center", "scale"),
tuneLength = 10, # parameters
trControl = trainControl(method = "cv"))
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
## Warning in .local(x, ...): Variable(s) `' constant. Cannot scale data.
#svmTuned
summary(svmTunedc)
## Length Class Mode
## 1 ksvm S4
#predict and assess
svm_predc <- predict(svmTunedc, newdata= test_cmpp)
postResample(pred = svm_predc, obs = test_cmp$Yield)
## RMSE Rsquared MAE
## 1.289762 0.469700 1.063210
best model so far is the svm judging from the RMSE Rsquared. Neural Network
reducing the number of predictors by finding the predictors that are well correlated.
set.seed(200)
#training neural network
ctrlc <- trainControl(
method = "cv", # Use repeated cross-validation
number = 10, # number of folds
savePredictions = "final", # save only final
classProbs = TRUE , # classification
allowParallel = FALSE #helps avoid computing issues
)
nnetgridc <- expand.grid(.decay=c(0,.01,.1), #textbook
.size = c(1:10),
.bag=FALSE)
nnetTunec <- train(x = train_cmpp, y= train_cmp$Yield, #train neural network
method= "avNNet",
tuneGrid = nnetgridc,
trControl = ctrlc,
preProc = c("center", "scale"),
linout = TRUE,
trace = FALSE,
MaxNWts = (ncol(train_cmpp)+1)+10+1, #manually adjusted
maxit = 500
)
## Warning in train.default(x = train_cmpp, y = train_cmp$Yield, method =
## "avNNet", : cannnot compute class probabilities for regression
## Warning: model fit failed for Fold01: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold01: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold01: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold01: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold01: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold01: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold01: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold02: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold02: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold02: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold02: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold02: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold02: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold03: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold03: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold03: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold03: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold03: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold03: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold04: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold04: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold04: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold04: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold04: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold04: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold05: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold05: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold05: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold05: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold05: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold05: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold06: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold06: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold06: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold06: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold06: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold06: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold07: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold07: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold07: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold07: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold07: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold07: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold08: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold08: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold08: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold08: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold08: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold08: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold09: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold09: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold09: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold09: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold09: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold09: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 2, bag=FALSE Error in { : task 1 failed - "too many (235) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 3, bag=FALSE Error in { : task 1 failed - "too many (352) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 4, bag=FALSE Error in { : task 1 failed - "too many (469) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 5, bag=FALSE Error in { : task 1 failed - "too many (586) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 6, bag=FALSE Error in { : task 1 failed - "too many (703) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 7, bag=FALSE Error in { : task 1 failed - "too many (820) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 8, bag=FALSE Error in { : task 1 failed - "too many (937) weights"
## Warning: model fit failed for Fold10: decay=0.00, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold10: decay=0.01, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold10: decay=0.10, size= 9, bag=FALSE Error in { : task 1 failed - "too many (1054) weights"
## Warning: model fit failed for Fold10: decay=0.00, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold10: decay=0.01, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning: model fit failed for Fold10: decay=0.10, size=10, bag=FALSE Error in { : task 1 failed - "too many (1171) weights"
## Warning in nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo,
## : There were missing values in resampled performance measures.
## Warning in train.default(x = train_cmpp, y = train_cmp$Yield, method =
## "avNNet", : missing values found in aggregated results
#nnetTune
summary(nnetTunec)
## Length Class Mode
## model 5 -none- list
## repeats 1 -none- numeric
## bag 1 -none- logical
## seeds 5 -none- numeric
## names 115 -none- character
## terms 3 terms call
## coefnames 115 -none- character
## contrasts 58 -none- list
## xlevels 0 -none- list
## xNames 115 -none- character
## problemType 1 -none- character
## tuneValue 3 data.frame list
## obsLevels 1 -none- logical
## param 4 -none- list
nnet_predc <- predict(nnetTunec, newdata= test_cmpp)
postResample(pred = nnet_predc, obs = test_cmp$Yield)
## RMSE Rsquared MAE
## 1.5218135 0.2717869 1.2780401
chemical_results<- rbind(
knnc = postResample(pred= knnPredc, obs= test_cmp$Yield),
nnetc = postResample(pred = nnet_predc, obs = test_cmp$Yield),
marsc = postResample(pred = mars_predc, obs = test_cmp$Yield),
svmc = postResample(pred = svm_predc, obs = test_cmp$Yield)
)
# Convert to a data frame
chemicalresults <- as.data.frame(chemical_results)
# see RMSE and R^2 for chapter models
print(chemicalresults)
## RMSE Rsquared MAE
## knnc 1.325906 0.4534155 1.118414
## nnetc 1.521813 0.2717869 1.278040
## marsc 1.260508 0.5445389 1.020805
## svmc 1.289762 0.4697000 1.063210
MARS gives the best overall model performance for the test set.
Important predictors
# the variables by importance
evimp(marsFitc) #used to show importance of predictors earth MARS model
## nsubsets gcv rss
## ManufacturingProcess32 15 100.0 100.0
## ManufacturingProcess13 14 68.6 72.0
## ManufacturingProcess21 11 37.9 45.1
## ManufacturingProcess28 11 37.9 45.1
## ManufacturingProcess33 9 26.3 35.3
## BiologicalMaterial03 7 18.0 28.1
## ManufacturingProcess39 5 16.3 23.8
## ManufacturingProcess31 4 14.6 21.2
## ManufacturingProcess37 2 2.5 12.6
Which predictors are most important? Manufacturing Processes dominate the Yield for the MARS model. only 1 biological material shows up in the top 9. The rest are Manufacturing processes.
from assignment 7 the best found Latent Variable model Overall
ManufacturingProcess13 92.4708233
ManufacturingProcess36 91.3473135
ManufacturingProcess09 84.3158605
ManufacturingProcess17 81.7846579
BiologicalMaterial02 70.6214136
BiologicalMaterial06 67.8114973
BiologicalMaterial03 67.0055935
BiologicalMaterial08 63.7959965
ManufacturingProcess06 63.2881421
both models agree that manufacturing process32 contributes most to the yield. They also agree that Manufacturing Process 13 is second most important. those are the only two manufacturing processes they agree upon. only biological material shared between the two biological material 3 using multiple models and checking the important predictors between them can help confirm their importance.
explore the predictor relationships to yield for the top model
# partial dependence plots
plot(marsFitc, which = 1:9)
# top predictors from MARS model
top_predict <- c("ManufacturingProcess32", "ManufacturingProcess13","ManufacturingProcess36","ManufacturingProcess21","ManufacturingProcess28","ManufacturingProcess33","BiologicalMaterial03")
predictor = "ManufacturingProcess32" #initiate
#show each predictor vs yield
for (predictor in top_predict) {
plot(train_cmpp[[predictor]], train_cmp$Yield,
xlab = predictor, ylab = "Yield",
main = paste("Yield vs.", predictor),
col = "blue")
abline(lm(train_cmp$Yield ~ train_cmpp[[predictor]]), col = "red") # Add linear fit
}
There is a clear trend for Manufacturing Processes: 32 13 36. 21 and 28
trend is not clear. for the biological material 03 there does appear to
be a trend as well. process 13 and 36 have an inverse relationship with
yield. 32 33 show a positive direct relationship. biological material 3
also has a positive direct relationship with yield. Again for process 21
and 28 there is no obvious connection to the yield since the data is
spread wide across multiple yeild and value of process. from looking at
these plots it becomes a bit more clear why the majority of these would
be selected as important more than others. a majority of them have clear
trends.