-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdhfr-classification-deploy.R
63 lines (44 loc) · 1.82 KB
/
dhfr-classification-deploy.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
####################################
# Data Professor #
# http://youtube.com/dataprofessor #
# http://github.com/dataprofessor #
####################################
# Importing libraries
library(datasets) # Contains several data sets
library(caret) # Package for machine learning algorithms / CARET stands for Classification And REgression Training
# Importing the dhfr data set
data(dhfr)
# Check to see if there are missing data?
sum(is.na(dhfr))
# To achieve reproducible model; set the random seed number
set.seed(100)
# Performs stratified random split of the data set
TrainingIndex <- createDataPartition(dhfr$Y, p=0.8, list = FALSE)
TrainingSet <- dhfr[TrainingIndex,] # Training Set
TestingSet <- dhfr[-TrainingIndex,] # Test Set
###############################
# SVM model (polynomial kernel)
# Build Training model
Model <- train(Y ~ ., data = TrainingSet,
method = "svmPoly",
na.action = na.omit,
preProcess=c("scale","center"),
trControl= trainControl(method="none"),
tuneGrid = data.frame(degree=1,scale=1,C=1)
)
# Save model to RDS file
saveRDS(Model, "Model.rds")
# Read the model from RDS file
read.Model <- readRDS("Model.rds")
# Apply model for prediction
Model.training <-predict(read.Model, TrainingSet) # Apply model to make prediction on Training set
Model.testing <-predict(read.Model, TestingSet) # Apply model to make prediction on Testing set
# Model performance (Displays confusion matrix and statistics)
Model.training.confusion <-confusionMatrix(Model.training, TrainingSet$Y)
Model.testing.confusion <-confusionMatrix(Model.testing, TestingSet$Y)
print(Model.training.confusion)
print(Model.testing.confusion)
# Feature importance
Importance <- varImp(Model)
plot(Importance, top = 25)
plot(Importance, col = "red")