File size: 1,780 Bytes
e5cbd17 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"GPU disponible:\", tf.config.list_physical_devices('GPU'))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"N = 10000 # muestras\n",
"T = 30 # pasos de tiempo\n",
"F = 10 # features\n",
"\n",
"X = np.random.rand(N, T, F)\n",
"y = np.random.rand(N, 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import LSTM, Dense\n",
"\n",
"model = Sequential([\n",
" LSTM(64, input_shape=(T, F)),\n",
" Dense(1)\n",
"])\n",
"\n",
"model.compile(optimizer='adam', loss='mse')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"history = model.fit(X, y, epochs=5, batch_size=64)\n",
"\n",
"# 6. Graficar pérdida\n",
"plt.plot(history.history['loss'])\n",
"plt.title('Pérdida de entrenamiento')\n",
"plt.xlabel('Época')\n",
"plt.ylabel('Loss')\n",
"plt.grid(True)\n",
"plt.show()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|