import pandas as pd import numpy as np import matplotlib.pyplot as plt from termcolor import colored as cl import itertools
from sklearn.preprocessing import StandardScaler from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.neighbors import KNeighborsClassifier from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC from sklearn.ensemble import RandomForestClassifier from xgboost import XGBClassifier
from sklearn.metrics import confusion_matrix from sklearn.metrics import accuracy_score from sklearn.metrics import f1_score
print(cl('CASE COUNT', attrs = ['bold'])) print(cl('--------------------------------------------', attrs = ['bold'])) print(cl('Total number of cases are {}'.format(cases), attrs = ['bold'])) print(cl('Number of Non-fraud cases are {}'.format(nonfraud_count), attrs = ['bold'])) print(cl('Number of Non-fraud cases are {}'.format(fraud_count), attrs = ['bold'])) print(cl('Percentage of fraud cases is {}'.format(fraud_percentage), attrs = ['bold'])) print(cl('--------------------------------------------', attrs = ['bold']))
CASE COUNT -------------------------------------------- Total number of cases are 284807 Number of Non-fraud cases are 284315 Number of Non-fraud cases are 492 Percentage of fraud cases is 0.17 --------------------------------------------
# 1. Accuracy score print(cl('ACCURACY SCORE', attrs = ['bold'])) print(cl('Accuracy score of the Decision Tree model is {}' .format(accuracy_score(y_test, tree_yhat)), attrs = ['bold'])) print(cl('Accuracy score of the KNN model is {}' .format(accuracy_score(y_test, knn_yhat)), attrs = ['bold'], color = 'green')) print(cl('Accuracy score of the Logistic Regression model is {}' .format(accuracy_score(y_test, lr_yhat)), attrs = ['bold'], color = 'red')) print(cl('Accuracy score of the SVM model is {}' .format(accuracy_score(y_test, svm_yhat)), attrs = ['bold'])) print(cl('Accuracy score of the Random Forest Tree model is {}' .format(accuracy_score(y_test, rf_yhat)), attrs = ['bold'])) print(cl('Accuracy score of the XGBoost model is {}' .format(accuracy_score(y_test, xgb_yhat)), attrs = ['bold']))
# 2. F1 score print(cl('F1 SCORE', attrs = ['bold'])) print(cl('F1 score of the Decision Tree model is {}' .format(f1_score(y_test, tree_yhat)), attrs = ['bold'])) print(cl('F1 score of the KNN model is {}' .format(f1_score(y_test, knn_yhat)), attrs = ['bold'], color = 'green')) print(cl('F1 score of the Logistic Regression model is {}' .format(f1_score(y_test, lr_yhat)), attrs = ['bold'], color = 'red')) print(cl('F1 score of the SVM model is {}' .format(f1_score(y_test, svm_yhat)), attrs = ['bold'])) print(cl('F1 score of the Random Forest Tree model is {}' .format(f1_score(y_test, rf_yhat)), attrs = ['bold'])) print(cl('F1 score of the XGBoost model is {}' .format(f1_score(y_test, xgb_yhat)), attrs = ['bold']))