{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
" "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "C1LAAic_C1Lt"
},
"source": [
"# Clasificación\n",
"\n",
"## Práctica"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "zI4khfezCNJZ"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from sklearn import preprocessing\n",
"import matplotlib.pyplot as plt \n",
"plt.rc(\"font\", size=14)\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.model_selection import train_test_split\n",
"import seaborn as sns\n",
"sns.set(style=\"white\")\n",
"sns.set(style=\"whitegrid\", color_codes=True)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KC8azJ77DEcE"
},
"source": [
"El dataset contiene datos relacionados con las campañas de marketing dirigidas (llamadas telefónicas) de una entidad bancaria portuguesa. El objetivo de la clasificación es predecir si el cliente suscribirá (1/0) un depósito a plazo (variable y)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "uKg2Cc3oCzkq"
},
"outputs": [],
"source": [
"data = pd.read_csv('https://raw.githubusercontent.com/madmashup/targeted-marketing-predictive-engine/master/banking.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "apZho91aDatY"
},
"source": [
"El conjunto de datos proporciona la información de los clientes del banco. Incluye 41.188 registros y 21 campos."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "SodO6-7uC2hA",
"outputId": "59f808d0-1783-451c-c0ba-d92ddac992d1"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(41188, 21)\n",
"Index(['age', 'job', 'marital', 'education', 'default', 'housing', 'loan',\n",
" 'contact', 'month', 'day_of_week', 'duration', 'campaign', 'pdays',\n",
" 'previous', 'poutcome', 'emp_var_rate', 'cons_price_idx',\n",
" 'cons_conf_idx', 'euribor3m', 'nr_employed', 'y'],\n",
" dtype='object')\n"
]
}
],
"source": [
"data = data.dropna()\n",
"print(data.shape)\n",
"print(data.columns)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 235
},
"id": "Nb4sPjRTDS6d",
"outputId": "2472fb8c-31df-489f-d304-98bb3507827a"
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n", " | age | \n", "job | \n", "marital | \n", "education | \n", "default | \n", "housing | \n", "loan | \n", "contact | \n", "month | \n", "day_of_week | \n", "... | \n", "campaign | \n", "pdays | \n", "previous | \n", "poutcome | \n", "emp_var_rate | \n", "cons_price_idx | \n", "cons_conf_idx | \n", "euribor3m | \n", "nr_employed | \n", "y | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "44 | \n", "blue-collar | \n", "married | \n", "basic.4y | \n", "unknown | \n", "yes | \n", "no | \n", "cellular | \n", "aug | \n", "thu | \n", "... | \n", "1 | \n", "999 | \n", "0 | \n", "nonexistent | \n", "1.4 | \n", "93.444 | \n", "-36.1 | \n", "4.963 | \n", "5228.1 | \n", "0 | \n", "
1 | \n", "53 | \n", "technician | \n", "married | \n", "unknown | \n", "no | \n", "no | \n", "no | \n", "cellular | \n", "nov | \n", "fri | \n", "... | \n", "1 | \n", "999 | \n", "0 | \n", "nonexistent | \n", "-0.1 | \n", "93.200 | \n", "-42.0 | \n", "4.021 | \n", "5195.8 | \n", "0 | \n", "
2 | \n", "28 | \n", "management | \n", "single | \n", "university.degree | \n", "no | \n", "yes | \n", "no | \n", "cellular | \n", "jun | \n", "thu | \n", "... | \n", "3 | \n", "6 | \n", "2 | \n", "success | \n", "-1.7 | \n", "94.055 | \n", "-39.8 | \n", "0.729 | \n", "4991.6 | \n", "1 | \n", "
3 rows × 21 columns
\n", "\n", " | age | \n", "duration | \n", "campaign | \n", "pdays | \n", "previous | \n", "emp_var_rate | \n", "cons_price_idx | \n", "cons_conf_idx | \n", "euribor3m | \n", "nr_employed | \n", "
---|---|---|---|---|---|---|---|---|---|---|
y | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
0 | \n", "39.911185 | \n", "220.844807 | \n", "2.633085 | \n", "984.113878 | \n", "0.132374 | \n", "0.248875 | \n", "93.603757 | \n", "-40.593097 | \n", "3.811491 | \n", "5176.166600 | \n", "
1 | \n", "40.913147 | \n", "553.191164 | \n", "2.051724 | \n", "792.035560 | \n", "0.492672 | \n", "-1.233448 | \n", "93.354386 | \n", "-39.789784 | \n", "2.123135 | \n", "5095.115991 | \n", "