text_plain_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.metrics import confusion_matrix, accuracy_score, roc_auc_score, plot_roc_curve, classification_report

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

import seaborn as sns

main_df = pd.read_csv('/kaggle/input/creditcardfraud/creditcard.csv')
df = main_df.copy()

df.isnull().sum()

legit = df[df.Class == 0]
fraud = df[df.Class == 1]

df.groupby('Class').mean()

model_lr = LogisticRegression(max_iter=120, random_state=0, n_jobs=20, solver='liblinear')

model_lr.fit(X_train, y_train)

trn_lr_pred = model_lr.predict(X_train)
trn_lr_acc = accuracy_score(trn_lr_pred, y_train)

tst_lr_pred = model_lr.predict(X_test)
tst_lr_acc = accuracy_score(tst_lr_pred, y_test)

cm1 = confusion_matrix(y_test, tst_lr_pred)

df.shape

X1 = df.drop(columns='Class', axis=1)
y1 = df['Class']

(X1.shape, y1.shape)

unique_original, counts_original = np.unique(y1, return_counts=True)
unique_oversampled, counts_oversampled = np.unique(y_oversampled, return_counts=True)
print('Original fraud class distribution:', dict(zip(unique_original, counts_original)))
print('New transformed fraud class distribution:', dict(zip(unique_oversampled, counts_oversampled)))