diff --git a/Fraud_Detection_Machine_Learning_Project.ipynb b/Fraud_Detection_Machine_Learning_Project.ipynb
deleted file mode 100644
index 582383301..000000000
--- a/Fraud_Detection_Machine_Learning_Project.ipynb
+++ /dev/null
@@ -1,3565 +0,0 @@
-{
- "nbformat": 4,
- "nbformat_minor": 0,
- "metadata": {
- "colab": {
- "provenance": [],
- "include_colab_link": true
- },
- "kernelspec": {
- "name": "python3",
- "display_name": "Python 3"
- },
- "language_info": {
- "name": "python"
- }
- },
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {
- "id": "view-in-github",
- "colab_type": "text"
- },
- "source": [
- ""
- ]
- },
- {
- "cell_type": "markdown",
- "source": [
- "### **Fraud Detection Project**"
- ],
- "metadata": {
- "id": "CJcZvXn4e3fY"
- }
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "cgEbe5wPeMmg",
- "outputId": "8d167fd1-c199-47c0-df29-0a6f391da9bd"
- },
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Requirement already satisfied: kaggle in /usr/local/lib/python3.10/dist-packages (1.6.17)\n",
- "Requirement already satisfied: six>=1.10 in /usr/local/lib/python3.10/dist-packages (from kaggle) (1.17.0)\n",
- "Requirement already satisfied: certifi>=2023.7.22 in /usr/local/lib/python3.10/dist-packages (from kaggle) (2024.12.14)\n",
- "Requirement already satisfied: python-dateutil in /usr/local/lib/python3.10/dist-packages (from kaggle) (2.8.2)\n",
- "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from kaggle) (2.32.3)\n",
- "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from kaggle) (4.67.1)\n",
- "Requirement already satisfied: python-slugify in /usr/local/lib/python3.10/dist-packages (from kaggle) (8.0.4)\n",
- "Requirement already satisfied: urllib3 in /usr/local/lib/python3.10/dist-packages (from kaggle) (2.3.0)\n",
- "Requirement already satisfied: bleach in /usr/local/lib/python3.10/dist-packages (from kaggle) (6.2.0)\n",
- "Requirement already satisfied: webencodings in /usr/local/lib/python3.10/dist-packages (from bleach->kaggle) (0.5.1)\n",
- "Requirement already satisfied: text-unidecode>=1.3 in /usr/local/lib/python3.10/dist-packages (from python-slugify->kaggle) (1.3)\n",
- "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->kaggle) (3.4.1)\n",
- "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->kaggle) (3.10)\n"
- ]
- }
- ],
- "source": [
- "pip install kaggle"
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "!mkdir -p ~/.kaggle\n",
- "!cp kaggle.json~/.kaggle/\n",
- "!chmod 600 ~/.kaggle/kaggle.json"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "3NBZssp0fJsk",
- "outputId": "6bde38c8-1b8b-4ff4-c90e-8527a9e4803a"
- },
- "execution_count": 2,
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "cp: missing destination file operand after 'kaggle.json~/.kaggle/'\n",
- "Try 'cp --help' for more information.\n",
- "chmod: cannot access '/root/.kaggle/kaggle.json': No such file or directory\n"
- ]
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "# API to fetch kaggle dataset\n",
- "!kaggle datasets download -d mlg-ulb/creditcardfraud"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "d6OnTj1ygtta",
- "outputId": "990b1470-f01e-4322-abbc-549d85cf3a1d"
- },
- "execution_count": 3,
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Dataset URL: https://www.kaggle.com/datasets/mlg-ulb/creditcardfraud\n",
- "License(s): DbCL-1.0\n",
- "Downloading creditcardfraud.zip to /content\n",
- " 94% 62.0M/66.0M [00:02<00:00, 43.9MB/s]\n",
- "100% 66.0M/66.0M [00:02<00:00, 29.3MB/s]\n"
- ]
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "# extracting zip file\n",
- "from zipfile import ZipFile\n",
- "file_name = \"creditcardfraud.zip\"\n",
- "\n",
- "with ZipFile(file_name,'r') as zip:\n",
- " zip.extractall()\n",
- " print(\"Done\")"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "smmqhDZwg9fE",
- "outputId": "49af5a9a-2431-456d-b4e2-7caaac7b4d1c"
- },
- "execution_count": 4,
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "Done\n"
- ]
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "from sklearn.model_selection import train_test_split\n",
- "from sklearn.linear_model import LogisticRegression\n",
- "from sklearn.metrics import accuracy_score\n"
- ],
- "metadata": {
- "id": "u8XAie13g9kI"
- },
- "execution_count": 5,
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "# Importing data\n",
- "data=pd.read_csv(\"/content/creditcard.csv\")"
- ],
- "metadata": {
- "id": "Zu7kS1mKg9sK"
- },
- "execution_count": 6,
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "data.head()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 255
- },
- "id": "g0fLI_V5iQ8t",
- "outputId": "b83f3655-79eb-4b96-900b-f2526934ac6e"
- },
- "execution_count": 7,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " Time V1 V2 V3 V4 V5 V6 V7 \\\n",
- "0 0.0 -1.359807 -0.072781 2.536347 1.378155 -0.338321 0.462388 0.239599 \n",
- "1 0.0 1.191857 0.266151 0.166480 0.448154 0.060018 -0.082361 -0.078803 \n",
- "2 1.0 -1.358354 -1.340163 1.773209 0.379780 -0.503198 1.800499 0.791461 \n",
- "3 1.0 -0.966272 -0.185226 1.792993 -0.863291 -0.010309 1.247203 0.237609 \n",
- "4 2.0 -1.158233 0.877737 1.548718 0.403034 -0.407193 0.095921 0.592941 \n",
- "\n",
- " V8 V9 ... V21 V22 V23 V24 V25 \\\n",
- "0 0.098698 0.363787 ... -0.018307 0.277838 -0.110474 0.066928 0.128539 \n",
- "1 0.085102 -0.255425 ... -0.225775 -0.638672 0.101288 -0.339846 0.167170 \n",
- "2 0.247676 -1.514654 ... 0.247998 0.771679 0.909412 -0.689281 -0.327642 \n",
- "3 0.377436 -1.387024 ... -0.108300 0.005274 -0.190321 -1.175575 0.647376 \n",
- "4 -0.270533 0.817739 ... -0.009431 0.798278 -0.137458 0.141267 -0.206010 \n",
- "\n",
- " V26 V27 V28 Amount Class \n",
- "0 -0.189115 0.133558 -0.021053 149.62 0 \n",
- "1 0.125895 -0.008983 0.014724 2.69 0 \n",
- "2 -0.139097 -0.055353 -0.059752 378.66 0 \n",
- "3 -0.221929 0.062723 0.061458 123.50 0 \n",
- "4 0.502292 0.219422 0.215153 69.99 0 \n",
- "\n",
- "[5 rows x 31 columns]"
- ],
- "text/html": [
- "\n",
- "
\n",
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Time | \n",
- " V1 | \n",
- " V2 | \n",
- " V3 | \n",
- " V4 | \n",
- " V5 | \n",
- " V6 | \n",
- " V7 | \n",
- " V8 | \n",
- " V9 | \n",
- " ... | \n",
- " V21 | \n",
- " V22 | \n",
- " V23 | \n",
- " V24 | \n",
- " V25 | \n",
- " V26 | \n",
- " V27 | \n",
- " V28 | \n",
- " Amount | \n",
- " Class | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.0 | \n",
- " -1.359807 | \n",
- " -0.072781 | \n",
- " 2.536347 | \n",
- " 1.378155 | \n",
- " -0.338321 | \n",
- " 0.462388 | \n",
- " 0.239599 | \n",
- " 0.098698 | \n",
- " 0.363787 | \n",
- " ... | \n",
- " -0.018307 | \n",
- " 0.277838 | \n",
- " -0.110474 | \n",
- " 0.066928 | \n",
- " 0.128539 | \n",
- " -0.189115 | \n",
- " 0.133558 | \n",
- " -0.021053 | \n",
- " 149.62 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.0 | \n",
- " 1.191857 | \n",
- " 0.266151 | \n",
- " 0.166480 | \n",
- " 0.448154 | \n",
- " 0.060018 | \n",
- " -0.082361 | \n",
- " -0.078803 | \n",
- " 0.085102 | \n",
- " -0.255425 | \n",
- " ... | \n",
- " -0.225775 | \n",
- " -0.638672 | \n",
- " 0.101288 | \n",
- " -0.339846 | \n",
- " 0.167170 | \n",
- " 0.125895 | \n",
- " -0.008983 | \n",
- " 0.014724 | \n",
- " 2.69 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 1.0 | \n",
- " -1.358354 | \n",
- " -1.340163 | \n",
- " 1.773209 | \n",
- " 0.379780 | \n",
- " -0.503198 | \n",
- " 1.800499 | \n",
- " 0.791461 | \n",
- " 0.247676 | \n",
- " -1.514654 | \n",
- " ... | \n",
- " 0.247998 | \n",
- " 0.771679 | \n",
- " 0.909412 | \n",
- " -0.689281 | \n",
- " -0.327642 | \n",
- " -0.139097 | \n",
- " -0.055353 | \n",
- " -0.059752 | \n",
- " 378.66 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 1.0 | \n",
- " -0.966272 | \n",
- " -0.185226 | \n",
- " 1.792993 | \n",
- " -0.863291 | \n",
- " -0.010309 | \n",
- " 1.247203 | \n",
- " 0.237609 | \n",
- " 0.377436 | \n",
- " -1.387024 | \n",
- " ... | \n",
- " -0.108300 | \n",
- " 0.005274 | \n",
- " -0.190321 | \n",
- " -1.175575 | \n",
- " 0.647376 | \n",
- " -0.221929 | \n",
- " 0.062723 | \n",
- " 0.061458 | \n",
- " 123.50 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 2.0 | \n",
- " -1.158233 | \n",
- " 0.877737 | \n",
- " 1.548718 | \n",
- " 0.403034 | \n",
- " -0.407193 | \n",
- " 0.095921 | \n",
- " 0.592941 | \n",
- " -0.270533 | \n",
- " 0.817739 | \n",
- " ... | \n",
- " -0.009431 | \n",
- " 0.798278 | \n",
- " -0.137458 | \n",
- " 0.141267 | \n",
- " -0.206010 | \n",
- " 0.502292 | \n",
- " 0.219422 | \n",
- " 0.215153 | \n",
- " 69.99 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
5 rows × 31 columns
\n",
- "
\n",
- "
\n",
- "
\n"
- ],
- "application/vnd.google.colaboratory.intrinsic+json": {
- "type": "dataframe",
- "variable_name": "data"
- }
- },
- "metadata": {},
- "execution_count": 7
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "data.shape"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "HAo_1IP4iQ_6",
- "outputId": "d8f47e26-1f18-44af-f927-28869b64c308"
- },
- "execution_count": 8,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "(284807, 31)"
- ]
- },
- "metadata": {},
- "execution_count": 8
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "data.info()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "MUA5pxcDiRCk",
- "outputId": "3ea91468-77ac-4a6c-c1ae-3bd612ac8b74"
- },
- "execution_count": 9,
- "outputs": [
- {
- "output_type": "stream",
- "name": "stdout",
- "text": [
- "\n",
- "RangeIndex: 284807 entries, 0 to 284806\n",
- "Data columns (total 31 columns):\n",
- " # Column Non-Null Count Dtype \n",
- "--- ------ -------------- ----- \n",
- " 0 Time 284807 non-null float64\n",
- " 1 V1 284807 non-null float64\n",
- " 2 V2 284807 non-null float64\n",
- " 3 V3 284807 non-null float64\n",
- " 4 V4 284807 non-null float64\n",
- " 5 V5 284807 non-null float64\n",
- " 6 V6 284807 non-null float64\n",
- " 7 V7 284807 non-null float64\n",
- " 8 V8 284807 non-null float64\n",
- " 9 V9 284807 non-null float64\n",
- " 10 V10 284807 non-null float64\n",
- " 11 V11 284807 non-null float64\n",
- " 12 V12 284807 non-null float64\n",
- " 13 V13 284807 non-null float64\n",
- " 14 V14 284807 non-null float64\n",
- " 15 V15 284807 non-null float64\n",
- " 16 V16 284807 non-null float64\n",
- " 17 V17 284807 non-null float64\n",
- " 18 V18 284807 non-null float64\n",
- " 19 V19 284807 non-null float64\n",
- " 20 V20 284807 non-null float64\n",
- " 21 V21 284807 non-null float64\n",
- " 22 V22 284807 non-null float64\n",
- " 23 V23 284807 non-null float64\n",
- " 24 V24 284807 non-null float64\n",
- " 25 V25 284807 non-null float64\n",
- " 26 V26 284807 non-null float64\n",
- " 27 V27 284807 non-null float64\n",
- " 28 V28 284807 non-null float64\n",
- " 29 Amount 284807 non-null float64\n",
- " 30 Class 284807 non-null int64 \n",
- "dtypes: float64(30), int64(1)\n",
- "memory usage: 67.4 MB\n"
- ]
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "data['Class'].value_counts()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 178
- },
- "id": "BaC0Ct1Rg9wL",
- "outputId": "afa8272a-5403-44b9-c386-59e96df6ce64"
- },
- "execution_count": 10,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "Class\n",
- "0 284315\n",
- "1 492\n",
- "Name: count, dtype: int64"
- ],
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " count | \n",
- "
\n",
- " \n",
- " Class | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 284315 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 492 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ]
- },
- "metadata": {},
- "execution_count": 10
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "# statastics\n",
- "data.describe()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 349
- },
- "id": "Z9i_dZ0gijg3",
- "outputId": "47f87fb2-9ea4-4e86-f553-1d542e34d970"
- },
- "execution_count": 11,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " Time V1 V2 V3 V4 \\\n",
- "count 284807.000000 2.848070e+05 2.848070e+05 2.848070e+05 2.848070e+05 \n",
- "mean 94813.859575 1.168375e-15 3.416908e-16 -1.379537e-15 2.074095e-15 \n",
- "std 47488.145955 1.958696e+00 1.651309e+00 1.516255e+00 1.415869e+00 \n",
- "min 0.000000 -5.640751e+01 -7.271573e+01 -4.832559e+01 -5.683171e+00 \n",
- "25% 54201.500000 -9.203734e-01 -5.985499e-01 -8.903648e-01 -8.486401e-01 \n",
- "50% 84692.000000 1.810880e-02 6.548556e-02 1.798463e-01 -1.984653e-02 \n",
- "75% 139320.500000 1.315642e+00 8.037239e-01 1.027196e+00 7.433413e-01 \n",
- "max 172792.000000 2.454930e+00 2.205773e+01 9.382558e+00 1.687534e+01 \n",
- "\n",
- " V5 V6 V7 V8 V9 \\\n",
- "count 2.848070e+05 2.848070e+05 2.848070e+05 2.848070e+05 2.848070e+05 \n",
- "mean 9.604066e-16 1.487313e-15 -5.556467e-16 1.213481e-16 -2.406331e-15 \n",
- "std 1.380247e+00 1.332271e+00 1.237094e+00 1.194353e+00 1.098632e+00 \n",
- "min -1.137433e+02 -2.616051e+01 -4.355724e+01 -7.321672e+01 -1.343407e+01 \n",
- "25% -6.915971e-01 -7.682956e-01 -5.540759e-01 -2.086297e-01 -6.430976e-01 \n",
- "50% -5.433583e-02 -2.741871e-01 4.010308e-02 2.235804e-02 -5.142873e-02 \n",
- "75% 6.119264e-01 3.985649e-01 5.704361e-01 3.273459e-01 5.971390e-01 \n",
- "max 3.480167e+01 7.330163e+01 1.205895e+02 2.000721e+01 1.559499e+01 \n",
- "\n",
- " ... V21 V22 V23 V24 \\\n",
- "count ... 2.848070e+05 2.848070e+05 2.848070e+05 2.848070e+05 \n",
- "mean ... 1.654067e-16 -3.568593e-16 2.578648e-16 4.473266e-15 \n",
- "std ... 7.345240e-01 7.257016e-01 6.244603e-01 6.056471e-01 \n",
- "min ... -3.483038e+01 -1.093314e+01 -4.480774e+01 -2.836627e+00 \n",
- "25% ... -2.283949e-01 -5.423504e-01 -1.618463e-01 -3.545861e-01 \n",
- "50% ... -2.945017e-02 6.781943e-03 -1.119293e-02 4.097606e-02 \n",
- "75% ... 1.863772e-01 5.285536e-01 1.476421e-01 4.395266e-01 \n",
- "max ... 2.720284e+01 1.050309e+01 2.252841e+01 4.584549e+00 \n",
- "\n",
- " V25 V26 V27 V28 Amount \\\n",
- "count 2.848070e+05 2.848070e+05 2.848070e+05 2.848070e+05 284807.000000 \n",
- "mean 5.340915e-16 1.683437e-15 -3.660091e-16 -1.227390e-16 88.349619 \n",
- "std 5.212781e-01 4.822270e-01 4.036325e-01 3.300833e-01 250.120109 \n",
- "min -1.029540e+01 -2.604551e+00 -2.256568e+01 -1.543008e+01 0.000000 \n",
- "25% -3.171451e-01 -3.269839e-01 -7.083953e-02 -5.295979e-02 5.600000 \n",
- "50% 1.659350e-02 -5.213911e-02 1.342146e-03 1.124383e-02 22.000000 \n",
- "75% 3.507156e-01 2.409522e-01 9.104512e-02 7.827995e-02 77.165000 \n",
- "max 7.519589e+00 3.517346e+00 3.161220e+01 3.384781e+01 25691.160000 \n",
- "\n",
- " Class \n",
- "count 284807.000000 \n",
- "mean 0.001727 \n",
- "std 0.041527 \n",
- "min 0.000000 \n",
- "25% 0.000000 \n",
- "50% 0.000000 \n",
- "75% 0.000000 \n",
- "max 1.000000 \n",
- "\n",
- "[8 rows x 31 columns]"
- ],
- "text/html": [
- "\n",
- " \n",
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Time | \n",
- " V1 | \n",
- " V2 | \n",
- " V3 | \n",
- " V4 | \n",
- " V5 | \n",
- " V6 | \n",
- " V7 | \n",
- " V8 | \n",
- " V9 | \n",
- " ... | \n",
- " V21 | \n",
- " V22 | \n",
- " V23 | \n",
- " V24 | \n",
- " V25 | \n",
- " V26 | \n",
- " V27 | \n",
- " V28 | \n",
- " Amount | \n",
- " Class | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " count | \n",
- " 284807.000000 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " ... | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 2.848070e+05 | \n",
- " 284807.000000 | \n",
- " 284807.000000 | \n",
- "
\n",
- " \n",
- " mean | \n",
- " 94813.859575 | \n",
- " 1.168375e-15 | \n",
- " 3.416908e-16 | \n",
- " -1.379537e-15 | \n",
- " 2.074095e-15 | \n",
- " 9.604066e-16 | \n",
- " 1.487313e-15 | \n",
- " -5.556467e-16 | \n",
- " 1.213481e-16 | \n",
- " -2.406331e-15 | \n",
- " ... | \n",
- " 1.654067e-16 | \n",
- " -3.568593e-16 | \n",
- " 2.578648e-16 | \n",
- " 4.473266e-15 | \n",
- " 5.340915e-16 | \n",
- " 1.683437e-15 | \n",
- " -3.660091e-16 | \n",
- " -1.227390e-16 | \n",
- " 88.349619 | \n",
- " 0.001727 | \n",
- "
\n",
- " \n",
- " std | \n",
- " 47488.145955 | \n",
- " 1.958696e+00 | \n",
- " 1.651309e+00 | \n",
- " 1.516255e+00 | \n",
- " 1.415869e+00 | \n",
- " 1.380247e+00 | \n",
- " 1.332271e+00 | \n",
- " 1.237094e+00 | \n",
- " 1.194353e+00 | \n",
- " 1.098632e+00 | \n",
- " ... | \n",
- " 7.345240e-01 | \n",
- " 7.257016e-01 | \n",
- " 6.244603e-01 | \n",
- " 6.056471e-01 | \n",
- " 5.212781e-01 | \n",
- " 4.822270e-01 | \n",
- " 4.036325e-01 | \n",
- " 3.300833e-01 | \n",
- " 250.120109 | \n",
- " 0.041527 | \n",
- "
\n",
- " \n",
- " min | \n",
- " 0.000000 | \n",
- " -5.640751e+01 | \n",
- " -7.271573e+01 | \n",
- " -4.832559e+01 | \n",
- " -5.683171e+00 | \n",
- " -1.137433e+02 | \n",
- " -2.616051e+01 | \n",
- " -4.355724e+01 | \n",
- " -7.321672e+01 | \n",
- " -1.343407e+01 | \n",
- " ... | \n",
- " -3.483038e+01 | \n",
- " -1.093314e+01 | \n",
- " -4.480774e+01 | \n",
- " -2.836627e+00 | \n",
- " -1.029540e+01 | \n",
- " -2.604551e+00 | \n",
- " -2.256568e+01 | \n",
- " -1.543008e+01 | \n",
- " 0.000000 | \n",
- " 0.000000 | \n",
- "
\n",
- " \n",
- " 25% | \n",
- " 54201.500000 | \n",
- " -9.203734e-01 | \n",
- " -5.985499e-01 | \n",
- " -8.903648e-01 | \n",
- " -8.486401e-01 | \n",
- " -6.915971e-01 | \n",
- " -7.682956e-01 | \n",
- " -5.540759e-01 | \n",
- " -2.086297e-01 | \n",
- " -6.430976e-01 | \n",
- " ... | \n",
- " -2.283949e-01 | \n",
- " -5.423504e-01 | \n",
- " -1.618463e-01 | \n",
- " -3.545861e-01 | \n",
- " -3.171451e-01 | \n",
- " -3.269839e-01 | \n",
- " -7.083953e-02 | \n",
- " -5.295979e-02 | \n",
- " 5.600000 | \n",
- " 0.000000 | \n",
- "
\n",
- " \n",
- " 50% | \n",
- " 84692.000000 | \n",
- " 1.810880e-02 | \n",
- " 6.548556e-02 | \n",
- " 1.798463e-01 | \n",
- " -1.984653e-02 | \n",
- " -5.433583e-02 | \n",
- " -2.741871e-01 | \n",
- " 4.010308e-02 | \n",
- " 2.235804e-02 | \n",
- " -5.142873e-02 | \n",
- " ... | \n",
- " -2.945017e-02 | \n",
- " 6.781943e-03 | \n",
- " -1.119293e-02 | \n",
- " 4.097606e-02 | \n",
- " 1.659350e-02 | \n",
- " -5.213911e-02 | \n",
- " 1.342146e-03 | \n",
- " 1.124383e-02 | \n",
- " 22.000000 | \n",
- " 0.000000 | \n",
- "
\n",
- " \n",
- " 75% | \n",
- " 139320.500000 | \n",
- " 1.315642e+00 | \n",
- " 8.037239e-01 | \n",
- " 1.027196e+00 | \n",
- " 7.433413e-01 | \n",
- " 6.119264e-01 | \n",
- " 3.985649e-01 | \n",
- " 5.704361e-01 | \n",
- " 3.273459e-01 | \n",
- " 5.971390e-01 | \n",
- " ... | \n",
- " 1.863772e-01 | \n",
- " 5.285536e-01 | \n",
- " 1.476421e-01 | \n",
- " 4.395266e-01 | \n",
- " 3.507156e-01 | \n",
- " 2.409522e-01 | \n",
- " 9.104512e-02 | \n",
- " 7.827995e-02 | \n",
- " 77.165000 | \n",
- " 0.000000 | \n",
- "
\n",
- " \n",
- " max | \n",
- " 172792.000000 | \n",
- " 2.454930e+00 | \n",
- " 2.205773e+01 | \n",
- " 9.382558e+00 | \n",
- " 1.687534e+01 | \n",
- " 3.480167e+01 | \n",
- " 7.330163e+01 | \n",
- " 1.205895e+02 | \n",
- " 2.000721e+01 | \n",
- " 1.559499e+01 | \n",
- " ... | \n",
- " 2.720284e+01 | \n",
- " 1.050309e+01 | \n",
- " 2.252841e+01 | \n",
- " 4.584549e+00 | \n",
- " 7.519589e+00 | \n",
- " 3.517346e+00 | \n",
- " 3.161220e+01 | \n",
- " 3.384781e+01 | \n",
- " 25691.160000 | \n",
- " 1.000000 | \n",
- "
\n",
- " \n",
- "
\n",
- "
8 rows × 31 columns
\n",
- "
\n",
- "
\n",
- "
\n"
- ],
- "application/vnd.google.colaboratory.intrinsic+json": {
- "type": "dataframe"
- }
- },
- "metadata": {},
- "execution_count": 11
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "legit=data[data.Class==0]\n",
- "fraud=data[data['Class']==1]"
- ],
- "metadata": {
- "id": "TZTQSHysijk-"
- },
- "execution_count": 12,
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "legit\n"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 443
- },
- "id": "kSv5ZTvqijpf",
- "outputId": "970c09b0-2b93-425a-c2e9-4b0deeb1b58f"
- },
- "execution_count": 13,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " Time V1 V2 V3 V4 V5 \\\n",
- "0 0.0 -1.359807 -0.072781 2.536347 1.378155 -0.338321 \n",
- "1 0.0 1.191857 0.266151 0.166480 0.448154 0.060018 \n",
- "2 1.0 -1.358354 -1.340163 1.773209 0.379780 -0.503198 \n",
- "3 1.0 -0.966272 -0.185226 1.792993 -0.863291 -0.010309 \n",
- "4 2.0 -1.158233 0.877737 1.548718 0.403034 -0.407193 \n",
- "... ... ... ... ... ... ... \n",
- "284802 172786.0 -11.881118 10.071785 -9.834783 -2.066656 -5.364473 \n",
- "284803 172787.0 -0.732789 -0.055080 2.035030 -0.738589 0.868229 \n",
- "284804 172788.0 1.919565 -0.301254 -3.249640 -0.557828 2.630515 \n",
- "284805 172788.0 -0.240440 0.530483 0.702510 0.689799 -0.377961 \n",
- "284806 172792.0 -0.533413 -0.189733 0.703337 -0.506271 -0.012546 \n",
- "\n",
- " V6 V7 V8 V9 ... V21 V22 \\\n",
- "0 0.462388 0.239599 0.098698 0.363787 ... -0.018307 0.277838 \n",
- "1 -0.082361 -0.078803 0.085102 -0.255425 ... -0.225775 -0.638672 \n",
- "2 1.800499 0.791461 0.247676 -1.514654 ... 0.247998 0.771679 \n",
- "3 1.247203 0.237609 0.377436 -1.387024 ... -0.108300 0.005274 \n",
- "4 0.095921 0.592941 -0.270533 0.817739 ... -0.009431 0.798278 \n",
- "... ... ... ... ... ... ... ... \n",
- "284802 -2.606837 -4.918215 7.305334 1.914428 ... 0.213454 0.111864 \n",
- "284803 1.058415 0.024330 0.294869 0.584800 ... 0.214205 0.924384 \n",
- "284804 3.031260 -0.296827 0.708417 0.432454 ... 0.232045 0.578229 \n",
- "284805 0.623708 -0.686180 0.679145 0.392087 ... 0.265245 0.800049 \n",
- "284806 -0.649617 1.577006 -0.414650 0.486180 ... 0.261057 0.643078 \n",
- "\n",
- " V23 V24 V25 V26 V27 V28 Amount \\\n",
- "0 -0.110474 0.066928 0.128539 -0.189115 0.133558 -0.021053 149.62 \n",
- "1 0.101288 -0.339846 0.167170 0.125895 -0.008983 0.014724 2.69 \n",
- "2 0.909412 -0.689281 -0.327642 -0.139097 -0.055353 -0.059752 378.66 \n",
- "3 -0.190321 -1.175575 0.647376 -0.221929 0.062723 0.061458 123.50 \n",
- "4 -0.137458 0.141267 -0.206010 0.502292 0.219422 0.215153 69.99 \n",
- "... ... ... ... ... ... ... ... \n",
- "284802 1.014480 -0.509348 1.436807 0.250034 0.943651 0.823731 0.77 \n",
- "284803 0.012463 -1.016226 -0.606624 -0.395255 0.068472 -0.053527 24.79 \n",
- "284804 -0.037501 0.640134 0.265745 -0.087371 0.004455 -0.026561 67.88 \n",
- "284805 -0.163298 0.123205 -0.569159 0.546668 0.108821 0.104533 10.00 \n",
- "284806 0.376777 0.008797 -0.473649 -0.818267 -0.002415 0.013649 217.00 \n",
- "\n",
- " Class \n",
- "0 0 \n",
- "1 0 \n",
- "2 0 \n",
- "3 0 \n",
- "4 0 \n",
- "... ... \n",
- "284802 0 \n",
- "284803 0 \n",
- "284804 0 \n",
- "284805 0 \n",
- "284806 0 \n",
- "\n",
- "[284315 rows x 31 columns]"
- ],
- "text/html": [
- "\n",
- " \n",
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Time | \n",
- " V1 | \n",
- " V2 | \n",
- " V3 | \n",
- " V4 | \n",
- " V5 | \n",
- " V6 | \n",
- " V7 | \n",
- " V8 | \n",
- " V9 | \n",
- " ... | \n",
- " V21 | \n",
- " V22 | \n",
- " V23 | \n",
- " V24 | \n",
- " V25 | \n",
- " V26 | \n",
- " V27 | \n",
- " V28 | \n",
- " Amount | \n",
- " Class | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.0 | \n",
- " -1.359807 | \n",
- " -0.072781 | \n",
- " 2.536347 | \n",
- " 1.378155 | \n",
- " -0.338321 | \n",
- " 0.462388 | \n",
- " 0.239599 | \n",
- " 0.098698 | \n",
- " 0.363787 | \n",
- " ... | \n",
- " -0.018307 | \n",
- " 0.277838 | \n",
- " -0.110474 | \n",
- " 0.066928 | \n",
- " 0.128539 | \n",
- " -0.189115 | \n",
- " 0.133558 | \n",
- " -0.021053 | \n",
- " 149.62 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 0.0 | \n",
- " 1.191857 | \n",
- " 0.266151 | \n",
- " 0.166480 | \n",
- " 0.448154 | \n",
- " 0.060018 | \n",
- " -0.082361 | \n",
- " -0.078803 | \n",
- " 0.085102 | \n",
- " -0.255425 | \n",
- " ... | \n",
- " -0.225775 | \n",
- " -0.638672 | \n",
- " 0.101288 | \n",
- " -0.339846 | \n",
- " 0.167170 | \n",
- " 0.125895 | \n",
- " -0.008983 | \n",
- " 0.014724 | \n",
- " 2.69 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 1.0 | \n",
- " -1.358354 | \n",
- " -1.340163 | \n",
- " 1.773209 | \n",
- " 0.379780 | \n",
- " -0.503198 | \n",
- " 1.800499 | \n",
- " 0.791461 | \n",
- " 0.247676 | \n",
- " -1.514654 | \n",
- " ... | \n",
- " 0.247998 | \n",
- " 0.771679 | \n",
- " 0.909412 | \n",
- " -0.689281 | \n",
- " -0.327642 | \n",
- " -0.139097 | \n",
- " -0.055353 | \n",
- " -0.059752 | \n",
- " 378.66 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 1.0 | \n",
- " -0.966272 | \n",
- " -0.185226 | \n",
- " 1.792993 | \n",
- " -0.863291 | \n",
- " -0.010309 | \n",
- " 1.247203 | \n",
- " 0.237609 | \n",
- " 0.377436 | \n",
- " -1.387024 | \n",
- " ... | \n",
- " -0.108300 | \n",
- " 0.005274 | \n",
- " -0.190321 | \n",
- " -1.175575 | \n",
- " 0.647376 | \n",
- " -0.221929 | \n",
- " 0.062723 | \n",
- " 0.061458 | \n",
- " 123.50 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 2.0 | \n",
- " -1.158233 | \n",
- " 0.877737 | \n",
- " 1.548718 | \n",
- " 0.403034 | \n",
- " -0.407193 | \n",
- " 0.095921 | \n",
- " 0.592941 | \n",
- " -0.270533 | \n",
- " 0.817739 | \n",
- " ... | \n",
- " -0.009431 | \n",
- " 0.798278 | \n",
- " -0.137458 | \n",
- " 0.141267 | \n",
- " -0.206010 | \n",
- " 0.502292 | \n",
- " 0.219422 | \n",
- " 0.215153 | \n",
- " 69.99 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 284802 | \n",
- " 172786.0 | \n",
- " -11.881118 | \n",
- " 10.071785 | \n",
- " -9.834783 | \n",
- " -2.066656 | \n",
- " -5.364473 | \n",
- " -2.606837 | \n",
- " -4.918215 | \n",
- " 7.305334 | \n",
- " 1.914428 | \n",
- " ... | \n",
- " 0.213454 | \n",
- " 0.111864 | \n",
- " 1.014480 | \n",
- " -0.509348 | \n",
- " 1.436807 | \n",
- " 0.250034 | \n",
- " 0.943651 | \n",
- " 0.823731 | \n",
- " 0.77 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 284803 | \n",
- " 172787.0 | \n",
- " -0.732789 | \n",
- " -0.055080 | \n",
- " 2.035030 | \n",
- " -0.738589 | \n",
- " 0.868229 | \n",
- " 1.058415 | \n",
- " 0.024330 | \n",
- " 0.294869 | \n",
- " 0.584800 | \n",
- " ... | \n",
- " 0.214205 | \n",
- " 0.924384 | \n",
- " 0.012463 | \n",
- " -1.016226 | \n",
- " -0.606624 | \n",
- " -0.395255 | \n",
- " 0.068472 | \n",
- " -0.053527 | \n",
- " 24.79 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 284804 | \n",
- " 172788.0 | \n",
- " 1.919565 | \n",
- " -0.301254 | \n",
- " -3.249640 | \n",
- " -0.557828 | \n",
- " 2.630515 | \n",
- " 3.031260 | \n",
- " -0.296827 | \n",
- " 0.708417 | \n",
- " 0.432454 | \n",
- " ... | \n",
- " 0.232045 | \n",
- " 0.578229 | \n",
- " -0.037501 | \n",
- " 0.640134 | \n",
- " 0.265745 | \n",
- " -0.087371 | \n",
- " 0.004455 | \n",
- " -0.026561 | \n",
- " 67.88 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 284805 | \n",
- " 172788.0 | \n",
- " -0.240440 | \n",
- " 0.530483 | \n",
- " 0.702510 | \n",
- " 0.689799 | \n",
- " -0.377961 | \n",
- " 0.623708 | \n",
- " -0.686180 | \n",
- " 0.679145 | \n",
- " 0.392087 | \n",
- " ... | \n",
- " 0.265245 | \n",
- " 0.800049 | \n",
- " -0.163298 | \n",
- " 0.123205 | \n",
- " -0.569159 | \n",
- " 0.546668 | \n",
- " 0.108821 | \n",
- " 0.104533 | \n",
- " 10.00 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 284806 | \n",
- " 172792.0 | \n",
- " -0.533413 | \n",
- " -0.189733 | \n",
- " 0.703337 | \n",
- " -0.506271 | \n",
- " -0.012546 | \n",
- " -0.649617 | \n",
- " 1.577006 | \n",
- " -0.414650 | \n",
- " 0.486180 | \n",
- " ... | \n",
- " 0.261057 | \n",
- " 0.643078 | \n",
- " 0.376777 | \n",
- " 0.008797 | \n",
- " -0.473649 | \n",
- " -0.818267 | \n",
- " -0.002415 | \n",
- " 0.013649 | \n",
- " 217.00 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
284315 rows × 31 columns
\n",
- "
\n",
- "
\n",
- "
\n"
- ],
- "application/vnd.google.colaboratory.intrinsic+json": {
- "type": "dataframe",
- "variable_name": "legit"
- }
- },
- "metadata": {},
- "execution_count": 13
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "fraud"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 443
- },
- "id": "NWPiqg01ijtY",
- "outputId": "5a02a532-0fc5-44bf-c940-399111636f96"
- },
- "execution_count": 14,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " Time V1 V2 V3 V4 V5 V6 \\\n",
- "541 406.0 -2.312227 1.951992 -1.609851 3.997906 -0.522188 -1.426545 \n",
- "623 472.0 -3.043541 -3.157307 1.088463 2.288644 1.359805 -1.064823 \n",
- "4920 4462.0 -2.303350 1.759247 -0.359745 2.330243 -0.821628 -0.075788 \n",
- "6108 6986.0 -4.397974 1.358367 -2.592844 2.679787 -1.128131 -1.706536 \n",
- "6329 7519.0 1.234235 3.019740 -4.304597 4.732795 3.624201 -1.357746 \n",
- "... ... ... ... ... ... ... ... \n",
- "279863 169142.0 -1.927883 1.125653 -4.518331 1.749293 -1.566487 -2.010494 \n",
- "280143 169347.0 1.378559 1.289381 -5.004247 1.411850 0.442581 -1.326536 \n",
- "280149 169351.0 -0.676143 1.126366 -2.213700 0.468308 -1.120541 -0.003346 \n",
- "281144 169966.0 -3.113832 0.585864 -5.399730 1.817092 -0.840618 -2.943548 \n",
- "281674 170348.0 1.991976 0.158476 -2.583441 0.408670 1.151147 -0.096695 \n",
- "\n",
- " V7 V8 V9 ... V21 V22 V23 \\\n",
- "541 -2.537387 1.391657 -2.770089 ... 0.517232 -0.035049 -0.465211 \n",
- "623 0.325574 -0.067794 -0.270953 ... 0.661696 0.435477 1.375966 \n",
- "4920 0.562320 -0.399147 -0.238253 ... -0.294166 -0.932391 0.172726 \n",
- "6108 -3.496197 -0.248778 -0.247768 ... 0.573574 0.176968 -0.436207 \n",
- "6329 1.713445 -0.496358 -1.282858 ... -0.379068 -0.704181 -0.656805 \n",
- "... ... ... ... ... ... ... ... \n",
- "279863 -0.882850 0.697211 -2.064945 ... 0.778584 -0.319189 0.639419 \n",
- "280143 -1.413170 0.248525 -1.127396 ... 0.370612 0.028234 -0.145640 \n",
- "280149 -2.234739 1.210158 -0.652250 ... 0.751826 0.834108 0.190944 \n",
- "281144 -2.208002 1.058733 -1.632333 ... 0.583276 -0.269209 -0.456108 \n",
- "281674 0.223050 -0.068384 0.577829 ... -0.164350 -0.295135 -0.072173 \n",
- "\n",
- " V24 V25 V26 V27 V28 Amount Class \n",
- "541 0.320198 0.044519 0.177840 0.261145 -0.143276 0.00 1 \n",
- "623 -0.293803 0.279798 -0.145362 -0.252773 0.035764 529.00 1 \n",
- "4920 -0.087330 -0.156114 -0.542628 0.039566 -0.153029 239.93 1 \n",
- "6108 -0.053502 0.252405 -0.657488 -0.827136 0.849573 59.00 1 \n",
- "6329 -1.632653 1.488901 0.566797 -0.010016 0.146793 1.00 1 \n",
- "... ... ... ... ... ... ... ... \n",
- "279863 -0.294885 0.537503 0.788395 0.292680 0.147968 390.00 1 \n",
- "280143 -0.081049 0.521875 0.739467 0.389152 0.186637 0.76 1 \n",
- "280149 0.032070 -0.739695 0.471111 0.385107 0.194361 77.89 1 \n",
- "281144 -0.183659 -0.328168 0.606116 0.884876 -0.253700 245.00 1 \n",
- "281674 -0.450261 0.313267 -0.289617 0.002988 -0.015309 42.53 1 \n",
- "\n",
- "[492 rows x 31 columns]"
- ],
- "text/html": [
- "\n",
- " \n",
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Time | \n",
- " V1 | \n",
- " V2 | \n",
- " V3 | \n",
- " V4 | \n",
- " V5 | \n",
- " V6 | \n",
- " V7 | \n",
- " V8 | \n",
- " V9 | \n",
- " ... | \n",
- " V21 | \n",
- " V22 | \n",
- " V23 | \n",
- " V24 | \n",
- " V25 | \n",
- " V26 | \n",
- " V27 | \n",
- " V28 | \n",
- " Amount | \n",
- " Class | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 541 | \n",
- " 406.0 | \n",
- " -2.312227 | \n",
- " 1.951992 | \n",
- " -1.609851 | \n",
- " 3.997906 | \n",
- " -0.522188 | \n",
- " -1.426545 | \n",
- " -2.537387 | \n",
- " 1.391657 | \n",
- " -2.770089 | \n",
- " ... | \n",
- " 0.517232 | \n",
- " -0.035049 | \n",
- " -0.465211 | \n",
- " 0.320198 | \n",
- " 0.044519 | \n",
- " 0.177840 | \n",
- " 0.261145 | \n",
- " -0.143276 | \n",
- " 0.00 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 623 | \n",
- " 472.0 | \n",
- " -3.043541 | \n",
- " -3.157307 | \n",
- " 1.088463 | \n",
- " 2.288644 | \n",
- " 1.359805 | \n",
- " -1.064823 | \n",
- " 0.325574 | \n",
- " -0.067794 | \n",
- " -0.270953 | \n",
- " ... | \n",
- " 0.661696 | \n",
- " 0.435477 | \n",
- " 1.375966 | \n",
- " -0.293803 | \n",
- " 0.279798 | \n",
- " -0.145362 | \n",
- " -0.252773 | \n",
- " 0.035764 | \n",
- " 529.00 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 4920 | \n",
- " 4462.0 | \n",
- " -2.303350 | \n",
- " 1.759247 | \n",
- " -0.359745 | \n",
- " 2.330243 | \n",
- " -0.821628 | \n",
- " -0.075788 | \n",
- " 0.562320 | \n",
- " -0.399147 | \n",
- " -0.238253 | \n",
- " ... | \n",
- " -0.294166 | \n",
- " -0.932391 | \n",
- " 0.172726 | \n",
- " -0.087330 | \n",
- " -0.156114 | \n",
- " -0.542628 | \n",
- " 0.039566 | \n",
- " -0.153029 | \n",
- " 239.93 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 6108 | \n",
- " 6986.0 | \n",
- " -4.397974 | \n",
- " 1.358367 | \n",
- " -2.592844 | \n",
- " 2.679787 | \n",
- " -1.128131 | \n",
- " -1.706536 | \n",
- " -3.496197 | \n",
- " -0.248778 | \n",
- " -0.247768 | \n",
- " ... | \n",
- " 0.573574 | \n",
- " 0.176968 | \n",
- " -0.436207 | \n",
- " -0.053502 | \n",
- " 0.252405 | \n",
- " -0.657488 | \n",
- " -0.827136 | \n",
- " 0.849573 | \n",
- " 59.00 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 6329 | \n",
- " 7519.0 | \n",
- " 1.234235 | \n",
- " 3.019740 | \n",
- " -4.304597 | \n",
- " 4.732795 | \n",
- " 3.624201 | \n",
- " -1.357746 | \n",
- " 1.713445 | \n",
- " -0.496358 | \n",
- " -1.282858 | \n",
- " ... | \n",
- " -0.379068 | \n",
- " -0.704181 | \n",
- " -0.656805 | \n",
- " -1.632653 | \n",
- " 1.488901 | \n",
- " 0.566797 | \n",
- " -0.010016 | \n",
- " 0.146793 | \n",
- " 1.00 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " 279863 | \n",
- " 169142.0 | \n",
- " -1.927883 | \n",
- " 1.125653 | \n",
- " -4.518331 | \n",
- " 1.749293 | \n",
- " -1.566487 | \n",
- " -2.010494 | \n",
- " -0.882850 | \n",
- " 0.697211 | \n",
- " -2.064945 | \n",
- " ... | \n",
- " 0.778584 | \n",
- " -0.319189 | \n",
- " 0.639419 | \n",
- " -0.294885 | \n",
- " 0.537503 | \n",
- " 0.788395 | \n",
- " 0.292680 | \n",
- " 0.147968 | \n",
- " 390.00 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 280143 | \n",
- " 169347.0 | \n",
- " 1.378559 | \n",
- " 1.289381 | \n",
- " -5.004247 | \n",
- " 1.411850 | \n",
- " 0.442581 | \n",
- " -1.326536 | \n",
- " -1.413170 | \n",
- " 0.248525 | \n",
- " -1.127396 | \n",
- " ... | \n",
- " 0.370612 | \n",
- " 0.028234 | \n",
- " -0.145640 | \n",
- " -0.081049 | \n",
- " 0.521875 | \n",
- " 0.739467 | \n",
- " 0.389152 | \n",
- " 0.186637 | \n",
- " 0.76 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 280149 | \n",
- " 169351.0 | \n",
- " -0.676143 | \n",
- " 1.126366 | \n",
- " -2.213700 | \n",
- " 0.468308 | \n",
- " -1.120541 | \n",
- " -0.003346 | \n",
- " -2.234739 | \n",
- " 1.210158 | \n",
- " -0.652250 | \n",
- " ... | \n",
- " 0.751826 | \n",
- " 0.834108 | \n",
- " 0.190944 | \n",
- " 0.032070 | \n",
- " -0.739695 | \n",
- " 0.471111 | \n",
- " 0.385107 | \n",
- " 0.194361 | \n",
- " 77.89 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 281144 | \n",
- " 169966.0 | \n",
- " -3.113832 | \n",
- " 0.585864 | \n",
- " -5.399730 | \n",
- " 1.817092 | \n",
- " -0.840618 | \n",
- " -2.943548 | \n",
- " -2.208002 | \n",
- " 1.058733 | \n",
- " -1.632333 | \n",
- " ... | \n",
- " 0.583276 | \n",
- " -0.269209 | \n",
- " -0.456108 | \n",
- " -0.183659 | \n",
- " -0.328168 | \n",
- " 0.606116 | \n",
- " 0.884876 | \n",
- " -0.253700 | \n",
- " 245.00 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- " 281674 | \n",
- " 170348.0 | \n",
- " 1.991976 | \n",
- " 0.158476 | \n",
- " -2.583441 | \n",
- " 0.408670 | \n",
- " 1.151147 | \n",
- " -0.096695 | \n",
- " 0.223050 | \n",
- " -0.068384 | \n",
- " 0.577829 | \n",
- " ... | \n",
- " -0.164350 | \n",
- " -0.295135 | \n",
- " -0.072173 | \n",
- " -0.450261 | \n",
- " 0.313267 | \n",
- " -0.289617 | \n",
- " 0.002988 | \n",
- " -0.015309 | \n",
- " 42.53 | \n",
- " 1 | \n",
- "
\n",
- " \n",
- "
\n",
- "
492 rows × 31 columns
\n",
- "
\n",
- "
\n",
- "
\n"
- ],
- "application/vnd.google.colaboratory.intrinsic+json": {
- "type": "dataframe",
- "variable_name": "fraud"
- }
- },
- "metadata": {},
- "execution_count": 14
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "legit.shape"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "uUeLjBzJij16",
- "outputId": "3d6804aa-21ee-448e-b2ae-4e7cc87a9805"
- },
- "execution_count": 15,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "(284315, 31)"
- ]
- },
- "metadata": {},
- "execution_count": 15
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "fraud.shape"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "b3ZBMilnj4O0",
- "outputId": "55551a02-9769-4c48-e08e-b7838164d2b5"
- },
- "execution_count": 16,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "(492, 31)"
- ]
- },
- "metadata": {},
- "execution_count": 16
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "legit_s=legit.sample(n=492)\n",
- "data=pd.concat([legit_s,fraud],axis=0)\n"
- ],
- "metadata": {
- "id": "s0lx5ll0j4Tn"
- },
- "execution_count": 17,
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "data.shape"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "UkxKUtyYj4aY",
- "outputId": "9b87f275-4926-4e54-857f-dccb0945da11"
- },
- "execution_count": 18,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "(984, 31)"
- ]
- },
- "metadata": {},
- "execution_count": 18
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "data['Class'].value_counts()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 178
- },
- "id": "BJ5HcAJCj4eG",
- "outputId": "46a8d581-a79c-446e-a869-122c5e7cefa6"
- },
- "execution_count": 19,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "Class\n",
- "0 492\n",
- "1 492\n",
- "Name: count, dtype: int64"
- ],
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " count | \n",
- "
\n",
- " \n",
- " Class | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 492 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 492 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ]
- },
- "metadata": {},
- "execution_count": 19
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "data.groupby('Class').mean()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 193
- },
- "id": "LXYEdIsAk-N1",
- "outputId": "2959e942-e217-488c-b3df-c55034385fc9"
- },
- "execution_count": 20,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- " Time V1 V2 V3 V4 V5 \\\n",
- "Class \n",
- "0 96841.701220 0.047145 -0.045274 0.018299 -0.028750 -0.028220 \n",
- "1 80746.806911 -4.771948 3.623778 -7.033281 4.542029 -3.151225 \n",
- "\n",
- " V6 V7 V8 V9 ... V20 V21 \\\n",
- "Class ... \n",
- "0 0.061239 0.124701 0.012802 0.037197 ... 0.015074 -0.013212 \n",
- "1 -1.397737 -5.568731 0.570636 -2.581123 ... 0.372319 0.713588 \n",
- "\n",
- " V22 V23 V24 V25 V26 V27 V28 \\\n",
- "Class \n",
- "0 -0.034433 0.048324 -0.00221 0.004126 0.006488 -0.022973 -0.016320 \n",
- "1 0.014049 -0.040308 -0.10513 0.041449 0.051648 0.170575 0.075667 \n",
- "\n",
- " Amount \n",
- "Class \n",
- "0 105.675793 \n",
- "1 122.211321 \n",
- "\n",
- "[2 rows x 30 columns]"
- ],
- "text/html": [
- "\n",
- " \n",
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Time | \n",
- " V1 | \n",
- " V2 | \n",
- " V3 | \n",
- " V4 | \n",
- " V5 | \n",
- " V6 | \n",
- " V7 | \n",
- " V8 | \n",
- " V9 | \n",
- " ... | \n",
- " V20 | \n",
- " V21 | \n",
- " V22 | \n",
- " V23 | \n",
- " V24 | \n",
- " V25 | \n",
- " V26 | \n",
- " V27 | \n",
- " V28 | \n",
- " Amount | \n",
- "
\n",
- " \n",
- " Class | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- " | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 96841.701220 | \n",
- " 0.047145 | \n",
- " -0.045274 | \n",
- " 0.018299 | \n",
- " -0.028750 | \n",
- " -0.028220 | \n",
- " 0.061239 | \n",
- " 0.124701 | \n",
- " 0.012802 | \n",
- " 0.037197 | \n",
- " ... | \n",
- " 0.015074 | \n",
- " -0.013212 | \n",
- " -0.034433 | \n",
- " 0.048324 | \n",
- " -0.00221 | \n",
- " 0.004126 | \n",
- " 0.006488 | \n",
- " -0.022973 | \n",
- " -0.016320 | \n",
- " 105.675793 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 80746.806911 | \n",
- " -4.771948 | \n",
- " 3.623778 | \n",
- " -7.033281 | \n",
- " 4.542029 | \n",
- " -3.151225 | \n",
- " -1.397737 | \n",
- " -5.568731 | \n",
- " 0.570636 | \n",
- " -2.581123 | \n",
- " ... | \n",
- " 0.372319 | \n",
- " 0.713588 | \n",
- " 0.014049 | \n",
- " -0.040308 | \n",
- " -0.10513 | \n",
- " 0.041449 | \n",
- " 0.051648 | \n",
- " 0.170575 | \n",
- " 0.075667 | \n",
- " 122.211321 | \n",
- "
\n",
- " \n",
- "
\n",
- "
2 rows × 30 columns
\n",
- "
\n",
- "
\n",
- "
\n"
- ],
- "application/vnd.google.colaboratory.intrinsic+json": {
- "type": "dataframe"
- }
- },
- "metadata": {},
- "execution_count": 20
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "x=data.drop('Class',axis=1)\n",
- "y=data['Class']"
- ],
- "metadata": {
- "id": "oS9EL437k-RD"
- },
- "execution_count": 21,
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "x.shape"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "173lxqaYk-T0",
- "outputId": "7129c9f5-a4f9-47c7-dacc-32e96c2959d2"
- },
- "execution_count": 22,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "(984, 30)"
- ]
- },
- "metadata": {},
- "execution_count": 22
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "y.shape"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "eLd3clgFk-Xh",
- "outputId": "ea5f1d59-1fc8-44a8-bf61-473af6bdf226"
- },
- "execution_count": 23,
- "outputs": [
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "(984,)"
- ]
- },
- "metadata": {},
- "execution_count": 23
- }
- ]
- },
- {
- "cell_type": "code",
- "source": [
- "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,stratify=y,random_state=2)"
- ],
- "metadata": {
- "id": "-ns-kvj0lfsF"
- },
- "execution_count": 24,
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "model=LogisticRegression()\n",
- "model.fit(x_train,y_train)\n",
- "ypred=model.predict(x_test)\n",
- "accuracy_score(y_test,ypred)"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/"
- },
- "id": "wn2fxiwplfuv",
- "outputId": "5a6146c5-3ce2-44fd-fb17-56dba4f8323b"
- },
- "execution_count": 25,
- "outputs": [
- {
- "output_type": "stream",
- "name": "stderr",
- "text": [
- "/usr/local/lib/python3.10/dist-packages/sklearn/linear_model/_logistic.py:465: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
- "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
- "\n",
- "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
- " https://scikit-learn.org/stable/modules/preprocessing.html\n",
- "Please also refer to the documentation for alternative solver options:\n",
- " https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
- " n_iter_i = _check_optimize_result(\n"
- ]
- },
- {
- "output_type": "execute_result",
- "data": {
- "text/plain": [
- "0.949238578680203"
- ]
- },
- "metadata": {},
- "execution_count": 25
- }
- ]
- },
- {
- "cell_type": "markdown",
- "source": [
- "## Data Visualization"
- ],
- "metadata": {
- "id": "FRnVqs60vUyp"
- }
- },
- {
- "cell_type": "code",
- "source": [
- "import matplotlib.pyplot as plt\n",
- "import seaborn as sns\n",
- "\n",
- "# Set the style\n",
- "sns.set(style=\"whitegrid\")\n",
- "\n",
- "# Plot the distribution of the 'Class' variable (fraudulent vs. non-fraudulent transactions)\n",
- "plt.figure(figsize=(8, 5))\n",
- "sns.countplot(x='Class', data=data)\n",
- "plt.title('Distribution of Fraudulent and Non-Fraudulent Transactions')\n",
- "plt.xlabel('Class (0: Non-Fraud, 1: Fraud)')\n",
- "plt.ylabel('Number of Transactions')\n",
- "plt.show()"
- ],
- "metadata": {
- "colab": {
- "base_uri": "https://localhost:8080/",
- "height": 496
- },
- "id": "xp0SxKoBvUjW",
- "outputId": "e2377079-5ee7-4b77-8468-f5d0afd09ca2"
- },
- "execution_count": 26,
- "outputs": [
- {
- "output_type": "display_data",
- "data": {
- "text/plain": [
- "