# load in package we'll use
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Read in the test and train data
setwd("/Users/apple/Desktop/361 project")
getwd()
## [1] "/Users/apple/Desktop/361 project"
train <- read.table('train.csv',header = T,sep=",")
test <- read.table('test.csv',header = T,sep=",")
#fit our model using all predictors
model <- lm(medv~ ., data = train)
# use our model to make predictions
predicted_medv <- predict(model, newdata = test)
# look at the first few predicted cost to ensure we have something sensible.
head(predicted_medv)
## 1 2 3 4 5 6
## 23.161111 22.527861 7.620764 15.538135 9.100576 16.819420
# create a dataframe with our results
my_submission <-tibble('id' = test$id, 'medv' = predicted_medv)
# save our file
write_csv(my_submission, 'submission.csv')
###Cp Criterion