forked from sabm0hmayahai/Electro-Maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraining.py
78 lines (45 loc) · 1.8 KB
/
training.py
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
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 13 20:08:38 2020
@author: kalpa
"""
import pandas as pd
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
dataset = pd.read_excel("15th_3.12.xlsx")
dataset = dataset.iloc[:,1:]
del dataset['Date']
import numpy as np
#lables
y_train = dataset.iloc[:,-1].values
y_train = np.array(y_train, ndmin=2)
y_train = y_train.T
#features
x_train = dataset.iloc[:,:-1].values
#scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
x_train = sc_X.fit_transform(x_train)
#splitting
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x_train, y_train, test_size = 0.2, random_state = 0)
classifier = Sequential()
#First Hidden Layer
classifier.add(Dense(20, activation='relu', kernel_initializer='random_normal', input_dim=20))
classifier.add(Dense(50, activation='relu', kernel_initializer='random_normal'))
classifier.add(Dense(30, activation='relu', kernel_initializer='random_normal'))
classifier.add(Dense(30, activation='relu', kernel_initializer='random_normal'))
classifier.add(Dense(50, activation='relu', kernel_initializer='random_normal'))
classifier.add(Dense(30, activation='relu', kernel_initializer='random_normal'))
#Output Layer
classifier.add(Dense(1, activation='sigmoid', kernel_initializer='random_normal'))
#Compiling the neural network
classifier.compile(optimizer ='adam',loss='binary_crossentropy', metrics =['accuracy'])
#Fitting the data to the training dataset
classifier.fit(x_train,y_train, batch_size=100, epochs=500)
#evaluate
eval_model=classifier.evaluate(x_test, y_test)
eval_model
#save model
classifier.save('final_model.h5')