0% found this document useful (0 votes)
15 views50 pages

Pregunta B

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views50 pages

Pregunta B

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 50

{

"nbformat": 4,

"nbformat_minor": 0,

"metadata": {

"colab": {

"provenance": [],

"toc_visible": true

},

"kernelspec": {

"name": "python3",

"display_name": "Python 3"

},

"language_info": {

"name": "python"

},

"cells": [

"cell_type": "code",

"source": [

"\n",

"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 import metrics\n",

"import sklearn\n",

"import joblib\n",

"\n",
"datos = pd.read_csv(\"titanic.csv\")\n",

"print(datos)"

],

"metadata": {

"id": "pJVtfeiiO97v",

"colab": {

"base_uri": "https://localhost:8080/"

},

"outputId": "62015fa4-6f87-4069-dfc1-ae5ab2d1681c"

},

"execution_count": 5,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

" Unnamed: 0 PassengerId Survived Pclass \\\n",

"0 1 1 0 3 \n",

"1 2 2 1 1 \n",

"2 3 3 1 3 \n",

"3 4 4 1 1 \n",

"4 5 5 0 3 \n",

"... ... ... ... ... \n",

"1304 1305 1305 0 3 \n",

"1305 1306 1306 1 1 \n",

"1306 1307 1307 0 3 \n",

"1307 1308 1308 0 3 \n",

"1308 1309 1309 0 3 \n",

"\n",
" Name Sex Age SibSp \\\n",

"0 Braund, Mr. Owen Harris male 22.0 1 \n",

"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",

"2 Heikkinen, Miss. Laina female 26.0 0 \n",

"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",

"4 Allen, Mr. William Henry male 35.0 0 \n",

"... ... ... ... ... \n",

"1304 Spector, Mr. Woolf male NaN 0 \n",

"1305 Oliva y Ocana, Dona. Fermina female 39.0 0 \n",

"1306 Saether, Mr. Simon Sivertsen male 38.5 0 \n",

"1307 Ware, Mr. Frederick male NaN 0 \n",

"1308 Peter, Master. Michael J male NaN 1 \n",

"\n",

" Parch Ticket Fare Cabin Embarked \n",

"0 0 A/5 21171 7.2500 NaN S \n",

"1 0 PC 17599 71.2833 C85 C \n",

"2 0 STON/O2. 3101282 7.9250 NaN S \n",

"3 0 113803 53.1000 C123 S \n",

"4 0 373450 8.0500 NaN S \n",

"... ... ... ... ... ... \n",

"1304 0 A.5. 3236 8.0500 NaN S \n",

"1305 0 PC 17758 108.9000 C105 C \n",

"1306 0 SOTON/O.Q. 3101262 7.2500 NaN S \n",

"1307 0 359309 8.0500 NaN S \n",

"1308 1 2668 22.3583 NaN C \n",

"\n",

"[1309 rows x 13 columns]\n"

}
]

},

"cell_type": "code",

"source": [

"datos.head()"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/",

"height": 449

},

"id": "UAszVV7AG_m0",

"outputId": "1dfa826f-e54e-4ac3-d993-08e10be32abe"

},

"execution_count": 6,

