Question: Using the codes I provided below provide a comment on Cross Validation and Test & training explaining the analysis used, and why using this analysis
Using the codes I provided below provide a comment on Cross Validation and Test & training explaining the analysis used, and why using this analysis then based on that analysis explain what should be the best model you suggest for prediction and why. And what limitations you found using this analysis .
``{r}
library(carData)
library(MASS)
library(ISLR)
library(car)
library(leaps)
```
```{r}
Salaries1<-Salaries
str(Salaries1)
attach(Salaries1)
```
### Train & test data
```{r}
set.seed(101)
# Now selecting 80% data as sample from total 'n' rows of the data
sample <- sample.int(n=nrow(Salaries1), size = floor(.80 * nrow(Salaries1)), replace = F)
train <- Salaries1[sample,]
test <- Salaries1[-sample,]
```
### Cross validation
```{r}
library(caret)
# Define training control
set.seed(123)
# Here CV stands for cross validation with 10 cross fold validation occurs
train.control<- trainControl(method = "cv", number =10)
# Train the model
model <- train(salary~., data= Salaries1, method = "lm",
trControl = train.control)
# Summarize the results
print(model)
```
```{r}
# Define training control
train.control<- trainControl(method = "LOOCV", number =10)
# Train the model
model <- train(salary~., data= Salaries1, method = "lm",
trControl = train.control)
# Summarize the results
print(model)
```
```{r}
set.seed(123)
train.control <- trainControl(method = "repeatedcv",
number = 10, repeats = 3)
# Train the model
model <- train(salary ~., data = Salaries1, method = "lm",
trControl = train.control)
# Summarize the results
print(model)
```
```{r}
model$finalModel
```
```{r}
model$resample
```
```{r}
sd(model$resample$Rsquared)
```
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
