library(mlbench) # Contains several benchmark data sets (especially the Boston Housing dataset) library(caret) # Package for machine learning algorithms / CARET stands for Classification And REgression Training
data(BostonHousing)
head(BostonHousing)
sum(is.na(BostonHousing))
set.seed(100)
TrainingIndex <- createDataPartition(BostonHousing$medv, p=0.8, list = FALSE) TrainingSet <- BostonHousing[TrainingIndex,] # Training Set TestingSet <- BostonHousing[-TrainingIndex,] # Test Set
###############################
Model <- train(medv ~ ., data = TrainingSet, method = "lm", na.action = na.omit, preProcess=c("scale","center"), trControl= trainControl(method="none") )
Model.training <-predict(Model, TrainingSet) # Apply model to make prediction on Training set Model.testing <-predict(Model, TestingSet) # Apply model to make prediction on Testing set
plot(TrainingSet$medv,Model.training, col = "blue" )
plot(TestingSet$medv,Model.testing, col = "blue" )