"outputs": [

"output_type": "execute_result",

"data": {

"text/plain": [

" Unnamed: 0 PassengerId Survived Pclass \\\n",

"0 1 1 0 3 \n",

"1 2 2 1 1 \n",

"2 3 3 1 3 \n",

"3 4 4 1 1 \n",

"4 5 5 0 3 \n",

"\n",

" Name Sex Age SibSp \\\n",


"0 Braund, Mr. Owen Harris male 22.0 1 \n",

"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",

"2 Heikkinen, Miss. Laina female 26.0 0 \n",

"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",

"4 Allen, Mr. William Henry male 35.0 0 \n",

"\n",

" Parch Ticket Fare Cabin Embarked \n",

"0 0 A/5 21171 7.2500 NaN S \n",

"1 0 PC 17599 71.2833 C85 C \n",

"2 0 STON/O2. 3101282 7.9250 NaN S \n",

"3 0 113803 53.1000 C123 S \n",

"4 0 373450 8.0500 NaN S "

],

"text/html": [

"\n",

" <div id=\"df-c31e3236-17fd-4f3d-88ef-f6ba5eeb5ce3\" class=\"colab-df-container\">\n",

" <div>\n",

"<style scoped>\n",

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",
"</style>\n",

"<table border=\"1\" class=\"dataframe\">\n",

" <thead>\n",

" <tr style=\"text-align: right;\">\n",

" <th></th>\n",

" <th>Unnamed: 0</th>\n",

" <th>PassengerId</th>\n",

" <th>Survived</th>\n",

" <th>Pclass</th>\n",

" <th>Name</th>\n",

" <th>Sex</th>\n",

" <th>Age</th>\n",

" <th>SibSp</th>\n",

" <th>Parch</th>\n",

" <th>Ticket</th>\n",

" <th>Fare</th>\n",

" <th>Cabin</th>\n",

" <th>Embarked</th>\n",

" </tr>\n",

" </thead>\n",

" <tbody>\n",

" <tr>\n",

" <th>0</th>\n",

" <td>1</td>\n",

" <td>1</td>\n",

" <td>0</td>\n",

" <td>3</td>\n",

" <td>Braund, Mr. Owen Harris</td>\n",

" <td>male</td>\n",
" <td>22.0</td>\n",

" <td>1</td>\n",

" <td>0</td>\n",

" <td>A/5 21171</td>\n",

" <td>7.2500</td>\n",

" <td>NaN</td>\n",

" <td>S</td>\n",

" </tr>\n",

" <tr>\n",

" <th>1</th>\n",

" <td>2</td>\n",

" <td>2</td>\n",

" <td>1</td>\n",

" <td>1</td>\n",

" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",

" <td>female</td>\n",

" <td>38.0</td>\n",

" <td>1</td>\n",

" <td>0</td>\n",

" <td>PC 17599</td>\n",

" <td>71.2833</td>\n",

" <td>C85</td>\n",

" <td>C</td>\n",

" </tr>\n",

" <tr>\n",

" <th>2</th>\n",

" <td>3</td>\n",

" <td>3</td>\n",

" <td>1</td>\n",
" <td>3</td>\n",

" <td>Heikkinen, Miss. Laina</td>\n",

" <td>female</td>\n",

" <td>26.0</td>\n",

" <td>0</td>\n",

" <td>0</td>\n",

" <td>STON/O2. 3101282</td>\n",

" <td>7.9250</td>\n",

" <td>NaN</td>\n",

" <td>S</td>\n",

" </tr>\n",

" <tr>\n",

" <th>3</th>\n",

" <td>4</td>\n",

" <td>4</td>\n",

" <td>1</td>\n",

" <td>1</td>\n",

" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",

" <td>female</td>\n",

" <td>35.0</td>\n",

" <td>1</td>\n",

" <td>0</td>\n",

" <td>113803</td>\n",

" <td>53.1000</td>\n",

" <td>C123</td>\n",

" <td>S</td>\n",

" </tr>\n",

" <tr>\n",

" <th>4</th>\n",
" <td>5</td>\n",

" <td>5</td>\n",

" <td>0</td>\n",

" <td>3</td>\n",

" <td>Allen, Mr. William Henry</td>\n",

" <td>male</td>\n",

" <td>35.0</td>\n",

" <td>0</td>\n",

" <td>0</td>\n",

" <td>373450</td>\n",

" <td>8.0500</td>\n",

" <td>NaN</td>\n",

" <td>S</td>\n",

" </tr>\n",

" </tbody>\n",

"</table>\n",

"</div>\n",

" <div class=\"colab-df-buttons\">\n",

"\n",

" <div class=\"colab-df-container\">\n",

" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c31e3236-17fd-


4f3d-88ef-f6ba5eeb5ce3')\"\n",

" title=\"Convert this dataframe to an interactive table.\"\n",

" style=\"display:none;\">\n",

"\n",

" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960


960\">\n",

" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220


220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440
0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",

" </button>\n",

"\n",

" <style>\n",

" .colab-df-container {\n",

" display:flex;\n",

" gap: 12px;\n",

" }\n",

"\n",

" .colab-df-convert {\n",

" background-color: #E8F0FE;\n",

" border: none;\n",

" border-radius: 50%;\n",

" cursor: pointer;\n",

" display: none;\n",

" fill: #1967D2;\n",

" height: 32px;\n",

" padding: 0 0 0 0;\n",

" width: 32px;\n",

" }\n",

"\n",

" .colab-df-convert:hover {\n",

" background-color: #E2EBFA;\n",

" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\
n",

" fill: #174EA6;\n",

" }\n",

"\n",

" .colab-df-buttons div {\n",


" margin-bottom: 4px;\n",

" }\n",

"\n",

" [theme=dark] .colab-df-convert {\n",

" background-color: #3B4455;\n",

" fill: #D2E3FC;\n",

" }\n",

"\n",

" [theme=dark] .colab-df-convert:hover {\n",

" background-color: #434B5C;\n",

" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",

" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",

" fill: #FFFFFF;\n",

" }\n",

" </style>\n",

"\n",

" <script>\n",

" const buttonEl =\n",

" document.querySelector('#df-c31e3236-17fd-4f3d-88ef-f6ba5eeb5ce3 button.colab-


df-convert');\n",

" buttonEl.style.display =\n",

" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",

"\n",

" async function convertToInteractive(key) {\n",

" const element = document.querySelector('#df-c31e3236-17fd-4f3d-88ef-


f6ba5eeb5ce3');\n",

" const dataTable =\n",

" await google.colab.kernel.invokeFunction('convertToInteractive',\n",

" [key], {});\n",

" if (!dataTable) return;\n",


"\n",

" const docLinkHtml = 'Like what you see? Visit the ' +\n",

" '<a target=\"_blank\"


href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\
n",

" + ' to learn more about interactive tables.';\n",

" element.innerHTML = '';\n",

" dataTable['output_type'] = 'display_data';\n",

" await google.colab.output.renderOutput(dataTable, element);\n",

" const docLink = document.createElement('div');\n",

" docLink.innerHTML = docLinkHtml;\n",

" element.appendChild(docLink);\n",

" }\n",

" </script>\n",

" </div>\n",

"\n",

"\n",

"<div id=\"df-8d6b80eb-e09e-4525-95bd-da535c827163\">\n",

" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-8d6b80eb-e09e-4525-


95bd-da535c827163')\"\n",

" title=\"Suggest charts\"\n",

" style=\"display:none;\">\n",

"\n",

"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",

" width=\"24px\">\n",

" <g>\n",

" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-
2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",

" </g>\n",

"</svg>\n",
" </button>\n",

"\n",

"<style>\n",

" .colab-df-quickchart {\n",

" --bg-color: #E8F0FE;\n",

" --fill-color: #1967D2;\n",

" --hover-bg-color: #E2EBFA;\n",

" --hover-fill-color: #174EA6;\n",

" --disabled-fill-color: #AAA;\n",

" --disabled-bg-color: #DDD;\n",

" }\n",

"\n",

" [theme=dark] .colab-df-quickchart {\n",

" --bg-color: #3B4455;\n",

" --fill-color: #D2E3FC;\n",

" --hover-bg-color: #434B5C;\n",

" --hover-fill-color: #FFFFFF;\n",

" --disabled-bg-color: #3B4455;\n",

" --disabled-fill-color: #666;\n",

" }\n",

"\n",

" .colab-df-quickchart {\n",

" background-color: var(--bg-color);\n",

" border: none;\n",

" border-radius: 50%;\n",

" cursor: pointer;\n",

" display: none;\n",

" fill: var(--fill-color);\n",

" height: 32px;\n",


" padding: 0;\n",

" width: 32px;\n",

" }\n",

"\n",

" .colab-df-quickchart:hover {\n",

" background-color: var(--hover-bg-color);\n",

" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",

" fill: var(--button-hover-fill-color);\n",

" }\n",

"\n",

" .colab-df-quickchart-complete:disabled,\n",

" .colab-df-quickchart-complete:disabled:hover {\n",

" background-color: var(--disabled-bg-color);\n",

" fill: var(--disabled-fill-color);\n",

" box-shadow: none;\n",

" }\n",

"\n",

" .colab-df-spinner {\n",

" border: 2px solid var(--fill-color);\n",

" border-color: transparent;\n",

" border-bottom-color: var(--fill-color);\n",

" animation:\n",

" spin 1s steps(1) infinite;\n",

" }\n",

"\n",

" @keyframes spin {\n",

" 0% {\n",

" border-color: transparent;\n",

" border-bottom-color: var(--fill-color);\n",


" border-left-color: var(--fill-color);\n",

" }\n",

" 20% {\n",

" border-color: transparent;\n",

" border-left-color: var(--fill-color);\n",

" border-top-color: var(--fill-color);\n",

" }\n",

" 30% {\n",

" border-color: transparent;\n",

" border-left-color: var(--fill-color);\n",

" border-top-color: var(--fill-color);\n",

" border-right-color: var(--fill-color);\n",

" }\n",

" 40% {\n",

" border-color: transparent;\n",

" border-right-color: var(--fill-color);\n",

" border-top-color: var(--fill-color);\n",

" }\n",

" 60% {\n",

" border-color: transparent;\n",

" border-right-color: var(--fill-color);\n",

" }\n",

" 80% {\n",

" border-color: transparent;\n",

" border-right-color: var(--fill-color);\n",

" border-bottom-color: var(--fill-color);\n",

" }\n",

" 90% {\n",

" border-color: transparent;\n",


" border-bottom-color: var(--fill-color);\n",

" }\n",

" }\n",

"</style>\n",

"\n",

" <script>\n",

" async function quickchart(key) {\n",

" const quickchartButtonEl =\n",

" document.querySelector('#' + key + ' button');\n",

" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",

" quickchartButtonEl.classList.add('colab-df-spinner');\n",

" try {\n",

" const charts = await google.colab.kernel.invokeFunction(\n",

" 'suggestCharts', [key], {});\n",

" } catch (error) {\n",

" console.error('Error during call to suggestCharts:', error);\n",

" }\n",

" quickchartButtonEl.classList.remove('colab-df-spinner');\n",

" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",

" }\n",

" (() => {\n",

" let quickchartButtonEl =\n",

" document.querySelector('#df-8d6b80eb-e09e-4525-95bd-da535c827163 button');\


n",

" quickchartButtonEl.style.display =\n",

" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",

" })();\n",

" </script>\n",

"</div>\n",
"\n",

" </div>\n",

" </div>\n"

],

"application/vnd.google.colaboratory.intrinsic+json": {

"type": "dataframe",

"variable_name": "datos",

"summary": "{\n \"name\": \"datos\",\n \"rows\": 1309,\n \"fields\": [\n {\


n \"column\": \"Unnamed: 0\",\n \"properties\": {\n \"dtype\": \"number\",\
n \"std\": 378,\n \"min\": 1,\n \"max\": 1309,\n \"num_unique_values\": 1309,\n
\"samples\": [\n 1149,\n 1050,\n 983\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\n \"column\": \"PassengerId\",\n \"properties\":
{\n \"dtype\": \"number\",\n \"std\": 378,\n \"min\": 1,\n \"max\": 1309,\
n \"num_unique_values\": 1309,\n \"samples\": [\n 1149,\n 1050,\n 983\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Survived\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\":
0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n
1,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"Pclass\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\
n \"min\": 1,\n \"max\": 3,\n \"num_unique_values\": 3,\n \"samples\": [\n
3,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"Name\",\n \"properties\": {\n \"dtype\": \"string\",\
n \"num_unique_values\": 1307,\n \"samples\": [\n \"Bryhl, Miss. Dagmar Jenny
Ingeborg \",\n \"Borebank, Mr. John James\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sex\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\
n \"female\",\n \"male\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\n \"column\": \"Age\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 14.413493211271321,\n \"min\": 0.17,\
n \"max\": 80.0,\n \"num_unique_values\": 98,\n \"samples\": [\n 45.5,\n
23.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"SibSp\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1,\n
\"min\": 0,\n \"max\": 8,\n \"num_unique_values\": 7,\n \"samples\": [\n 1,\n
0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Parch\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n
\"min\": 0,\n \"max\": 9,\n \"num_unique_values\": 8,\n \"samples\": [\n 1,\n
4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Ticket\",\n \"properties\": {\n \"dtype\": \"string\",\
n \"num_unique_values\": 929,\n \"samples\": [\n \"PC 17531\",\n \"345765\"\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Fare\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\":
51.75866823917411,\n \"min\": 0.0,\n \"max\": 512.3292,\n \"num_unique_values\":
281,\n \"samples\": [\n 11.2417,\n 35.0\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"Cabin\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 186,\n \"samples\": [\
n \"B71\",\n \"C51\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n },\n {\n \"column\": \"Embarked\",\n \"properties\": {\n \"dtype\": \"category\",\
n \"num_unique_values\": 3,\n \"samples\": [\n \"S\",\n \"C\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"

},

"metadata": {},

"execution_count": 6

},

"cell_type": "code",

"source": [

"print(datos)"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "kEsJVE_YBf2Y",

"outputId": "d8529887-e83a-4abe-83ac-fa5c06152a7a"

},

"execution_count": 7,

"outputs": [

"output_type": "stream",
"name": "stdout",

"text": [

" Unnamed: 0 PassengerId Survived Pclass \\\n",

"0 1 1 0 3 \n",

"1 2 2 1 1 \n",

"2 3 3 1 3 \n",

"3 4 4 1 1 \n",

"4 5 5 0 3 \n",

"... ... ... ... ... \n",

"1304 1305 1305 0 3 \n",

"1305 1306 1306 1 1 \n",

"1306 1307 1307 0 3 \n",

"1307 1308 1308 0 3 \n",

"1308 1309 1309 0 3 \n",

"\n",

" Name Sex Age SibSp \\\n",

"0 Braund, Mr. Owen Harris male 22.0 1 \n",

"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",

"2 Heikkinen, Miss. Laina female 26.0 0 \n",

"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",

"4 Allen, Mr. William Henry male 35.0 0 \n",

"... ... ... ... ... \n",

"1304 Spector, Mr. Woolf male NaN 0 \n",

"1305 Oliva y Ocana, Dona. Fermina female 39.0 0 \n",

"1306 Saether, Mr. Simon Sivertsen male 38.5 0 \n",

"1307 Ware, Mr. Frederick male NaN 0 \n",

"1308 Peter, Master. Michael J male NaN 1 \n",

"\n",

" Parch Ticket Fare Cabin Embarked \n",


"0 0 A/5 21171 7.2500 NaN S \n",

"1 0 PC 17599 71.2833 C85 C \n",

"2 0 STON/O2. 3101282 7.9250 NaN S \n",

"3 0 113803 53.1000 C123 S \n",

"4 0 373450 8.0500 NaN S \n",

"... ... ... ... ... ... \n",

"1304 0 A.5. 3236 8.0500 NaN S \n",

"1305 0 PC 17758 108.9000 C105 C \n",

"1306 0 SOTON/O.Q. 3101262 7.2500 NaN S \n",

"1307 0 359309 8.0500 NaN S \n",

"1308 1 2668 22.3583 NaN C \n",

"\n",

"[1309 rows x 13 columns]\n"

},

"cell_type": "markdown",

"source": [

"###Validamos los Datos nulos. Cuantos nulos hay por cada campo?"

],

"metadata": {

"id": "f2U75-rn-QUv"

},

"cell_type": "code",

"source": [
"datos.isnull().sum()"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "1QsQJJycHHGe",

"outputId": "8d80b334-eed6-4052-98b9-a160f554dd61"

},

"execution_count": 8,

"outputs": [

"output_type": "execute_result",

"data": {

"text/plain": [

"Unnamed: 0 0\n",

"PassengerId 0\n",

"Survived 0\n",

"Pclass 0\n",

"Name 0\n",

"Sex 0\n",

"Age 263\n",

"SibSp 0\n",

"Parch 0\n",

"Ticket 0\n",

"Fare 1\n",

"Cabin 1014\n",

"Embarked 2\n",

"dtype: int64"
]

},

"metadata": {},

"execution_count": 8

},

"cell_type": "markdown",

"source": [

"###Borramos la columna cabina y Unnamed: 0 con drop."

],

"metadata": {

"id": "bqXp9z8U-d3X"

},

"cell_type": "code",

"source": [

"datos = datos.drop(columns = ['Cabin','Unnamed: 0'])"

],

"metadata": {

"id": "U3065ksQHaF4"

},

"execution_count": 9,

"outputs": []

},

"cell_type": "code",
"source": [

"print(datos)"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "64dNhD-PBTWx",

"outputId": "35fb451d-94c7-4125-fc83-0fb72a21e5fd"

},

"execution_count": 10,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

" PassengerId Survived Pclass \\\n",

"0 1 0 3 \n",

"1 2 1 1 \n",

"2 3 1 3 \n",

"3 4 1 1 \n",

"4 5 0 3 \n",

"... ... ... ... \n",

"1304 1305 0 3 \n",

"1305 1306 1 1 \n",

"1306 1307 0 3 \n",

"1307 1308 0 3 \n",

"1308 1309 0 3 \n",

"\n",
" Name Sex Age SibSp \\\n",

"0 Braund, Mr. Owen Harris male 22.0 1 \n",

"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",

"2 Heikkinen, Miss. Laina female 26.0 0 \n",

"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",

"4 Allen, Mr. William Henry male 35.0 0 \n",

"... ... ... ... ... \n",

"1304 Spector, Mr. Woolf male NaN 0 \n",

"1305 Oliva y Ocana, Dona. Fermina female 39.0 0 \n",

"1306 Saether, Mr. Simon Sivertsen male 38.5 0 \n",

"1307 Ware, Mr. Frederick male NaN 0 \n",

"1308 Peter, Master. Michael J male NaN 1 \n",

"\n",

" Parch Ticket Fare Embarked \n",

"0 0 A/5 21171 7.2500 S \n",

"1 0 PC 17599 71.2833 C \n",

"2 0 STON/O2. 3101282 7.9250 S \n",

"3 0 113803 53.1000 S \n",

"4 0 373450 8.0500 S \n",

"... ... ... ... ... \n",

"1304 0 A.5. 3236 8.0500 S \n",

"1305 0 PC 17758 108.9000 C \n",

"1306 0 SOTON/O.Q. 3101262 7.2500 S \n",

"1307 0 359309 8.0500 S \n",

"1308 1 2668 22.3583 C \n",

"\n",

"[1309 rows x 11 columns]\n"

}
]

},

