I did started to use Caret, and I will continue using it, so I have to try a lot of things in R to become familiar with it.
In Caret the are a data set (data=tecator) from a Tecator instrument for meat analysis, working in transmitance and in the range from 850 to 1050 nm with a total of 100 data points.
The parameters are Moisture, Fat and Protein. You can play around with this data to become familiar with Caret, so I try to create a quick regression with PCR.
Caret let us prepare the Training and Testing Data in a random order and to train the model with several kinds of cross validations. So I wrote some code apart from the help I found in the available Caret Documentation.
colnames(absorp) <- paste("x", 1:ncol(absorp))
## We will model the protein content data
trainMeats <- createDataPartition(endpoints[,3], p = 3/4)
absorpTrain <- absorp[trainMeats[], ]
proteinTrain <- endpoints[trainMeats[], 3]
absorpTest <- absorp[-trainMeats[], ]
proteinTest <- endpoints[-trainMeats[], 3]
model <- train(proteinTrain~.,data=trainData, method = "pcr",
scale = TRUE,
trControl = trainControl("cv", number = 10),
tuneLength = 10)
predictions <- predict(model,testData)
With this code we get plots and statistics. This is my first step into Caret, where I would like to go really deep into. So I hope to write more posts about this subjet.