The Carseats data that accompanies library(ISLR2) contains sales of child car seats at 400 different stores. To
Question:
The Carseats data that accompanies library(ISLR2) contains sales of child car seats at 400 different stores. To access the data, load the 'ISLR2' package and call the `Carseats` data as illustrated below.
library(ISLR2) data(Carseats)
Use simple random sampling to split the data into a train and test sample with 80% of the data in the train sample. Use a seed of 617. Compute the average price in the train sample and in the test sample. What is the absolute difference in average price between the train and test samples?
Now, use stratified sampling to split the "Carseats" data into a train and test sample with 80% of the data in the train sample. Do the sampling in such a way that the distribution of "price" is approximately equal in both samples. Use a seed of 617 and utilize "createDataPartition", for the split and set groups to 10. Compute the average price in the train sample and in the test sample. What is the absolute difference in average price between the train and test samples? Since you are asked absolute difference, if the difference is negative, drop the negative sign.