"cell_type": "markdown",

"source": [

"##LLenar los datos nulos encontrados en la columna edad por la media de estos."

],

"metadata": {

"id": "uDNTo4ChJVt6"

},

"cell_type": "code",

"source": [

"datos['Age'].fillna(datos['Age'].mean(), inplace=True)\n",

"datos['Fare'].fillna(datos['Fare'].mean(), inplace=True)\n",

"#datos['Embarked'].fillna(datos['Embarked'].mean(), inplace=True)"

],

"metadata": {

"id": "X9oRwHOtHnVz"

},

"execution_count": 11,

"outputs": []

},

"cell_type": "markdown",

"source": [

"##Imprimir la moda de la columna Embarked"

],
"metadata": {

"id": "uWQUBCMMJzWP"

},

"cell_type": "code",

"source": [

"print(datos['Embarked'].mode())"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "W4mkzbWbIMDa",

"outputId": "cfc13ae0-89d7-4199-fde3-65c7a4e524df"

},

"execution_count": 12,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

"0 S\n",

"Name: Embarked, dtype: object\n"

},

{
"cell_type": "markdown",

"source": [

"## Reemplazar en la columna Embarked los datos nulos con el dato de la moda."

],

"metadata": {

"id": "mY4wCJUiKIea"

},

"cell_type": "code",

"source": [

"datos['Embarked'].fillna(datos['Embarked'].mode()[0], inplace=True)"

],

"metadata": {

"id": "E9KbpD6dIyMc"

},

"execution_count": 13,

"outputs": []

},

