<jupyter_start><jupyter_text>Dependency Import<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression<jupyter_output><empty_output><jupyter_text>Dataset Exploring<jupyter_code>path = '/kaggle/input/creditcardfraud/creditcard.csv'
data = pd.read_csv(path)
print('The dataset contains {} columns and {} rows'.format(data.shape[1], data.shape[0]))
data.info()
data.sample(5)<jupyter_output><empty_output><jupyter_text>Distribution of Time and Amount<jupyter_code>sns.kdeplot(data['Time']).set(title='Distribution of time')
sns.kdeplot(data['Amount']).set(title='Distribution of amount')<jupyter_output><empty_output><jupyter_text>Classification of Normal and Fraudulent Transactions<jupyter_code>counts = data.Class.value_counts()
normal = data[data.Class == 0]
fraudulent = data[data.Class == 1]
perc_normal = (counts[0]/(counts[0] + counts[1]))*100
perc_fraudulent = (counts[1]/(counts[0] + counts[1]))*100

print('The {:.2f}% of transactions were normal and {:.2f}% were fraudulent'.format(perc_normal, perc_fraudulent))
sns.barplot(x=counts.index, y=counts).set(title='Normal vs. Fraudulent transactions', ylabel='Count', xlabel='Class(0:Normal, 1:Fraudulent)')<jupyter_output><empty_output><jupyter_text>Data Modeling<jupyter_code>normal_sample = normal.sample(n=counts[1])
modif_data = pd.concat([normal_sample, fraudulent], axis=0)
modif_data['Class'].value_counts()
X = modif_data.drop(columns='Class', axis=1)
y = modif_data['Class']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1/5, random_state=8)<jupyter_output><empty_output><jupyter_text>Training and testing<jupyter_code>lr = LogisticRegression(solver='liblinear')
lr.fit(X_train, y_train)
X_test_pred = lr.predict(X_test)
acc_regres = round(accuracy_score(X_test_pred, y_test) * 100, 2)
print('Logistic Regression Accuracy: ', acc_regres)<jupyter_output>Logistic Regression Accuracy:  95.43
{'fraction_non_alphanumeric': 0.13803230543318648, 'fraction_numerical': 0.017131669114047968, 'mean_word_length': 9.93048128342246, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '257293', 'license': 'MIT', 'n_tokens_mistral': 781, 'n_tokens_neox': 744, 'n_words': 123, 'path': 'Fraud-Analysis.ipynb', 'repo_name': 'rgaezsd/fraud-analysis', 'size': '2043'}