{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "from sklearn.tree import DecisionTreeClassifier\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.ensemble import RandomForestClassifier\n", "from sklearn.model_selection import GridSearchCV\n", "from sklearn.metrics import accuracy_score, confusion_matrix, classification_report, ConfusionMatrixDisplay\n", "from sklearn.ensemble import GradientBoostingClassifier" ], "metadata": { "id": "pTNV9noRtUNZ" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "df = pd.read_csv('creditcard.csv')" ], "metadata": { "id": "gFE_sJ7fuJMt" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "df.head()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 256 }, "id": "QOWHOnn3uURp", "outputId": "7f40f75f-ebcf-44c7-f81e-49f4f2296028" }, "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Time V1 V2 V3 V4 V5 V6 V7 \\\n", "0 0 -1.359807 -0.072781 2.536347 1.378155 -0.338321 0.462388 0.239599 \n", "1 0 1.191857 0.266151 0.166480 0.448154 0.060018 -0.082361 -0.078803 \n", "2 1 -1.358354 -1.340163 1.773209 0.379780 -0.503198 1.800499 0.791461 \n", "3 1 -0.966272 -0.185226 1.792993 -0.863291 -0.010309 1.247203 0.237609 \n", "4 2 -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.0 \n", "1 0.125895 -0.008983 0.014724 2.69 0.0 \n", "2 -0.139097 -0.055353 -0.059752 378.66 0.0 \n", "3 -0.221929 0.062723 0.061458 123.50 0.0 \n", "4 0.502292 0.219422 0.215153 69.99 0.0 \n", "\n", "[5 rows x 31 columns]" ], "text/html": [ "\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", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "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.0 | \n", "
1 | \n", "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.0 | \n", "
2 | \n", "1 | \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.0 | \n", "
3 | \n", "1 | \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.0 | \n", "
4 | \n", "2 | \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.0 | \n", "
5 rows × 31 columns
\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", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
count | \n", "87240.000000 | \n", "87240.000000 | \n", "87240.000000 | \n", "87240.000000 | \n", "87240.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "... | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "87239.000000 | \n", "
mean | \n", "39208.302212 | \n", "-0.264415 | \n", "-0.039672 | \n", "0.679463 | \n", "0.163042 | \n", "-0.277593 | \n", "0.094179 | \n", "-0.110135 | \n", "0.054041 | \n", "-0.025376 | \n", "... | \n", "-0.029472 | \n", "-0.106031 | \n", "-0.037054 | \n", "0.009686 | \n", "0.132652 | \n", "0.026722 | \n", "0.000801 | \n", "0.002105 | \n", "98.400990 | \n", "0.002350 | \n", "
std | \n", "15846.338289 | \n", "1.876993 | \n", "1.667305 | \n", "1.359385 | \n", "1.360959 | \n", "1.372054 | \n", "1.302524 | \n", "1.233574 | \n", "1.217704 | \n", "1.131867 | \n", "... | \n", "0.729483 | \n", "0.635050 | \n", "0.624121 | \n", "0.594797 | \n", "0.441065 | \n", "0.496992 | \n", "0.390442 | \n", "0.327910 | \n", "267.389535 | \n", "0.048419 | \n", "
min | \n", "0.000000 | \n", "-56.407510 | \n", "-72.715728 | \n", "-33.680984 | \n", "-5.172595 | \n", "-42.147898 | \n", "-26.160506 | \n", "-31.764946 | \n", "-73.216718 | \n", "-9.283925 | \n", "... | \n", "-34.830382 | \n", "-10.933144 | \n", "-26.751119 | \n", "-2.836627 | \n", "-7.495741 | \n", "-2.534330 | \n", "-9.390980 | \n", "-9.617915 | \n", "0.000000 | \n", "0.000000 | \n", "
25% | \n", "31867.750000 | \n", "-1.028026 | \n", "-0.603069 | \n", "0.184406 | \n", "-0.720243 | \n", "-0.897262 | \n", "-0.645804 | \n", "-0.602405 | \n", "-0.140723 | \n", "-0.691868 | \n", "... | \n", "-0.223746 | \n", "-0.525484 | \n", "-0.177939 | \n", "-0.321974 | \n", "-0.131957 | \n", "-0.326135 | \n", "-0.063559 | \n", "-0.005877 | \n", "7.680000 | \n", "0.000000 | \n", "
50% | \n", "41579.000000 | \n", "-0.261473 | \n", "0.070422 | \n", "0.762151 | \n", "0.186247 | \n", "-0.312307 | \n", "-0.155825 | \n", "-0.071350 | \n", "0.070699 | \n", "-0.100498 | \n", "... | \n", "-0.057635 | \n", "-0.081403 | \n", "-0.049749 | \n", "0.065023 | \n", "0.171178 | \n", "-0.071981 | \n", "0.009300 | \n", "0.023036 | \n", "26.990000 | \n", "0.000000 | \n", "
75% | \n", "51578.500000 | \n", "1.152808 | \n", "0.726160 | \n", "1.389214 | \n", "1.039812 | \n", "0.256678 | \n", "0.488780 | \n", "0.417652 | \n", "0.353244 | \n", "0.595250 | \n", "... | \n", "0.118528 | \n", "0.309661 | \n", "0.080971 | \n", "0.406151 | \n", "0.420203 | \n", "0.306278 | \n", "0.082638 | \n", "0.076227 | \n", "89.900000 | \n", "0.000000 | \n", "
max | \n", "61596.000000 | \n", "1.960497 | \n", "18.902453 | \n", "4.226108 | \n", "16.715537 | \n", "34.801666 | \n", "22.529298 | \n", "36.677268 | \n", "20.007208 | \n", "10.392889 | \n", "... | \n", "22.614889 | \n", "10.503090 | \n", "18.946734 | \n", "4.014444 | \n", "5.525093 | \n", "3.517346 | \n", "12.152401 | \n", "33.847808 | \n", "19656.530000 | \n", "1.000000 | \n", "
8 rows × 31 columns
\n", "