"cell_type": "markdown",

"source": [

"## Trasnformacion de datos categoricos de sex y embarked"

],

"metadata": {

"id": "yhSIJ7k7OIMq"

},

{
"cell_type": "code",

"source": [

"datos.replace({'Sex':{'male':0,'female':1},'Embarked': {'S':0,'C':1,'Q':2}},inplace =True)\n",

"print(datos)"

],

"metadata": {

"id": "lyDrkKghJGUb",

"colab": {

"base_uri": "https://localhost:8080/"

},

"outputId": "cca2e001-6100-451d-e063-8114cec9951e"

},

"execution_count": 14,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

" PassengerId Survived Pclass \\\n",

"0 1 0 3 \n",

"1 2 1 1 \n",

"2 3 1 3 \n",

"3 4 1 1 \n",

"4 5 0 3 \n",

"... ... ... ... \n",

"1304 1305 0 3 \n",

"1305 1306 1 1 \n",

"1306 1307 0 3 \n",

"1307 1308 0 3 \n",


"1308 1309 0 3 \n",

"\n",

" Name Sex Age \\\n",

"0 Braund, Mr. Owen Harris 0 22.000000 \n",

"1 Cumings, Mrs. John Bradley (Florence Briggs Th... 1 38.000000 \n",

"2 Heikkinen, Miss. Laina 1 26.000000 \n",

"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) 1 35.000000 \n",

"4 Allen, Mr. William Henry 0 35.000000 \n",

"... ... ... ... \n",

"1304 Spector, Mr. Woolf 0 29.881138 \n",

"1305 Oliva y Ocana, Dona. Fermina 1 39.000000 \n",

"1306 Saether, Mr. Simon Sivertsen 0 38.500000 \n",

"1307 Ware, Mr. Frederick 0 29.881138 \n",

"1308 Peter, Master. Michael J 0 29.881138 \n",

"\n",

" SibSp Parch Ticket Fare Embarked \n",

"0 1 0 A/5 21171 7.2500 0 \n",

"1 1 0 PC 17599 71.2833 1 \n",

"2 0 0 STON/O2. 3101282 7.9250 0 \n",

"3 1 0 113803 53.1000 0 \n",

"4 0 0 373450 8.0500 0 \n",

"... ... ... ... ... ... \n",

"1304 0 0 A.5. 3236 8.0500 0 \n",

"1305 0 0 PC 17758 108.9000 1 \n",

"1306 0 0 SOTON/O.Q. 3101262 7.2500 0 \n",

"1307 0 0 359309 8.0500 0 \n",

"1308 1 1 2668 22.3583 1 \n",

"\n",

"[1309 rows x 11 columns]\n"


]

},

