{ "cells": [ { "cell_type": "markdown", "id": "eafb1be2", "metadata": {}, "source": [ "# Seleccion de variables mediante la Entropia de Shannon\n", "## 1. Introduccion\n", "
No siempre es obvia la cantidad de información que aporta un atributo al resultado de la variable objetivo. Aquí vamos a ver un método relativamente sencillo de medirlo.
\n", "Es un muy buen método para obtener relación entre variables independientes con respecto a la variable objetivo. Usa conceptos de Entropía de termodinámica aplicada a la información (Shannon, 1948). Puede obtenerse un ranking ordenado de las variables según cuán fuerte es su aporte de información hacia la variable objetivo. Y se usa como un metodo alternativo al calculo de las correlaciones estadisticas.
\n", "En este trabajo se presenta un ejemplo del uso de la entropia de Shannon para la selección de variables a partir del dataset público del hundimiento del Titanic: titanic.csv basado en la informacion presentada en el sitio del Laberinto de Falken: https://www.ellaberintodefalken.com/2018/09/seleccion-atributos-relevantes-entropia-shannon.html
" ] }, { "cell_type": "markdown", "id": "6494f268", "metadata": {}, "source": [ "### Carga de Librerias y Datos" ] }, { "cell_type": "code", "execution_count": 51, "id": "5d70187f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "tamaño del dataset: (2201, 5)\n", "['passenger_number', 'Class', 'Sex', 'Age', 'Survived']\n", "Eliminacion de columna 'passenger_number':\n", " Class Sex Age Survived\n", "0 2nd Male Adult No\n", "1 3rd Male Child No\n", "2 3rd Male Adult No\n", "3 Crew Male Adult No\n", "4 Crew Male Adult No\n", "... ... ... ... ...\n", "2196 Crew Male Adult No\n", "2197 Crew Male Adult Yes\n", "2198 3rd Male Adult No\n", "2199 Crew Male Adult No\n", "2200 1st Male Adult No\n", "\n", "[2201 rows x 4 columns]\n" ] } ], "source": [ "# Librerias\n", "import pandas as pd\n", "import requests\n", "import numpy as np\n", "import math\n", "import os\n", "\n", "# Datos\n", "link=\"https://rudeboybert.github.io/SDS220/static/PS/titanic.csv\"\n", "data=pd.read_csv(link)\n", "\n", "# Acerca del Dataset:\n", "print(\"tamaño del dataset:\",data.shape)\n", "\n", "# Eliminaremos la variable 'passengerId' y 'Name'\n", "columnas=data.columns.tolist()\n", "print(columnas)\n", "columnasAeliminar=[\"passenger_number\"]\n", "df=data.drop(columnasAeliminar, axis=1)\n", "print(\"Eliminacion de columna 'passenger_number':\")\n", "print(df)" ] }, { "cell_type": "markdown", "id": "77a262d4", "metadata": {}, "source": [ "## 2. Las variables\n", "### 2.1. Variables" ] }, { "cell_type": "code", "execution_count": 52, "id": "010024c8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Variables= ['Class', 'Sex', 'Age', 'Survived']\n", "valores de Class = {'3rd', 'Crew', '1st', '2nd'}\n", "valores de Sex = {'Male', 'Female'}\n", "valores de Age = {'Adult', 'Child'}\n", "valores de Survived = {'No', 'Yes'}\n" ] } ], "source": [ "# Las variables\n", "print(\"Variables=\",df.columns.tolist())\n", "# Valores de cada variable:\n", "for i in range(df.shape[1]):\n", " print(\"valores de \",df.columns.tolist()[i],\"=\",set(list(df.iloc[:,i])))" ] }, { "cell_type": "code", "execution_count": 53, "id": "e997a20d", "metadata": {}, "outputs": [], "source": [ "# Binarizaremos la variable objetivo \"survived\" (reemplazar 'si' / 'no' por 1 / 0):\n", "df[\"Survived\"] = df[\"Survived\"].replace({ \"Yes\": 1, \"No\": 0 })" ] }, { "cell_type": "markdown", "id": "e1fe8960", "metadata": {}, "source": [ "### 2.2. Variables dependientes e independientes" ] }, { "cell_type": "code", "execution_count": 54, "id": "044c31da", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "vars_indep= ['Class', 'Sex', 'Age']\n", "vars_target= Survived\n" ] } ], "source": [ "cols=df.columns.tolist()\n", "vars_indep=cols[:len(cols)-1]\n", "vars_target=cols[len(cols)-1]\n", "# Variables independientes:\n", "print(\"vars_indep=\",vars_indep)\n", "# Variables targets:\n", "print(\"vars_target=\",vars_target)" ] }, { "attachments": { "entropia01.png": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVEAAABTCAIAAACpq6OqAAAAA3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y2gnn5VVSCjICQ5aA4B6cmO1AISEvMKfctVWCpX7cqfzrlek+WqPLc0leIoV9+LqqRMXHkblkQgwCUvbwQ3vVqBpHjAxWcXmNW8ypBTlGjijWe9H06KUfDq5ZPXN9K4zPA9Mq5XwoUlukaojAAACDklEQVRQnIL0xC+R4cHv/Xxfvv+cxfmeGgLv0M9uYIs7/Wh+J7Tm/xT4Kd7rXI6GFjM6S2X8t3PNrbp1ib5vJaNQpQ2ZIkmS5HLYbFZhfm5OTk5+Mbd2BhgAXHaQXaOD42n+TGjN/xGg/Lf/OG97mkkiIFODHqW20G0IZZtRFo1NLE7zh0Jr/g8A5T3asfZaAhfDsAYSK9UFVjVZWJ3/IbqMsKsZqEnT5vh/2u1paGh+P7SBloamfUFrnoamfUFrnoamfUFrnoamfUFrnoamfUFrvq2DeFw+7Zqh+QGt+TYNmXBpTn+zQRtf1szDRNN+oTXfpiFzM3NxZWMTTTrShuY7dEwODU37gh7naWjaF7Tm2yglkZeXTRptO2zsmtsJTf8mH00bhtZ8WwTlP999IHHM0cvL9VMeHK/40hgNDQDQmm+TkF9vXSsZs7CP1OcPYaWMzioCPoxG036h99K2QXBZ6xUr/+pY6u/9OF2k14IhyrTmaX5Aa74NgnXU6A6o6LH38zyJvvaD5Om8NzRVoEeANgrKfe79urjjQLv+0ryshOQi2iNLUwGt+bYJlf74zgeO4lB7K7GcBzt2Ps0R8BFDmvYJrfm2CZWZms6TMOttUPzuxEOZaWO6tpf0/zQNQsfhtVG4sf+uWu6VKt+VOXTx6olMCXpNT1MBrXkamvYFPbenoWlf0JqnoWlf/A/WPRhWrIQzwAAAAABJRU5ErkJggg==" } }, "cell_type": "markdown", "id": "4fda7e65", "metadata": {}, "source": [ "## 3. La entropia de Shannon\n", "### 3.1. Definición de Entropia\n", "La entropía es una medida del desorden de un conjunto datos, y se define como:\n", "![entropia01.png](attachment:entropia01.png)\n", "Donde pi es la probabilidad relativa de aparición de la propiedad i en el conjunto de datos. Por ejemplo, p1 podría ser la probabilidad de tener cáncer de pulmón y p2 la probabilidad de no tenerlo." ] }, { "cell_type": "markdown", "id": "10dfb9ed", "metadata": {}, "source": [ "### 3.2. Cálculo de la entropía\n", "Lo que nos dice este valor es la medida de desorden de la variable explicada con un valor que va de 0 a 1. Un valor de 0 indica orden total, o lo que es lo mismo, o todos sobrevivieron o todos murieron, pero todos los valores son iguales. Cuanto más cerca esté de 1, mayor desorden. Un valor 1 querría decir que el 50% de pasajeros murieron y el otro 50% sobrevivió (hay que tener en cuenta que la entropía no es una función lineal).