# Importaciones necesarias
import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
# Cargamos los datos
df = pd.read_csv('titanic.csv')
df.head(2)
survived | pclass | age | sibsp | parch | fare | male | age_was_missing | embarked_from_cherbourg | embarked_from_queenstown | embarked_from_southampton | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 3 | 22.0 | 1 | 0 | 7.2500 | 1 | False | 0 | 0 | 1 |
1 | 1 | 1 | 38.0 | 1 | 0 | 71.2833 | 0 | False | 1 | 0 | 0 |
df['age_was_missing'].unique()
array([False, True])
# numero de filas por numero de columnas
df.shape
(891, 11)
La variable objetivo corresponde a la columna survived
que tiene marcado el 1 si el pasajero sobrevivió y 0 caso contrario. El resto de columnas coresponden a las características.
De tal manera, nuestro objetivo será predecir si el pasajero sobrevivió o no.
Notemos antes que de los pasajeros, sobrevivieron más mujeres (0) que hombres (1)
plt.figure(figsize=(4,4))
sns.scatterplot(data=df, x="age", y="male", hue='survived')
plt.title('Sexo vs Edad: Sobrevivientes')
plt.show()
Continuando, nuestra red tendrá 10 nodos de entrada y un nodo de salida; la capa de salida tendrá asociada la función sigmoide, la cual nos arrojará 0 para números obtenido menores al umbral (por defecto el umbral vale 0.5), y 1 para números mayores o iguales al umbral. Crearemos dos capas ocultas y le asociaremos la función de activación relu
Convertiremos nuestro dataframe a un array
df.columns
Index(['survived', 'pclass', 'age', 'sibsp', 'parch', 'fare', 'male', 'age_was_missing', 'embarked_from_cherbourg', 'embarked_from_queenstown', 'embarked_from_southampton'], dtype='object')
# Convertimos el dataframe a un array
df_np = np.array(df)
# Veamos que la columna 7 tiene entradas booleanas
df_np[0:3,7].reshape(3,1)
array([[False], [False], [False]], dtype=object)
# Cambiaremos el valor de True a 1 y el de False a 0
filtrado = np.where(df_np[:,7] , 1, 0)
# A la columna 7 le asignamos los valores obtenidos
# anteriormente
df_np[:,7] = filtrado
Procedemos a dividir los datos:
df_np[:, 0]
array([0, 1, 1, 1, 0, 0, 0, 0, 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 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0], dtype=object)
from sklearn.model_selection import train_test_split
# Las columnas de la 1 a la ultima son nuestras
# caracteristicas
X = df_np[:, 1:11]
X = np.asarray(X).astype('float32')
# La variable objetivo es la primera columna
y = df_np[:, 0].reshape(891,1)
y = np.asarray(y).astype('float32')
# División de los datos
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
train_size = 0.75,
random_state = 123)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
(668, 10) (223, 10) (668, 1) (223, 1)
Ahora creamos nuestro modelo en keras:
# Realizamos las importaciones necesarias
from keras.models import Sequential
from keras.layers import Dense
# Fijamos una semilla
np.random.seed(123)
# Instanciamos el modelo
model = Sequential()
# Capa de entrada de 10 neuronas y capa oculta
# de 70 neuronas
model.add(Dense(50, input_shape=(10,) , activation='relu'))
# Capa de salida
model.add(Dense(1, activation='sigmoid'))
# Compilacion del modelo.
# El optimizador: adam
# Funcion de perdida: binary_crossentropy
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
# Vemos un resumen sobre nuestro modelo
model.summary()
Model: "sequential_20" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_55 (Dense) (None, 50) 550 dense_56 (Dense) (None, 1) 51 ================================================================= Total params: 601 Trainable params: 601 Non-trainable params: 0 _________________________________________________________________
# Ajustamos el modelo con los datos de entrenamiento
history = model.fit(X_train, y_train,
epochs=100,
validation_data=(X_test, y_test))
Epoch 1/100 21/21 [==============================] - 1s 8ms/step - loss: 3.3755 - accuracy: 0.3817 - val_loss: 1.1949 - val_accuracy: 0.3139 Epoch 2/100 21/21 [==============================] - 0s 3ms/step - loss: 0.8643 - accuracy: 0.6108 - val_loss: 0.6134 - val_accuracy: 0.7130 Epoch 3/100 21/21 [==============================] - 0s 3ms/step - loss: 0.6225 - accuracy: 0.7081 - val_loss: 0.6028 - val_accuracy: 0.7265 Epoch 4/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5840 - accuracy: 0.7081 - val_loss: 0.5845 - val_accuracy: 0.7220 Epoch 5/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5734 - accuracy: 0.7141 - val_loss: 0.5841 - val_accuracy: 0.7265 Epoch 6/100 21/21 [==============================] - 0s 2ms/step - loss: 0.5678 - accuracy: 0.7275 - val_loss: 0.5683 - val_accuracy: 0.7534 Epoch 7/100 21/21 [==============================] - 0s 2ms/step - loss: 0.5588 - accuracy: 0.7275 - val_loss: 0.5544 - val_accuracy: 0.7534 Epoch 8/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5516 - accuracy: 0.7395 - val_loss: 0.5614 - val_accuracy: 0.7309 Epoch 9/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5485 - accuracy: 0.7395 - val_loss: 0.5410 - val_accuracy: 0.7578 Epoch 10/100 21/21 [==============================] - 0s 2ms/step - loss: 0.5445 - accuracy: 0.7320 - val_loss: 0.5390 - val_accuracy: 0.7534 Epoch 11/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5414 - accuracy: 0.7365 - val_loss: 0.5458 - val_accuracy: 0.7489 Epoch 12/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5333 - accuracy: 0.7485 - val_loss: 0.5214 - val_accuracy: 0.7578 Epoch 13/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5252 - accuracy: 0.7380 - val_loss: 0.5134 - val_accuracy: 0.7578 Epoch 14/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5303 - accuracy: 0.7395 - val_loss: 0.5174 - val_accuracy: 0.7578 Epoch 15/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5338 - accuracy: 0.7440 - val_loss: 0.5353 - val_accuracy: 0.7848 Epoch 16/100 21/21 [==============================] - 0s 2ms/step - loss: 0.5277 - accuracy: 0.7425 - val_loss: 0.4985 - val_accuracy: 0.7848 Epoch 17/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5042 - accuracy: 0.7560 - val_loss: 0.4934 - val_accuracy: 0.7758 Epoch 18/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5019 - accuracy: 0.7545 - val_loss: 0.4873 - val_accuracy: 0.7803 Epoch 19/100 21/21 [==============================] - 0s 3ms/step - loss: 0.5011 - accuracy: 0.7485 - val_loss: 0.4891 - val_accuracy: 0.7892 Epoch 20/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4956 - accuracy: 0.7680 - val_loss: 0.4874 - val_accuracy: 0.7892 Epoch 21/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4991 - accuracy: 0.7605 - val_loss: 0.4780 - val_accuracy: 0.7937 Epoch 22/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4968 - accuracy: 0.7650 - val_loss: 0.4724 - val_accuracy: 0.7892 Epoch 23/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4954 - accuracy: 0.7740 - val_loss: 0.4709 - val_accuracy: 0.7848 Epoch 24/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4917 - accuracy: 0.7769 - val_loss: 0.4763 - val_accuracy: 0.7982 Epoch 25/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4850 - accuracy: 0.7754 - val_loss: 0.4722 - val_accuracy: 0.7848 Epoch 26/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4877 - accuracy: 0.7769 - val_loss: 0.4858 - val_accuracy: 0.7803 Epoch 27/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4749 - accuracy: 0.7814 - val_loss: 0.4665 - val_accuracy: 0.7803 Epoch 28/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4752 - accuracy: 0.7859 - val_loss: 0.4568 - val_accuracy: 0.8027 Epoch 29/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4745 - accuracy: 0.7889 - val_loss: 0.4597 - val_accuracy: 0.8072 Epoch 30/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4827 - accuracy: 0.7979 - val_loss: 0.4534 - val_accuracy: 0.7982 Epoch 31/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4667 - accuracy: 0.8009 - val_loss: 0.4478 - val_accuracy: 0.8117 Epoch 32/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4643 - accuracy: 0.8054 - val_loss: 0.4485 - val_accuracy: 0.8072 Epoch 33/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4644 - accuracy: 0.7814 - val_loss: 0.4516 - val_accuracy: 0.8161 Epoch 34/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4690 - accuracy: 0.8024 - val_loss: 0.4526 - val_accuracy: 0.7848 Epoch 35/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4603 - accuracy: 0.7979 - val_loss: 0.4487 - val_accuracy: 0.8027 Epoch 36/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4599 - accuracy: 0.8129 - val_loss: 0.4398 - val_accuracy: 0.8072 Epoch 37/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4576 - accuracy: 0.8084 - val_loss: 0.4398 - val_accuracy: 0.8072 Epoch 38/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4628 - accuracy: 0.7949 - val_loss: 0.5009 - val_accuracy: 0.7668 Epoch 39/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4810 - accuracy: 0.7829 - val_loss: 0.4420 - val_accuracy: 0.7848 Epoch 40/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4685 - accuracy: 0.8084 - val_loss: 0.4568 - val_accuracy: 0.8027 Epoch 41/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4620 - accuracy: 0.8084 - val_loss: 0.4345 - val_accuracy: 0.8161 Epoch 42/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4592 - accuracy: 0.8144 - val_loss: 0.4353 - val_accuracy: 0.8161 Epoch 43/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4545 - accuracy: 0.8084 - val_loss: 0.4323 - val_accuracy: 0.8072 Epoch 44/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4529 - accuracy: 0.8039 - val_loss: 0.4373 - val_accuracy: 0.8296 Epoch 45/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4536 - accuracy: 0.8114 - val_loss: 0.4491 - val_accuracy: 0.8072 Epoch 46/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4521 - accuracy: 0.8099 - val_loss: 0.4423 - val_accuracy: 0.8072 Epoch 47/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4523 - accuracy: 0.8084 - val_loss: 0.4272 - val_accuracy: 0.8206 Epoch 48/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4495 - accuracy: 0.8024 - val_loss: 0.4273 - val_accuracy: 0.8072 Epoch 49/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4474 - accuracy: 0.8039 - val_loss: 0.4334 - val_accuracy: 0.8161 Epoch 50/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4454 - accuracy: 0.8159 - val_loss: 0.4256 - val_accuracy: 0.8161 Epoch 51/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4509 - accuracy: 0.7979 - val_loss: 0.4252 - val_accuracy: 0.8117 Epoch 52/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4458 - accuracy: 0.8084 - val_loss: 0.4246 - val_accuracy: 0.8251 Epoch 53/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4493 - accuracy: 0.8039 - val_loss: 0.4383 - val_accuracy: 0.8206 Epoch 54/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4650 - accuracy: 0.8054 - val_loss: 0.4343 - val_accuracy: 0.8027 Epoch 55/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4438 - accuracy: 0.8144 - val_loss: 0.4248 - val_accuracy: 0.8027 Epoch 56/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4470 - accuracy: 0.8039 - val_loss: 0.4227 - val_accuracy: 0.8251 Epoch 57/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4382 - accuracy: 0.8129 - val_loss: 0.4213 - val_accuracy: 0.8117 Epoch 58/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4504 - accuracy: 0.8084 - val_loss: 0.4526 - val_accuracy: 0.8072 Epoch 59/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4440 - accuracy: 0.8144 - val_loss: 0.4218 - val_accuracy: 0.8117 Epoch 60/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4368 - accuracy: 0.8144 - val_loss: 0.4205 - val_accuracy: 0.8161 Epoch 61/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4389 - accuracy: 0.8114 - val_loss: 0.4254 - val_accuracy: 0.8206 Epoch 62/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4456 - accuracy: 0.8024 - val_loss: 0.4260 - val_accuracy: 0.8117 Epoch 63/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4355 - accuracy: 0.8054 - val_loss: 0.4252 - val_accuracy: 0.8117 Epoch 64/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4452 - accuracy: 0.8069 - val_loss: 0.4176 - val_accuracy: 0.8161 Epoch 65/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4422 - accuracy: 0.8039 - val_loss: 0.4339 - val_accuracy: 0.7982 Epoch 66/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4439 - accuracy: 0.8114 - val_loss: 0.4196 - val_accuracy: 0.8206 Epoch 67/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4365 - accuracy: 0.8084 - val_loss: 0.4163 - val_accuracy: 0.8117 Epoch 68/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4363 - accuracy: 0.8174 - val_loss: 0.4181 - val_accuracy: 0.8206 Epoch 69/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4376 - accuracy: 0.8144 - val_loss: 0.4215 - val_accuracy: 0.8072 Epoch 70/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4394 - accuracy: 0.8054 - val_loss: 0.4212 - val_accuracy: 0.8161 Epoch 71/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4576 - accuracy: 0.8009 - val_loss: 0.4357 - val_accuracy: 0.8117 Epoch 72/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4391 - accuracy: 0.8084 - val_loss: 0.4303 - val_accuracy: 0.8072 Epoch 73/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4414 - accuracy: 0.8084 - val_loss: 0.4231 - val_accuracy: 0.8072 Epoch 74/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4336 - accuracy: 0.8084 - val_loss: 0.4163 - val_accuracy: 0.8161 Epoch 75/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4339 - accuracy: 0.8114 - val_loss: 0.4218 - val_accuracy: 0.8117 Epoch 76/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4319 - accuracy: 0.8069 - val_loss: 0.4172 - val_accuracy: 0.8206 Epoch 77/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4291 - accuracy: 0.8129 - val_loss: 0.4217 - val_accuracy: 0.8206 Epoch 78/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4302 - accuracy: 0.8174 - val_loss: 0.4181 - val_accuracy: 0.8206 Epoch 79/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4461 - accuracy: 0.8039 - val_loss: 0.4153 - val_accuracy: 0.8027 Epoch 80/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4365 - accuracy: 0.8099 - val_loss: 0.4148 - val_accuracy: 0.8206 Epoch 81/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4441 - accuracy: 0.8114 - val_loss: 0.4301 - val_accuracy: 0.8296 Epoch 82/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4331 - accuracy: 0.8293 - val_loss: 0.4185 - val_accuracy: 0.8296 Epoch 83/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4390 - accuracy: 0.8189 - val_loss: 0.4204 - val_accuracy: 0.8296 Epoch 84/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4359 - accuracy: 0.8174 - val_loss: 0.4160 - val_accuracy: 0.8161 Epoch 85/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4403 - accuracy: 0.7979 - val_loss: 0.4161 - val_accuracy: 0.8117 Epoch 86/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4306 - accuracy: 0.8204 - val_loss: 0.4196 - val_accuracy: 0.8251 Epoch 87/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4636 - accuracy: 0.7994 - val_loss: 0.4232 - val_accuracy: 0.8117 Epoch 88/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4229 - accuracy: 0.8174 - val_loss: 0.4236 - val_accuracy: 0.8296 Epoch 89/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4289 - accuracy: 0.8009 - val_loss: 0.4189 - val_accuracy: 0.8251 Epoch 90/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4310 - accuracy: 0.8249 - val_loss: 0.4196 - val_accuracy: 0.8072 Epoch 91/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4355 - accuracy: 0.8174 - val_loss: 0.4138 - val_accuracy: 0.8117 Epoch 92/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4285 - accuracy: 0.8099 - val_loss: 0.4148 - val_accuracy: 0.8206 Epoch 93/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4301 - accuracy: 0.8278 - val_loss: 0.4130 - val_accuracy: 0.8117 Epoch 94/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4298 - accuracy: 0.8084 - val_loss: 0.4219 - val_accuracy: 0.7937 Epoch 95/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4277 - accuracy: 0.7979 - val_loss: 0.4513 - val_accuracy: 0.8027 Epoch 96/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4427 - accuracy: 0.7934 - val_loss: 0.4192 - val_accuracy: 0.8072 Epoch 97/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4289 - accuracy: 0.8099 - val_loss: 0.4151 - val_accuracy: 0.8161 Epoch 98/100 21/21 [==============================] - 0s 2ms/step - loss: 0.4324 - accuracy: 0.8084 - val_loss: 0.4128 - val_accuracy: 0.8117 Epoch 99/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4355 - accuracy: 0.8009 - val_loss: 0.4285 - val_accuracy: 0.8072 Epoch 100/100 21/21 [==============================] - 0s 3ms/step - loss: 0.4321 - accuracy: 0.8144 - val_loss: 0.4166 - val_accuracy: 0.8072
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Precisión del modelo')
plt.xlabel('Epoch')
plt.ylabel('Presición')
plt.legend(['Train', 'Test'])
plt.show()
scores = model.evaluate(X_test, y_test)
print('%s: %.4f%%' % (model.metrics_names[1], scores[1] * 100))
7/7 [==============================] - 0s 1ms/step - loss: 0.4166 - accuracy: 0.8072 accuracy: 80.7175%