"cell_type": "markdown",

"source": [

"## Borrarmos las columnas PassengerID,Name,Ticket,'urvived"

],

"metadata": {

"id": "GgsMgQySTtSL"

},

"cell_type": "code",

"source": [

"#datos= datos.drop(columns = ['PassengerId','Name','Ticket','Survived'] , axis = 1)\n",

"#Y = datos['Survived']"

],

"metadata": {

"id": "8mXzWuYgKtep"

},

"execution_count": 15,

"outputs": []

},

"cell_type": "markdown",

"source": [
"#Despues del preprocesamiento pasamos a hacer la predicción si una persona sobrevive o no
sobrevive"

],

"metadata": {

"id": "2DsUGjDUUNhF"

},

"cell_type": "markdown",

"source": [],

"metadata": {

"id": "icO21PZ1Tshz"

},

"source": [

"\n",

"X = datos.drop(['PassengerId','Name','Ticket','Survived'],axis = 1)\n",

"\n",

"y = datos['Survived']\n",

"print(datos.columns)"

],

"cell_type": "code",

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "TkL5rdgQPa9q",

"outputId": "8eb275f8-0a71-4d24-f4a3-88b93a09e0a6"
},

"execution_count": 16,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

"Index(['PassengerId', 'Survived', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp',\n",

