<jupyter_start><jupyter_text><jupyter_code>import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns 
from sklearn.model_selection import train_test_split 
from sklearn.linear_model import LogisticRegression 
from sklearn.metrics import accuracy_score 
from sklearn import metrics
card_dataset = pd.read_csv('/content/creditcard.csv')
card_dataset.shape
card_dataset.head()
card_dataset.tail()
card_dataset.describe()
card_dataset.info()
card_dataset.isnull().sum()
card_dataset['Class'].value_counts()
# separating the data for analysis
legit = card_dataset[card_dataset.Class == 0]
fraud = card_dataset[card_dataset.Class == 1]
legit_sample = legit.sample(n=492)
print(legit_sample)
new_dataset = pd.concat([legit_sample, fraud], axis = 0)
new_dataset.describe()
new_dataset.shape
X = new_dataset.drop(columns='Class', axis=1)
Y = new_dataset['Class']
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, stratify=Y, random_state=2)
model = LogisticRegression()
model.fit(X_train, Y_train)
# accuracy on training data
X_train_prediction = model.predict(X_train)
training_data_accuracy = accuracy_score(X_train_prediction, Y_train)
print('Accuracy on Training data : ', training_data_accuracy)
# accuracy on test data
X_test_prediction = model.predict(X_test)
test_data_accuracy = accuracy_score(X_test_prediction, Y_test)
print('Accuracy score on Test Data : ', test_data_accuracy)<jupyter_output>Accuracy score on Test Data :  0.9741379310344828
{'fraction_non_alphanumeric': 0.09767441860465116, 'fraction_numerical': 0.017940199335548173, 'mean_word_length': 7.705202312138728, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '593364', 'license': 'Apache-2.0', 'n_tokens_mistral': 533, 'n_tokens_neox': 510, 'n_words': 114, 'path': 'Credit_Card_Fraud_Detection.ipynb', 'repo_name': 'DgBack/Credit_Card_Fraud_Detection', 'size': '1505'}