-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANN.R
73 lines (35 loc) · 1.43 KB
/
ANN.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
#Artificiel Neural Network
#import the dataset
dataset = read.csv('Churn_Modelling.csv')
dataset = dataset[4: 14]
# inconding categorical variable as factor
dataset$Geography = as.numeric(factor(dataset$Geography,
levels = c('France','Spain','Germany'),
labels = c(1,2,3)))
dataset$Gender = as.numeric(factor(dataset$Gender,
levels = c('Male','Female'),
labels = c(1,2)))
#training the dataset into the training set and the test set
library(caTools)
set.seed(123)
split = sample.split(dataset$Exited, SplitRatio = 0.8)
training_set= subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)
#Feature Scaling
training_set[-11] = scale(training_set[-11])
test_set[-11] = scale(test_set[-11])
#Fitting the ANN to the training set
install.packages('h2o')
library(h2o)
h2o.init(nthreads = -1)
classifier = h2o.deeplearning(y = 'Exited',
training_frame = as.h2o(training_set),
activation = 'Rectifier',
hidden = c(6,6),
epochs = 100,
train_samples_per_iteration = -2)
#Predicting the test result
prob_pred = h2o.predict(classifier, newdata = as.h2o(test_set[-11]))
y_pred =(prob_pred > 0.5)
#Making the Confusion Matrix
cm = table(test_set[-11], y_pred)