" 'Parch', 'Ticket', 'Fare', 'Embarked'],\n",

" dtype='object')\n"

},

"cell_type": "code",

"source": [

"\n",

"X_train, X_test, y_train, y_test = train_test_split(X,y,test_size =0.2, random_state = 2)\n",

"\n"

],

"metadata": {

"id": "QckOtN2RRInN"

},

"execution_count": 17,

"outputs": []

},

"cell_type": "markdown",
"source": [

"###Se hace el entrenamiendo del model"

],

"metadata": {

"id": "37saVOWldUkF"

},

"cell_type": "code",

"source": [

"model = LogisticRegression()\n",

"model.fit(X_train, y_train)"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/",

"height": 234

},

"id": "aPEPc-w8dYGE",

"outputId": "8f4420b3-0298-4687-ccfa-5d6d75862a4e"

},

"execution_count": 18,

"outputs": [

"output_type": "stream",

"name": "stderr",

"text": [

"/usr/local/lib/python3.10/dist-packages/sklearn/linear_model/_logistic.py:458:
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": [

"LogisticRegression()"

],

"text/html": [

"<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1


pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1
label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding:
0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-
arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1
label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-
estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-
toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-
color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color:
black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-
toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width:
100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-
toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-
toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-
container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label
{background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px
1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding:
0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family:
monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing:
border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color:
#d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom:
1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label
{background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position:
absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index:
0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items:
center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-
container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display:
flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-
container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before
{content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom:
0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-
index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-
child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after
{align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width:
0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em
0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1
div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height:
1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-
container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set
`[hidden] { display: none !important; }` so we also need the `!important` here to be able to
override the default hidden behavior on the sphinx rendered scikit-learn.org. See:
https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !
important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display:
none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-
fallback\"><pre>LogisticRegression()</pre><b>In a Jupyter environment, please rerun this cell to
show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation
is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-
container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input
class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\"
checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-
arrow\">LogisticRegression</label><div class=\"sk-
toggleable__content\"><pre>LogisticRegression()</pre></div></div></div></div></div>"

},

"metadata": {},

"execution_count": 18

},

{
"cell_type": "markdown",

"source": [

"## Medimos la precisión del modelo."

],

"metadata": {

"id": "tzt1W5ECgTkm"

},

"cell_type": "code",

"source": [

"from sklearn.metrics import accuracy_score\n",

"X_train_prediction = model.predict(X_train)\n",

"accuracy = accuracy_score(y_train, X_train_prediction)\n",

"print(accuracy)\n"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "xQSCpnyEgWCf",

"outputId": "66a6f76c-90a4-4a4f-bba6-8987b5b135fd"

},

"execution_count": 19,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [
"0.8586437440305635\n"

},

"cell_type": "markdown",

"source": [

"## Medimos la precisión de la predicción."

],

"metadata": {

"id": "CRZyG0GCW874"

},

"cell_type": "code",

"source": [

"X_test_prediction = model.predict(X_test)\n",

"test_data_accuracy = accuracy_score(y_test, X_test_prediction)\n",

"print(test_data_accuracy)"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "LSxlMccoXDoA",

"outputId": "597d0638-4cb5-4284-c733-3eaeed6026b3"

},

"execution_count": 20,
"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

"0.8625954198473282\n"

},

"cell_type": "markdown",

"source": [

"## Para guardar el entrenamiento"

],

"metadata": {

"id": "9-_vTDSSSV8V"

},

"cell_type": "code",

"source": [

"joblib.dump(model, 'modelo_entrenado')"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "5LKJYKY5Sdcw",
"outputId": "370ab248-bb90-4090-f488-251924e6c526"

},

"execution_count": 21,

"outputs": [

"output_type": "execute_result",

"data": {

"text/plain": [

"['modelo_entrenado']"

},

"metadata": {},

"execution_count": 21

},

"cell_type": "markdown",

"source": [],

"metadata": {

"id": "ZjgxjiVkWyeZ"

},

"cell_type": "markdown",

"source": [

"##Se hace la prueba con datos aleatorios del modelo entrenado"

],

"metadata": {
"id": "qUMHc756k2kV"

},

"cell_type": "markdown",

"source": [

"###Prediccion con el modelos y datos de prueba"

],

"metadata": {

"id": "QxreEhODmwC3"

},

"cell_type": "code",

"source": [],

"metadata": {

"id": "YvWfNadvI5gi"

},

"execution_count": null,

"outputs": []

},

"cell_type": "code",

"source": [],

"metadata": {

"id": "Zj8rcQgd-l2Y"

},

"execution_count": 22,

"outputs": []
},

"cell_type": "markdown",

"source": [

"### b.\tQue hubiera ocurrido si más del 50% de los pasajeros del barco hubiesen sido
varones entre 30 y 60 años"

],

"metadata": {

"id": "da-jMoOV-oOu"

},

"cell_type": "markdown",

"source": [

"##### **Modificación** del Dataset con las condiciones pedidas para el pronostico"

],

"metadata": {

"id": "DwogFk1m_Fuh"

},

"cell_type": "code",

"source": [

"#Cantidad de hombres\n",

"\n",

"datos = pd.read_csv('titanic.csv')\n",

"\n",

"# Contar la cantidad de hombres\n",

"num_hombres = datos[datos['Sex'] == 'male'].shape[0]\n",


"\n",

"print(f'Cantidad de hombres en el dataset: {num_hombres}')\n",

"# Contar la cantidad de mujeres\n",

"num_mujeres = datos[datos['Sex'] == 'male'].shape[1]\n",

"\n",

"print(f'Cantidad de mujeres en el dataset: {num_mujeres}')\n"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "DAVPee9J_MqZ",

"outputId": "ed4c9193-0b0d-459a-fbc4-389b163e2c3b"

},

"execution_count": 25,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

"Cantidad de hombres en el dataset: 843\n",

"Cantidad de mujeres en el dataset: 13\n"

},

"cell_type": "markdown",

"source": [
"####Cantidad de hombres entre 30 y 60 años"

],

"metadata": {

"id": "I0QkHxz_F92-"

},

"cell_type": "code",

"source": [

"\n",

"# Filtrar los hombres entre 30 y 60 años\n",

"hombres_30_60 = datos[(datos['Sex'] == 'male') & (datos['Age'] >= 30) & (datos['Age'] <=
60)]\n",

"\n",

"# Contar la cantidad de hombres en ese rango de edad\n",

"num_hombres_30_60 = hombres_30_60.shape[0]\n",

"\n",

"print(f'Cantidad de hombres entre 30 y 60 años en el dataset: {num_hombres_30_60}')\n"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "Sg_0m-awF54c",

"outputId": "e4e96a9a-7d5e-4191-8ad0-72a336007d48"

},

