forked from jfbratt/WebScraping
-
Notifications
You must be signed in to change notification settings - Fork 3
/
classifier.R
36 lines (28 loc) · 956 Bytes
/
classifier.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
library(caret)
library(mlbench)
library(magrittr)
data(Sonar)
set.seed(107)
in_train <- createDataPartition(y = Sonar$Class, p = 0.75, list = FALSE)
training <- Sonar[in_train, ]
testing <- Sonar[-in_train, ]
ctrl <- trainControl(method = "repeatedcv",
repeats = 3,
classProbs = TRUE,
summaryFunction = twoClassSummary
)
# See names(getModelInfo()) for potential models
# or http://topepo.github.io/caret/bytag.html
model <- train(Class ~ .,
data = training,
method = "pls",
preProc = c("center", "scale"),
trControl = ctrl,
metric = "ROC",
tuneLength = 15
)
model
plot(model)
predictions <- predict(model, newdata = testing)
predictions_prob <- predict(model, newdata = testing, type = "prob")
accuracy <- confusionMatrix(data = predictions, testing$Class)