This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import pandas as pd | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Dense, Dropout, Activation | |
from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score) | |
from sklearn.preprocessing import Normalizer | |
import h5py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
traindata = pd.read_csv('https://cainvas-static.s3.amazonaws.com/media/user_data/vomchaithany/Training.csv', header=None) | |
testdata = pd.read_csv('https://cainvas-static.s3.amazonaws.com/media/user_data/vomchaithany/Testing.csv', header=None) | |
traindata = traindata.sample(30000) | |
testdata = testdata.sample(6000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Class count | |
count_class_1, count_class_0 = traindata[0].value_counts() | |
# Divide by class | |
df_train_class_0 = traindata[traindata[0] == 0] | |
df_train_class_1 = traindata[traindata[0] == 1] | |
# Oversample 0-class and concat the DataFrames of both classes | |
df_train_class_0_over = df_train_class_0.sample(count_class_1, replace=True) | |
df_train_over = pd.concat([df_train_class_1, df_train_class_0_over], axis=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ['KMP_DUPLICATE_LIB_OK']='True' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X = df_train_over.iloc[:,1:5] | |
Y = df_train_over.iloc[:,0] | |
C = df_test_over.iloc[:,0] | |
T = df_test_over.iloc[:,1:5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scaler = Normalizer().fit(X) | |
trainX = scaler.transform(X) | |
scaler = Normalizer().fit(T) | |
testT = scaler.transform(T) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y_train = np.array(Y) | |
y_test = np.array(C) | |
X_train = np.array(trainX) | |
X_test = np.array(testT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
batch_size = 64 | |
model = Sequential() | |
model.add(Dense(1000,input_dim=4,activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(700,activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(300,activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(100,activation='relu')) | |
model.add(Dropout(0.5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
plt.plot(history.history['loss']) | |
plt.plot(history.history['val_loss']) | |
plt.title('model loss') | |
plt.ylabel('loss') | |
plt.xlabel('epoch') | |
plt.legend(['train', 'validation'], loc='upper left') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
plt.plot(history.history['accuracy']) | |
plt.plot(history.history['val_accuracy']) | |
plt.title('model accuracy') | |
plt.ylabel('accuracy') | |
plt.xlabel('epoch') | |
plt.legend(['train', 'validation'], loc='upper left') | |
plt.show() |
OlderNewer