"execution_count": 28,

"outputs": [

{
"output_type": "stream",

"name": "stdout",

"text": [

"Cantidad de hombres entre 30 y 60 años en el dataset: 281\n"

},

"cell_type": "markdown",

"source": [

"#### Reemplazo los 422 hombres con edades entre los 30 y 60"

],

"metadata": {

"id": "-7SWrDCUIMjj"

},

"cell_type": "code",

"source": [

"\n",

"\n",

"# Filtrar los hombres\n",

"hombres = datos[datos['Sex'] == 'male']\n",

"\n",

"# Asegurarse de que haya suficientes hombres en el dataset\n",

"if len(hombres) < 422:\n",

" raise ValueError(\"No hay suficientes hombres en el dataset para reemplazar las
edades.\")\n",
"\n",

"# Seleccionar 422 hombres de forma aleatoria\n",

"hombres_aleatorios = hombres.sample(n=422, random_state=42).index\n",

"\n",

"# Generar nuevas edades aleatorias entre 30 y 60 años\n",

"nuevas_edades = np.random.randint(30, 61, size=422)\n",

"\n",

"# Reemplazar las edades de los hombres seleccionados con las nuevas edades\n",

"datos.loc[hombres_aleatorios, 'Age'] = nuevas_edades\n",

"\n",

"# Verificar los cambios\n",

"print(datos.loc[hombres_aleatorios, ['Sex', 'Age']])\n"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "f39Ze1q8IY_s",

"outputId": "d509af3b-8543-4c15-c191-26debd0caade"

},

"execution_count": 29,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

" Sex Age\n",

"762 male 43.0\n",

"344 male 58.0\n",


"966 male 39.0\n",

"1148 male 33.0\n",

"103 male 43.0\n",

"... ... ...\n",

"508 male 34.0\n",

"1243 male 52.0\n",

"221 male 33.0\n",

"936 male 53.0\n",

"822 male 60.0\n",

"\n",

"[422 rows x 2 columns]\n"

},

"cell_type": "markdown",

"source": [

"#### Verificación"

],

"metadata": {

"id": "yjAMBAxDInNw"

},

"cell_type": "code",

"source": [

"hombres_30_60 = datos[(datos['Sex'] == 'male') & (datos['Age'] >= 30) & (datos['Age'] <=
60)]\n",
"\n",

