Today, I did computing of Chapter 6.
library(AppliedPredictiveModeling)
data(solubility)
ls(pattern = "^solT")
set.seed(2)
sample(names(solTrainX), 8)
# 1. ordianry linear regression
trainingdata=solTrainXtrans
#add the solubility outcome
trainingdata$solubility=solTrainY
lmfitallpredictors=lm(solubility~., data=trainingdata)
summary(lmfitallpredictors)
lmpred1=predict(lmfitallpredictors, solTestXtrans)
head(lmpred1)
nrow(solTestXtrans)
lmvalues1=data.frame(obs=solTestY, pred=lmpred1)
library(caret)
defaultSummary(lmvalues1)
library(MASS)
rlmfitallpredictors=rlm(solubility~., data=trainingdata)
summary(rlmfitallpredictors)
rlmpred1=predict(rlmfitallpredictors, solTestXtrans)
head(rlmpred1)
rlmvalues1=data.frame(obs=solTestY, pred=rlmpred1)
defaultSummary(rlmvalues1)
#generate a resampling estimate of performance
ctr1=trainControl(method = "cv", number = 10)
set.seed(100)
lmfit1=train(x=solTrainXtrans, y=solTrainY, method = "lm", trControl = ctr1)
xyplot(solTrainY~predict(lmfit1),
type=c("p","g"), xlab = "Predicted", ylab = "Observed")
xyplot(resid(lmfit1)~predict(lmfit1),
type=c("p","g"), xlab = "Predicted", ylab = "Residuals")
#resid: generate the model residuals; predict: return the predicted values
I will try to finish computing at the weekend.
No comments:
Post a Comment