Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to graph theory

Authors: Douglas B. West

2nd edition

131437372, 978-0131437371

More Books

Students also viewed these Mathematics questions