<jupyter_start><jupyter_text>DeciosnTreeModel To Detect FraduCards<jupyter_code>import types
import pandas as pd
from botocore.client import Config
import ibm_boto3

def __iter__(self): return 0

# @hidden_cell
# The following code accesses a file in your IBM Cloud Object Storage. It includes your credentials.
# You might want to remove those credentials before you share the notebook.
client_781b004b54474bea30ee7e26faffc = ibm_boto3.client(service_name='s3',
    ibm_api_key_id='<KEY>',
    ibm_auth_endpoint="https://iam.cloud.ibm.com/oidc/token",
    config=Config(signature_version='oauth'),
    endpoint_url='https://s3.eu-geo.objectstorage.service.networklayer.com')

body = client_781b004b54474bea30ee7e26faffc.get_object(Bucket='creditcardfrauddetection-donotdelete-pr-hpiixlza7mj',Key='creditcard.csv')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(body, "__iter__"): body.__iter__ = types.MethodType( __iter__, body )

df_data_1 = pd.read_csv(body)
df_data_1.head()

import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import numpy as np
import keras
import os
np.random.seed(2)
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
import itertools
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix,accuracy_score,precision_score,recall_score,f1_score<jupyter_output><empty_output><jupyter_text>Data Processing  Scale Data<jupyter_code>scaler = StandardScaler()
df_data_1['NormalizedAmount'] = scaler.fit_transform(df_data_1['Amount'].values.reshape(-1,1))
df_data_1.drop(['Amount'],inplace=True,axis = 1)<jupyter_output><empty_output><jupyter_text>Split Data<jupyter_code>df_data_1.drop(['Time'],inplace=True,axis = 1)
X = df_data_1['Class']
Y = df_data_1.drop(['Class'],axis = 1)
X.head(3)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.25,random_state = 0)
Y_train.shape, Y_test.shape<jupyter_output><empty_output><jupyter_text>Fit the Model with decisionTreeClasssifier<jupyter_code>dec_tree = DecisionTreeClassifier()
dec_tree.fit(Y_train, X_train)<jupyter_output><empty_output><jupyter_text>Evaluation<jupyter_code>x_pred = dec_tree.predict(Y_test) 
dec_tree.score(Y_test, X_test)
def plotting_confusion_matrix(cm, classes, normalize = False,title = 'Confusion Matrix',cmap = plt.cm.Blues):
    if normalize:
        cm = cm.astype('float') / cm.sum(axis = 1)[:,np.newaxis]
        print("Normalized")
    else:
        print("Confusion Matrix, Without Normalization ")
    plt.imshow(cm, interpolation = 'nearest', cmap = cmap)
    plt.title(title)
    plt.colorbar()
    tick_marks = np.arange(len(classes))
    plt.xticks(tick_marks, classes, rotation = 0)
    plt.yticks(tick_marks, classes)
    
    formt = '.2f' if normalize else 'd'
    threshold = cm.max()/2.
    for i, j in itertools.product(range(cm.shape[0]),range(cm.shape[1])):
        plt.text(j, i, format(cm[i,j], formt),
                horizontalalignment = "center",
                color = "white" if cm[i,j] > threshold else "Blue")
    plt.ylabel('True Label')
    plt.xlabel('Predicted Label')
    plt.tight_layout()
cm = confusion_matrix(X_test, x_pred.round())
print(cm)
print(accuracy_score(X_test, x_pred.round()))
print(precision_score(X_test, x_pred.round()))
print(recall_score(X_test, x_pred.round()))
print(f1_score(X_test, x_pred.round()))
plotting_confusion_matrix(cm, classes = [0, 1], title = 'Confusion Matrix - Test dataset')<jupyter_output>Confusion Matrix, Without Normalization
{'fraction_non_alphanumeric': 0.12143055170501801, 'fraction_numerical': 0.018574993069032437, 'mean_word_length': 6.033138401559454, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 2, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '534327', 'license': 'MIT', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1268, 'n_words': 243, 'path': 'FraudDetectionModels/DecisionTreeModel.ipynb', 'repo_name': 'arunsundar022/CreditCard-Fraud-Detect-and-Predict-', 'size': '3642'}