<jupyter_start><jupyter_text>**Scale data**<jupyter_code>scaler = StandardScaler()
data['NormalizedAmount'] = scaler.fit_transform(data['Amount'].values.reshape(-1, 1))
data = data.drop(['Amount', 'Time'], axis = 1)
y = data['Class']
X = data.drop(['Class'], axis = 1)
import keras
import os
import matplotlib.pyplot as plt
import itertools
from collections import Counter
np.random.seed(2)
from imblearn.over_sampling import SMOTE
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout<jupyter_output><empty_output><jupyter_text>**SMOTE**<jupyter_code>X_resample, y_resample = SMOTE().fit_sample(X, y)
X_resample.shape
counter = Counter(y_resample)
print(counter)<jupyter_output>Counter({0: 284315, 1: 284315})<jupyter_text>**Split into testing and training** **dataset**<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X_resample, y_resample, test_size = 0.3)
X_train = np.array(X_train)
X_test = np.array(X_test)
y_train = np.array(y_train)
y_test = np.array(y_test)<jupyter_output><empty_output><jupyter_text>**Model** **architecture**<jupyter_code>model = Sequential()
#add input layer
model.add(Dense(input_dim = 29, units = 16, activation = 'relu'))
#add 2nd hidden layer
model.add(Dense(units = 24, activation = 'relu'))
#add dropout layer
model.add(Dropout(0.5))
#add 3rd hidden layer
model.add(Dense(units = 20, activation = 'relu'))
#add 4th hidden layer
model.add(Dense(units = 24, activation = 'relu'))
#add ouptut layer
model.add(Dense(units = 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)
model.evaluate(X_test, y_test)
y_pred = model.predict(X_test)
import matplotlib.pyplot as plt
from mlxtend.plotting import plot_confusion_matrix
from sklearn.metrics import confusion_matrix<jupyter_output><empty_output><jupyter_text>Plotting Confusion Matrix<jupyter_code>conf_matrix = confusion_matrix(y_test, y_pred.round())
print(conf_matrix)
fig, ax = plt.subplots(figsize=(7.5, 7.5))
ax.matshow(conf_matrix, cmap=plt.cm.Blues, alpha=0.3)
for i in range(conf_matrix.shape[0]):
    for j in range(conf_matrix.shape[1]):
        ax.text(x=j, y=i,s=conf_matrix[i, j], va='center', ha='center', size='xx-large')
 
plt.xlabel('Predictions', fontsize=18)
plt.ylabel('Actuals', fontsize=18)
plt.title('Confusion Matrix', fontsize=18)
plt.show()<jupyter_output><empty_output><jupyter_text>**Calculating other performance metrics**<jupyter_code>print(precision_score(y_test, y_pred.round()))
print(recall_score(y_test, y_pred.round()))
print(f1_score(y_test, y_pred.round()))<jupyter_output>0.9968980677060861
0.999906427276449
0.9983999813136505
{'fraction_non_alphanumeric': 0.14581818181818182, 'fraction_numerical': 0.038181818181818185, 'mean_word_length': 8.07920792079208, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '664360', 'license': 'MIT', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1030, 'n_words': 197, 'path': 'Credit_card_Fraud_using_DNN_SMOTE.ipynb', 'repo_name': 'SPARSHSHRI10/Credit-Card-Fraud-Detection', 'size': '2750'}