-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathDeep Learning Multiclass Classification
67 lines (54 loc) · 1.37 KB
/
Deep Learning Multiclass Classification
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
64
65
66
67
# Install packages
library(---)
install_keras()
# Read data
data <- read.csv(---, header = T)
str(data)
# Change to matrix
data <- as.matrix(data)
dimnames(data) <- NULL
# Normalize
data[, 1:21] <- normalize(---)
data[,22] <- as.numeric(data[,22]) -1
summary(data)
# Data partition
set.seed(1234)
ind <- sample(2, nrow(data), replace = T, prob = c(---, ---))
training <- data[---]
test <- data[---]
trainingtarget <- data[ind==1, 22]
testtarget <- data[ind==2, 22]
# One Hot Encoding
trainLabels <- to_categorical(trainingtarget)
testLabels <- ---(testtarget)
print(testLabels)
# Create sequential model
model <- keras_model_sequential()
model %>%
layer_dense(units=8, activation = ---, input_shape = ---) %>%
---(units = 3, activation = ---)
summary(model)
# Compile
model %>%
compile(loss = ---,
optimizer = ---,
metrics = ---)
# Fit model
history <- model %>%
fit(training,
trainLabels,
epoch = 200,
batch_size = 32,
validation_split = 0.2)
plot(history)
# Evaluate model with test data
model1 <- model %>%
evaluate(test, testLabels)
# Prediction & confusion matrix - test data
prob <- model %>%
---(test)
pred <- model %>%
---(test)
table1 <- table(Predicted = pred, Actual = testtarget)
cbind(prob, pred, testtarget)
# Fine-tune model