Skip to content

Commit 36504ac

Browse files
authored
Create Deep Learning Multiclass Classification
1 parent eb87b85 commit 36504ac

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Install packages
2+
library(---)
3+
install_keras()
4+
5+
# Read data
6+
data <- read.csv(---, header = T)
7+
str(data)
8+
9+
# Change to matrix
10+
data <- as.matrix(data)
11+
dimnames(data) <- NULL
12+
13+
# Normalize
14+
data[, 1:21] <- normalize(---)
15+
data[,22] <- as.numeric(data[,22]) -1
16+
summary(data)
17+
18+
# Data partition
19+
set.seed(1234)
20+
ind <- sample(2, nrow(data), replace = T, prob = c(---, ---))
21+
training <- data[---]
22+
test <- data[---]
23+
trainingtarget <- data[ind==1, 22]
24+
testtarget <- data[ind==2, 22]
25+
26+
# One Hot Encoding
27+
trainLabels <- to_categorical(trainingtarget)
28+
testLabels <- ---(testtarget)
29+
print(testLabels)
30+
31+
# Create sequential model
32+
model <- keras_model_sequential()
33+
model %>%
34+
layer_dense(units=8, activation = ---, input_shape = ---) %>%
35+
---(units = 3, activation = ---)
36+
summary(model)
37+
38+
# Compile
39+
model %>%
40+
compile(loss = ---,
41+
optimizer = ---,
42+
metrics = ---)
43+
44+
# Fit model
45+
history <- model %>%
46+
fit(training,
47+
trainLabels,
48+
epoch = 200,
49+
batch_size = 32,
50+
validation_split = 0.2)
51+
plot(history)
52+
53+
# Evaluate model with test data
54+
model1 <- model %>%
55+
evaluate(test, testLabels)
56+
57+
# Prediction & confusion matrix - test data
58+
prob <- model %>%
59+
---(test)
60+
61+
pred <- model %>%
62+
---(test)
63+
table1 <- table(Predicted = pred, Actual = testtarget)
64+
65+
cbind(prob, pred, testtarget)
66+
67+
# Fine-tune model

0 commit comments

Comments
 (0)