<jupyter_start><jupyter_text>1. Configuración inicial<jupyter_code>from keras.datasets import mnist
from keras import layers, models
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.utils import to_categorical
import warnings
warnings.simplefilter("ignore")<jupyter_output><empty_output><jupyter_text>2. Cargamos nuestro set de datos<jupyter_code>(train_data, train_labels), (test_data, test_labels) = mnist.load_data()
train_data.shape
plt.imshow(train_data[25]);
train_labels[25]<jupyter_output><empty_output><jupyter_text>3. Creando nuestro modelo<jupyter_code># Instanciamos el modelo
model = models.Sequential()

# Agregamos unas capas
model.add(layers.Dense(512,activation='relu', input_shape=(28*28,)))
model.add(layers.Dense(10,activation='softmax'))<jupyter_output><empty_output><jupyter_text>4. Compilamos el modelo<jupyter_code># Compilamos
model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
model.summary()<jupyter_output>Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 dense (Dense)               (None, 512)               401920    
                                                                 
 dense_1 (Dense)             (None, 10)                5130      
                                                                 
=================================================================
Total params: 407,050
Trainable params: 407,050
Non-trainable params: 0
_________________________________________________________________<jupyter_text>5. Limpieza de datos<jupyter_code># Reducimos el tamaño de nuestra Red Neuronal porque es más fácil trabajar en 2 dimensiones que en 'n' dimensiones
x_train = train_data.reshape((60000,28*28))
x_train = x_train.astype('float32')/255

x_test = test_data.reshape((10000,28*28))
x_test = x_test.astype('float32')/255

y_train = to_categorical(train_labels)
y_test = to_categorical(test_labels)
display(train_labels[0])
display(y_train[0])<jupyter_output><empty_output><jupyter_text>6. Entrenando el modelo<jupyter_code># Entrenando
model.fit(x_train, y_train, epochs=5, batch_size=128)<jupyter_output>Epoch 1/5
469/469 [==============================] - 5s 10ms/step - loss: 0.2583 - accuracy: 0.9257
Epoch 2/5
469/469 [==============================] - 5s 10ms/step - loss: 0.1048 - accuracy: 0.9693
Epoch 3/5
469/469 [==============================] - 5s 10ms/step - loss: 0.0686 - accuracy: 0.9795
Epoch 4/5
469/469 [==============================] - 5s 10ms/step - loss: 0.0506 - accuracy: 0.9849
Epoch 5/5
469/469 [==============================] - 5s 10ms/step - loss: 0.0380 - accuracy: 0.9884<jupyter_text>7. Evaluando sobre los datos de test<jupyter_code># Evaluamos el modelo
model.evaluate(x_test,y_test)<jupyter_output>313/313 [==============================] - 1s 3ms/step - loss: 0.0649 - accuracy: 0.9802
{'fraction_non_alphanumeric': 0.19901315789473684, 'fraction_numerical': 0.0680921052631579, 'mean_word_length': 4.36331569664903, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '387063', 'license': 'MIT', 'n_tokens_mistral': 1115, 'n_tokens_neox': 953, 'n_words': 190, 'path': 'Notebooks - Deep Learning/Notebook - Entrenamiento de una Red Neuronal con Keras.ipynb', 'repo_name': 'jorge-robledo11/Notebooks', 'size': '3040'}