forked from dzlab/Practical-Machine-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path010_Carpet Package.R
36 lines (27 loc) · 873 Bytes
/
010_Carpet Package.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
install.packages("caret")
install.packages("e1071")
library(caret)
library(kernlab)
data(spam)
# Data splitting with createDataPartition()
inTrain <- createDataPartition(y=spam$type, p=0.75, list=FALSE)
training <- spam[inTrain, ]
testing <- spam[-inTrain, ]
dim(training)
# Fit a model with train() from 'caret'
set.seed(32343)
modelFit <- train(type ~., data=training, method="glm") # generalized linear model
modelFit
# final model
modelFit$finalModel
# prediction
predictions <- predict(modelFit, newdata=testing)
predictions
# confusion Matrix
confusionMatrix(predictions, testing$type)
# Further information
# Caret tutorials:
# - http://www.edii.uclm.es/~useR-2013/Tutorials/kuhn/user_caret_2up.pdf
# - http://cran.r-project.org/web/packages/caret/vignettes/caret.pdf
# A paper introducing the caret package
# - http://www.jstatsoft.org/v28/i05/paper