Lapin
Lapin

Reputation: 19

Tensorflow - Confusion matrix with half zeros

I'm trying to create a tensorflow model that predicts fraudulent transactions (in my dataset, 99.8% of transactions are normal and only 0.2% are fraudulent). I have only three columns :

But, when I compute the confusion matrix, here is my result :

array([[227459,      0],
       [   387,      0]], dtype=int64)

My data is stored into X, y.

I start by splitting my data :

#Create three separate splits (Train, Val, Test)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.95, random_state=42)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2, random_state=42)

#Rebalance the training set
sm = SMOTE(random_state=42)
X_train, y_train = sm.fit_resample(X_train, y_train)

Then, I create the model and fit it :

model = models.Sequential()
model.add(layers.Normalization())
model.add(layers.Dense(25, activation="relu"))
model.add(layers.Dropout(0.3))
model.add(layers.Dense(10, activation="relu"))
model.add(layers.Dropout(0.3))
model.add(layers.Dense(5, activation="relu"))
model.add(layers.Dropout(0.3))
model.add(layers.Dense(1, activation="sigmoid"))
model.compile(optimizer="Adam", loss="binary_crossentropy", metrics=["Precision", "Recall", "AUC"])
history = model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=100)

Also, here are things that I import :

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import imblearn
from imblearn.over_sampling import SMOTE
from tensorflow import keras
from tensorflow.keras import models
from tensorflow.keras import layers
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras import regularizers
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.optimizers.schedules import ExponentialDecay

Can someone help me, please ?

Thank you in advance !

Upvotes: 0

Views: 33

Answers (0)

Related Questions