-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNeuralNetwork.py
60 lines (40 loc) · 1.69 KB
/
NeuralNetwork.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 1 16:54:54 2018
@author: gowtham
"""
import numpy as np
import pandas as pd
a = pd.read_csv("Encdata.tsv", sep = '\t', index_col=False)
b = pd.read_csv("Encdatag.tsv", sep = '\t', index_col=False)
dataset = [a, b]
dataset = pd.concat(dataset)
a = pd.read_csv("remove.csv", header = None)
for i in a[0]:
del dataset[i]
X = dataset.iloc[:-1, 1:388].values
y = dataset.iloc[:-1, -1].values
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1, random_state = 0)
from keras.models import Sequential
from keras.layers import Dense
classifier = Sequential()
classifier.add(Dense(output_dim = 128, init = 'uniform', activation = 'relu', input_dim = 387))
classifier.add(Dense(output_dim = 128, init = 'uniform', activation = 'relu'))
#classifier.add(Dense(output_dim = 256, init = 'uniform', activation = 'relu'))
classifier.add(Dense(output_dim = 128, init = 'uniform', activation = 'relu'))
classifier.add(Dense(output_dim = 1, init = 'uniform', activation = 'sigmoid'))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
classifier.fit(X_train, y_train, batch_size = 10, epochs = 50, validation_data=(X_test, y_test))
model_json = classifier.to_json()
with open("model.json", "w") as json_file:
json_file.write(model_json)
# serialize weights to HDF5
classifier.save_weights("model.h5")
print("Saved model to disk")
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)