Question: Write R-code that reads from the downloaded file, and create and use your model that helps to answer the question you stated above. (e.g logistic
Write R-code that reads from the downloaded file, and create and use your model that helps to answer the question you stated above. (e.g logistic regression, or multiple linear regression, etc. ). You will also have to use training/test data set and cross validation for your analysis. Also, do an error analysis of the goodness of your model and comment on that.
I am using the dataset "mtcars". I am trying to determine the relationship that "disp", "hp", and "wt" have on the "mpg"
the formula i used for the model was fit <- lm(mpg~disp+wt+hp, data=mtcars)
I really need writing the code for the training/test data set and cross validation and error analysis.
basically all I have so far is:
>print(mtcars)
>fit <- lm(mpg~disp+wt+hp, data=mtcars)
>summary(fit)
> sample <- sample.int(n=nrow(mtcars), size=floor(.50*nrow(mtcars)), replace = F)
> train <- mtcars[sample, ]
> test <- mtcars[-sample, ]
> score = list()
> LOOCV_function=function(x,label){
+ for(i in 1:nrow(x)){
+ traiing = x[-i,]
+ model =
+ validation = x[i,]
+ pred=predict(model, validation[,setdiff(names(validation),label)])
+ score[[i]] = rmse(pred, validation[[label]])
+ }
+ return(unlist(score))
+ }
>
> library(caret)
Loading required package: lattice
Loading required package: ggplot2
> data(mtcars)
> set.seed(42)
>model <- train(mpg~disp+hp+wt, mtcars,
+ method = "lm",
+ trControl = trainControl(
+ method = "cv", number = 10,
+ verboseIter = TRUE
+ printdat
+ )
but i dont think its right
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
