{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":9120,"databundleVersionId":860599,"sourceType":"competition"},{"sourceId":50160,"databundleVersionId":7921029,"sourceType":"competition"},{"sourceId":3244803,"sourceType":"datasetVersion","datasetId":1966610},{"sourceId":12699,"sourceType":"datasetVersion","datasetId":9109},{"sourceId":16695845,"sourceType":"kernelVersion"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:53.671146Z","iopub.execute_input":"2026-09-11T15:38:53.671607Z","iopub.status.idle":"2026-09-11T15:38:53.676205Z","shell.execute_reply.started":"2026-09-11T15:38:53.671568Z","shell.execute_reply":"2026-09-11T15:38:53.675189Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data =pd.read_csv('/kaggle/input/datasets/jitheshbhatjithu/creditcard1/creditcard.csv')","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:53.677794Z","iopub.execute_input":"2026-09-11T15:38:53.678355Z","iopub.status.idle":"2026-09-11T15:38:55.320293Z","shell.execute_reply.started":"2026-09-11T15:38:53.678334Z","shell.execute_reply":"2026-09-11T15:38:55.319203Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.321589Z","iopub.execute_input":"2026-09-11T15:38:55.321944Z","iopub.status.idle":"2026-09-11T15:38:55.350742Z","shell.execute_reply.started":"2026-09-11T15:38:55.321922Z","shell.execute_reply":"2026-09-11T15:38:55.349626Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.options.display.max_columns = None","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.351927Z","iopub.execute_input":"2026-09-11T15:38:55.352174Z","iopub.status.idle":"2026-09-11T15:38:55.361173Z","shell.execute_reply.started":"2026-09-11T15:38:55.352136Z","shell.execute_reply":"2026-09-11T15:38:55.360287Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.363424Z","iopub.execute_input":"2026-09-11T15:38:55.364300Z","iopub.status.idle":"2026-09-11T15:38:55.400012Z","shell.execute_reply.started":"2026-09-11T15:38:55.364263Z","shell.execute_reply":"2026-09-11T15:38:55.398706Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.tail()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.401843Z","iopub.execute_input":"2026-09-11T15:38:55.402083Z","iopub.status.idle":"2026-09-11T15:38:55.425066Z","shell.execute_reply.started":"2026-09-11T15:38:55.402063Z","shell.execute_reply":"2026-09-11T15:38:55.424133Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.426098Z","iopub.execute_input":"2026-09-11T15:38:55.426425Z","iopub.status.idle":"2026-09-11T15:38:55.435303Z","shell.execute_reply.started":"2026-09-11T15:38:55.426405Z","shell.execute_reply":"2026-09-11T15:38:55.434261Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Number of columns: {}\".format(data.shape[1]))\nprint(\"Number of rows: {}\".format(data.shape[0]))","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.436382Z","iopub.execute_input":"2026-09-11T15:38:55.436778Z","iopub.status.idle":"2026-09-11T15:38:55.444912Z","shell.execute_reply.started":"2026-09-11T15:38:55.436757Z","shell.execute_reply":"2026-09-11T15:38:55.444023Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.445900Z","iopub.execute_input":"2026-09-11T15:38:55.446399Z","iopub.status.idle":"2026-09-11T15:38:55.478249Z","shell.execute_reply.started":"2026-09-11T15:38:55.446379Z","shell.execute_reply":"2026-09-11T15:38:55.477287Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.479478Z","iopub.execute_input":"2026-09-11T15:38:55.479736Z","iopub.status.idle":"2026-09-11T15:38:55.498755Z","shell.execute_reply.started":"2026-09-11T15:38:55.479714Z","shell.execute_reply":"2026-09-11T15:38:55.497732Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.499854Z","iopub.execute_input":"2026-09-11T15:38:55.500211Z","iopub.status.idle":"2026-09-11T15:38:55.503996Z","shell.execute_reply.started":"2026-09-11T15:38:55.500178Z","shell.execute_reply":"2026-09-11T15:38:55.503022Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sc = StandardScaler()\ndata['Amount'] = sc.fit_transform(pd.DataFrame(data['Amount']))","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.504927Z","iopub.execute_input":"2026-09-11T15:38:55.505634Z","iopub.status.idle":"2026-09-11T15:38:55.525825Z","shell.execute_reply.started":"2026-09-11T15:38:55.505602Z","shell.execute_reply":"2026-09-11T15:38:55.524726Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.526965Z","iopub.execute_input":"2026-09-11T15:38:55.527191Z","iopub.status.idle":"2026-09-11T15:38:55.552508Z","shell.execute_reply.started":"2026-09-11T15:38:55.527172Z","shell.execute_reply":"2026-09-11T15:38:55.551282Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data = data.drop(['Time'], axis =1)","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.556437Z","iopub.execute_input":"2026-09-11T15:38:55.556801Z","iopub.status.idle":"2026-09-11T15:38:55.588424Z","shell.execute_reply.started":"2026-09-11T15:38:55.556780Z","shell.execute_reply":"2026-09-11T15:38:55.587709Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.589558Z","iopub.execute_input":"2026-09-11T15:38:55.589820Z","iopub.status.idle":"2026-09-11T15:38:55.613680Z","shell.execute_reply.started":"2026-09-11T15:38:55.589799Z","shell.execute_reply":"2026-09-11T15:38:55.612522Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.duplicated().any()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:55.614853Z","iopub.execute_input":"2026-09-11T15:38:55.615368Z","iopub.status.idle":"2026-09-11T15:38:56.031552Z","shell.execute_reply.started":"2026-09-11T15:38:55.615345Z","shell.execute_reply":"2026-09-11T15:38:56.030432Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data = data.drop_duplicates()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.032746Z","iopub.execute_input":"2026-09-11T15:38:56.033145Z","iopub.status.idle":"2026-09-11T15:38:56.523952Z","shell.execute_reply.started":"2026-09-11T15:38:56.033096Z","shell.execute_reply":"2026-09-11T15:38:56.523206Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.525019Z","iopub.execute_input":"2026-09-11T15:38:56.525579Z","iopub.status.idle":"2026-09-11T15:38:56.531282Z","shell.execute_reply.started":"2026-09-11T15:38:56.525554Z","shell.execute_reply":"2026-09-11T15:38:56.530207Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data['Class'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.532589Z","iopub.execute_input":"2026-09-11T15:38:56.533293Z","iopub.status.idle":"2026-09-11T15:38:56.546955Z","shell.execute_reply.started":"2026-09-11T15:38:56.533255Z","shell.execute_reply":"2026-09-11T15:38:56.546149Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\nplt.style.use('ggplot')","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.548106Z","iopub.execute_input":"2026-09-11T15:38:56.548455Z","iopub.status.idle":"2026-09-11T15:38:56.556327Z","shell.execute_reply.started":"2026-09-11T15:38:56.548424Z","shell.execute_reply":"2026-09-11T15:38:56.555407Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.countplot(data['Class'])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.557220Z","iopub.execute_input":"2026-09-11T15:38:56.557497Z","iopub.status.idle":"2026-09-11T15:38:56.748983Z","shell.execute_reply.started":"2026-09-11T15:38:56.557478Z","shell.execute_reply":"2026-09-11T15:38:56.748192Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = data.drop('Class', axis = 1)\ny=data['Class']","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.750441Z","iopub.execute_input":"2026-09-11T15:38:56.750817Z","iopub.status.idle":"2026-09-11T15:38:56.781124Z","shell.execute_reply.started":"2026-09-11T15:38:56.750784Z","shell.execute_reply":"2026-09-11T15:38:56.780050Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.782460Z","iopub.execute_input":"2026-09-11T15:38:56.782748Z","iopub.status.idle":"2026-09-11T15:38:56.786741Z","shell.execute_reply.started":"2026-09-11T15:38:56.782727Z","shell.execute_reply":"2026-09-11T15:38:56.785947Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.787758Z","iopub.execute_input":"2026-09-11T15:38:56.787991Z","iopub.status.idle":"2026-09-11T15:38:56.869440Z","shell.execute_reply.started":"2026-09-11T15:38:56.787972Z","shell.execute_reply":"2026-09-11T15:38:56.868171Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.870936Z","iopub.execute_input":"2026-09-11T15:38:56.871275Z","iopub.status.idle":"2026-09-11T15:38:56.875942Z","shell.execute_reply.started":"2026-09-11T15:38:56.871210Z","shell.execute_reply":"2026-09-11T15:38:56.874852Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier\n","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.877122Z","iopub.execute_input":"2026-09-11T15:38:56.877412Z","iopub.status.idle":"2026-09-11T15:38:56.885529Z","shell.execute_reply.started":"2026-09-11T15:38:56.877392Z","shell.execute_reply":"2026-09-11T15:38:56.884526Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix, classification_report\nfrom sklearn.naive_bayes import GaussianNB\n\nclassifier = {\n    \"Logistic Regression\": LogisticRegression(),\n    \"Decision Tree Classifier\": DecisionTreeClassifier()\n}\n\nfor name, clf in classifier.items():\n    print(f\"\\n=========={name}===========\")\n    clf.fit(X_train, y_train)\n    y_pred = clf.predict(X_test)\n    \n    # Evaluation Metrics\n    accuracy = accuracy_score(y_test, y_pred)\n    precision = precision_score(y_test, y_pred)\n    recall = recall_score(y_test, y_pred)\n    f1 = f1_score(y_test, y_pred)\n    print(f\"\\n Accuracy: {accuracy}\")\n    print(f\" Precision: {precision}\")\n    print(f\" Recall: {recall}\")\n    print(f\" F1 Score: {f1}\")\n    \n    # Confusion Matrix\n    print(\"\\n Confusion Matrix:\")\n    print(confusion_matrix(y_test, y_pred))\n    \n    # Classification Report\n    print(\"\\n Classification Report:\")\n    print(classification_report(y_test, y_pred))\n","metadata":{"execution":{"iopub.status.busy":"2026-09-11T15:38:56.886747Z","iopub.execute_input":"2026-09-11T15:38:56.886977Z","iopub.status.idle":"2026-09-11T15:39:17.728964Z","shell.execute_reply.started":"2026-09-11T15:38:56.886957Z","shell.execute_reply":"2026-09-11T15:39:17.727876Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Undersampling","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.730178Z","iopub.execute_input":"2026-09-11T15:39:17.730629Z","iopub.status.idle":"2026-09-11T15:39:17.734931Z","shell.execute_reply.started":"2026-09-11T15:39:17.730603Z","shell.execute_reply":"2026-09-11T15:39:17.733751Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"normal = data[data['Class']==0]\nfraud = data[data['Class']==1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.736056Z","iopub.execute_input":"2026-09-11T15:39:17.736378Z","iopub.status.idle":"2026-09-11T15:39:17.784436Z","shell.execute_reply.started":"2026-09-11T15:39:17.736349Z","shell.execute_reply":"2026-09-11T15:39:17.783681Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"normal.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.785511Z","iopub.execute_input":"2026-09-11T15:39:17.785761Z","iopub.status.idle":"2026-09-11T15:39:17.792266Z","shell.execute_reply.started":"2026-09-11T15:39:17.785740Z","shell.execute_reply":"2026-09-11T15:39:17.791033Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fraud.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.793292Z","iopub.execute_input":"2026-09-11T15:39:17.793522Z","iopub.status.idle":"2026-09-11T15:39:17.805385Z","shell.execute_reply.started":"2026-09-11T15:39:17.793503Z","shell.execute_reply":"2026-09-11T15:39:17.804292Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"normal_sample = normal.sample(n=473)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.806553Z","iopub.execute_input":"2026-09-11T15:39:17.806857Z","iopub.status.idle":"2026-09-11T15:39:17.819696Z","shell.execute_reply.started":"2026-09-11T15:39:17.806829Z","shell.execute_reply":"2026-09-11T15:39:17.818887Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"normal_sample.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.820839Z","iopub.execute_input":"2026-09-11T15:39:17.821193Z","iopub.status.idle":"2026-09-11T15:39:17.830819Z","shell.execute_reply.started":"2026-09-11T15:39:17.821168Z","shell.execute_reply":"2026-09-11T15:39:17.829800Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_data = pd.concat([normal_sample,fraud], ignore_index=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.831947Z","iopub.execute_input":"2026-09-11T15:39:17.832311Z","iopub.status.idle":"2026-09-11T15:39:17.838138Z","shell.execute_reply.started":"2026-09-11T15:39:17.832274Z","shell.execute_reply":"2026-09-11T15:39:17.837279Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_data.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.839150Z","iopub.execute_input":"2026-09-11T15:39:17.839470Z","iopub.status.idle":"2026-09-11T15:39:17.864975Z","shell.execute_reply.started":"2026-09-11T15:39:17.839435Z","shell.execute_reply":"2026-09-11T15:39:17.864017Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"new_data['Class'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.866110Z","iopub.execute_input":"2026-09-11T15:39:17.866488Z","iopub.status.idle":"2026-09-11T15:39:17.873677Z","shell.execute_reply.started":"2026-09-11T15:39:17.866466Z","shell.execute_reply":"2026-09-11T15:39:17.872621Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = new_data.drop('Class', axis = 1)\ny= new_data['Class']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.875092Z","iopub.execute_input":"2026-09-11T15:39:17.875361Z","iopub.status.idle":"2026-09-11T15:39:17.882421Z","shell.execute_reply.started":"2026-09-11T15:39:17.875341Z","shell.execute_reply":"2026-09-11T15:39:17.881263Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.883565Z","iopub.execute_input":"2026-09-11T15:39:17.883912Z","iopub.status.idle":"2026-09-11T15:39:17.893434Z","shell.execute_reply.started":"2026-09-11T15:39:17.883891Z","shell.execute_reply":"2026-09-11T15:39:17.892489Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"classifier = {\n    \"Logistic Regression\": LogisticRegression(),\n    \"Decision Tree Classifier\": DecisionTreeClassifier()\n}\n\nfor name, clf in classifier.items():\n    print(f\"\\n=========={name}===========\")\n    clf.fit(X_train, y_train)\n    y_pred = clf.predict(X_test)\n    print(f\"\\n Accuaracy: {accuracy_score(y_test, y_pred)}\")\n    print(f\"\\n Precision: {precision_score(y_test, y_pred)}\")\n    print(f\"\\n Recall: {recall_score(y_test, y_pred)}\")\n    print(f\"\\n F1 Score: {f1_score(y_test, y_pred)}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.894546Z","iopub.execute_input":"2026-09-11T15:39:17.894853Z","iopub.status.idle":"2026-09-11T15:39:17.992695Z","shell.execute_reply.started":"2026-09-11T15:39:17.894832Z","shell.execute_reply":"2026-09-11T15:39:17.990003Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# OVERSAMPLING","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:17.994408Z","iopub.execute_input":"2026-09-11T15:39:17.994846Z","iopub.status.idle":"2026-09-11T15:39:18.002432Z","shell.execute_reply.started":"2026-09-11T15:39:17.994805Z","shell.execute_reply":"2026-09-11T15:39:18.000988Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = data.drop('Class', axis = 1)\ny= data['Class']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.015637Z","iopub.execute_input":"2026-09-11T15:39:18.016377Z","iopub.status.idle":"2026-09-11T15:39:18.042256Z","shell.execute_reply.started":"2026-09-11T15:39:18.016334Z","shell.execute_reply":"2026-09-11T15:39:18.040742Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.045260Z","iopub.execute_input":"2026-09-11T15:39:18.046236Z","iopub.status.idle":"2026-09-11T15:39:18.056285Z","shell.execute_reply.started":"2026-09-11T15:39:18.046159Z","shell.execute_reply":"2026-09-11T15:39:18.054471Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.057650Z","iopub.execute_input":"2026-09-11T15:39:18.058211Z","iopub.status.idle":"2026-09-11T15:39:18.065834Z","shell.execute_reply.started":"2026-09-11T15:39:18.058172Z","shell.execute_reply":"2026-09-11T15:39:18.064767Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from imblearn.over_sampling import SMOTE","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.067104Z","iopub.execute_input":"2026-09-11T15:39:18.067885Z","iopub.status.idle":"2026-09-11T15:39:18.073566Z","shell.execute_reply.started":"2026-09-11T15:39:18.067859Z","shell.execute_reply":"2026-09-11T15:39:18.072440Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_res, y_res = SMOTE().fit_resample(X,y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.074927Z","iopub.execute_input":"2026-09-11T15:39:18.075973Z","iopub.status.idle":"2026-09-11T15:39:18.543928Z","shell.execute_reply.started":"2026-09-11T15:39:18.075935Z","shell.execute_reply":"2026-09-11T15:39:18.543165Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_res.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.544944Z","iopub.execute_input":"2026-09-11T15:39:18.545155Z","iopub.status.idle":"2026-09-11T15:39:18.555532Z","shell.execute_reply.started":"2026-09-11T15:39:18.545136Z","shell.execute_reply":"2026-09-11T15:39:18.554424Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X_res, y_res, test_size = 0.2, random_state = 42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.556815Z","iopub.execute_input":"2026-09-11T15:39:18.557113Z","iopub.status.idle":"2026-09-11T15:39:18.834621Z","shell.execute_reply.started":"2026-09-11T15:39:18.557085Z","shell.execute_reply":"2026-09-11T15:39:18.833482Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"classifier = {\n    \"Logistic Regression\": LogisticRegression(),\n    \"Decision Tree Classifier\": DecisionTreeClassifier()\n}\n\nfor name, clf in classifier.items():\n    print(f\"\\n=========={name}===========\")\n    clf.fit(X_train, y_train)\n    y_pred = clf.predict(X_test)\n    print(f\"\\n Accuaracy: {accuracy_score(y_test, y_pred)}\")\n    print(f\"\\n Precision: {precision_score(y_test, y_pred)}\")\n    print(f\"\\n Recall: {recall_score(y_test, y_pred)}\")\n    print(f\"\\n F1 Score: {f1_score(y_test, y_pred)}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:39:18.836108Z","iopub.execute_input":"2026-09-11T15:39:18.836433Z","iopub.status.idle":"2026-09-11T15:40:01.174880Z","shell.execute_reply.started":"2026-09-11T15:39:18.836411Z","shell.execute_reply":"2026-09-11T15:40:01.173819Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dtc = DecisionTreeClassifier()\ndtc.fit(X_res, y_res)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:40:01.176627Z","iopub.execute_input":"2026-09-11T15:40:01.177007Z","iopub.status.idle":"2026-09-11T15:40:45.935556Z","shell.execute_reply.started":"2026-09-11T15:40:01.176973Z","shell.execute_reply":"2026-09-11T15:40:45.934690Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import joblib","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:40:45.936681Z","iopub.execute_input":"2026-09-11T15:40:45.937077Z","iopub.status.idle":"2026-09-11T15:40:45.941729Z","shell.execute_reply.started":"2026-09-11T15:40:45.937042Z","shell.execute_reply":"2026-09-11T15:40:45.940883Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"joblib.dump(dtc, \"credit_card_model.pkl\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-11T15:40:45.942931Z","iopub.execute_input":"2026-09-11T15:40:45.943690Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = joblib.load(\"credit_card_model.pkl\")","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pred = model.predict([[-1.3598071336738,-0.0727811733098497,2.53634673796914,1.37815522427443,-0.338320769942518,0.462387777762292,0.239598554061257,0.0986979012610507,0.363786969611213,0.0907941719789316,-0.551599533260813,-0.617800855762348,-0.991389847235408,-0.311169353699879,1.46817697209427,-0.470400525259478,0.207971241929242,0.0257905801985591,0.403992960255733,0.251412098239705,-0.018306777944153,0.277837575558899,-0.110473910188767,0.0669280749146731,0.128539358273528,-0.189114843888824,0.133558376740387,-0.0210530534538215,149.62]])","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pred[0]","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if pred[0] == 0:\n    print(\"Normal Transcation\")\nelse:\n    print(\"Fraud Transcation\")","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}