text_plain_output_1.png
from keras.layers import Dense

from keras.layers import Dropout

from keras.models import Sequential

from sklearn.metrics import confusion_matrix

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data = pd.read_csv('../input/creditcard.csv')

data['normalized_amt'] = StandardScaler().fit_transform(data['Amount'].values.reshape(-1, 1))

data = data.drop(['Amount'], axis=1)

data = data.drop(['Time'], axis=1)

x = data.iloc[:, data.columns != 'Class']
y = data.iloc[:, data.columns == 'Class']

np.array(x_train)

x_train = np.array(x_train)
x_test = np.array(x_test)
y_train = np.array(y_train)
y_test = np.array(y_test)

model = Sequential([Dense(units=16, input_dim=29, activation='relu'), Dense(units=24, activation='relu'), Dropout(0.5), Dense(20, activation='relu'), Dense(24, activation='relu'), Dense(1, activation='sigmoid')])
model.summary()

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=15, epochs=5)

score = model.evaluate(x_test, y_test)

def plot_confusion_matrix(cm, classes, normalize=False, title='None', cmap=plt.cm.Blues):
    """
    This function prints and plots the confusion matrix.
    Normalization can be applied by setting `normalize=True`.
    """
    if normalize:
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
    plt.colorbar()
    tick_marks = np.arange(len(classes))
    plt.xticks(tick_marks, classes, rotation=45)
    plt.yticks(tick_marks, classes)
    fmt = '.2f' if normalize else 'd'
    thresh = cm.max() / 2.0
    for i in range(cm.shape[0]):
        for j in range(cm.shape[1]):
            plt.text(j, i, format(cm[i, j], fmt), ha='center', va='center', color='white' if cm[i, j] > thresh else 'black')
    plt.tight_layout()

y_pred = model.predict(x_test)
y_pred.shape

y_test.shape

y_test = pd.DataFrame(y_test)

y_pred1 = model.predict(x)
y_actual = pd.DataFrame(y)
cnf_matrix1 = confusion_matrix(y_actual, y_pred1.round())
plot_confusion_matrix(cnf_matrix1, classes=[0, 1])