This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
Poker <- read.csv("poker_data.csv")
str(Poker)
'data.frame': 1025012 obs. of 11 variables:
$ S1 : int 1 2 3 4 4 1 1 2 3 4 ...
$ C1 : int 10 11 12 10 1 2 9 1 5 1 ...
$ S2 : int 1 2 3 4 4 1 1 2 3 4 ...
$ C2 : int 11 13 11 11 13 4 12 2 6 4 ...
$ S3 : int 1 2 3 4 4 1 1 2 3 4 ...
$ C3 : int 13 10 13 1 12 5 10 3 9 2 ...
$ S4 : int 1 2 3 4 4 1 1 2 3 4 ...
$ C4 : int 12 12 10 13 11 3 11 4 7 3 ...
$ S5 : int 1 2 3 4 4 1 1 2 3 4 ...
$ C5 : int 1 1 1 12 10 6 13 5 8 5 ...
$ CLASS: int 9 9 9 9 9 8 8 8 8 8 ...
# custom normalization function
normalize <- function(x) {
return((x - min(x)) / (max(x) - min(x)))
}
# apply normalization to entire data frame
Poker_norm <- as.data.frame(lapply(Poker, normalize))
# confirm that the range is now between zero and one
summary(Poker_norm$S1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000000 0.3333333 0.6666667 0.5002309 0.6666667 1.0000000
summary(Poker_norm$CLASS)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.00000000 0.00000000 0.00000000 0.06855638 0.11111110 1.00000000
# compared to the original minimum and maximum
summary(Poker$S1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.000000 2.000000 3.000000 2.500693 3.000000 4.000000
summary(Poker$CLASS)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000000 0.0000000 0.0000000 0.6170074 1.0000000 9.0000000
# create training and test data
poker_train <- Poker_norm[1:25012, ]
poker_test <- Poker_norm[25013:1025013, ]
## Step 3: Training a model on the data ----
# train the neuralnet model
library(neuralnet)
# simple ANN with only a single hidden neuron
## This will test how the different cards affect the outcome of the poker hand (CLASS) - Modeling the Strength of the Poker hand.
poker_model <- neuralnet(CLASS ~ S1 +
C1 + S2 + C2 +
S3 + C3 + S4 + C4 + S5 + C5,
data = poker_train)
# visualize the network topology
plot(poker_model)
#to see values