"# Contar la cantidad de hombres en ese rango de edad\n",

"num_hombres_30_60 = hombres_30_60.shape[0]\n",

"\n",

"print(f'Cantidad de hombres entre 30 y 60 años en el dataset: {num_hombres_30_60}')"

],

"metadata": {

"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "LVEVTCAkIsKG",

"outputId": "0ce7a198-2201-48ac-d7c9-43b99e7b3722"

},

"execution_count": 30,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

"Cantidad de hombres entre 30 y 60 años en el dataset: 563\n"

},

"cell_type": "markdown",

"source": [

"#### Se hace la predicción"

],
"metadata": {

"id": "cp4ukgo5I7X6"

},

"cell_type": "code",

"source": [

"import numpy as np\n",

"\n",

"# Definición de los pasajeros: Clase, Sexo(mujer=0,hombre=1), Edad, Número de hermanos o


conyugues a bordo, Número de padres e hijos a bordo, Tarifa, Lugar de embarque\n",

"Pasajeros = [\n",

" (1, 0, 40, 0, 0, 72, 1),\n",

" (1, 0, 40, 0, 0, 50, 1),\n",

" (1, 0, 80, 0, 0, 20, 1)\n",

"]\n",

"\n",

"# Iterar sobre cada pasajero y hacer la predicción\n",

"for i, pasajero in enumerate(Pasajeros):\n",

" input_data_as_numpy_array = np.asarray(pasajero)\n",

" input_data_reshaped = input_data_as_numpy_array.reshape(1, -1)\n",

" prediction = model.predict(input_data_reshaped)\n",

"\n",

" if prediction[0] == 0:\n",

" print(f\"Pasajero {i+1}: Muerto\")\n",

" elif prediction[0] == 1:\n",

" print(f\"Pasajero {i+1}: Vivió\")\n"

],

"metadata": {
"colab": {

"base_uri": "https://localhost:8080/"

},

"id": "nMRG7aQd7M-D",

"outputId": "9eabd562-8db1-41d6-ebf3-b1a79bd65cd0"

},

"execution_count": 33,

"outputs": [

"output_type": "stream",

"name": "stdout",

"text": [

"Pasajero 1: Muerto\n",

"Pasajero 2: Muerto\n",

"Pasajero 3: Muerto\n"

},

"output_type": "stream",

"name": "stderr",

"text": [

"/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not


have valid feature names, but LogisticRegression was fitted with feature names\n",

" warnings.warn(\n",

"/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not


have valid feature names, but LogisticRegression was fitted with feature names\n",

" warnings.warn(\n",

"/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not


have valid feature names, but LogisticRegression was fitted with feature names\n",

" warnings.warn(\n"
]

You might also like