Skip to content

Commit 75ae38c

Browse files
authored
Merge pull request #3 from johnnync13/master
Tema01 colab
2 parents d0ae5f9 + 5d2fc1a commit 75ae38c

17 files changed

+8199
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

scripts/.DS_Store

8 KB
Binary file not shown.

scripts/tema01/.DS_Store

6 KB
Binary file not shown.
Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "01-general-info_colab.ipynb",
7+
"provenance": [],
8+
"collapsed_sections": []
9+
},
10+
"kernelspec": {
11+
"display_name": "Python 3",
12+
"language": "python",
13+
"name": "python3"
14+
},
15+
"language_info": {
16+
"codemirror_mode": {
17+
"name": "ipython",
18+
"version": 3
19+
},
20+
"file_extension": ".py",
21+
"mimetype": "text/x-python",
22+
"name": "python",
23+
"nbconvert_exporter": "python",
24+
"pygments_lexer": "ipython3",
25+
"version": "3.8.3"
26+
},
27+
"accelerator": "GPU"
28+
},
29+
"cells": [
30+
{
31+
"cell_type": "markdown",
32+
"metadata": {
33+
"colab_type": "text",
34+
"id": "KdUFcDsdzRyw"
35+
},
36+
"source": [
37+
"# Clonamos el repositorio para obtener los dataSet"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"metadata": {
43+
"colab_type": "code",
44+
"id": "mHReFf3_y9ms",
45+
"colab": {}
46+
},
47+
"source": [
48+
"!git clone https://github.com/joanby/tensorflow.git"
49+
],
50+
"execution_count": null,
51+
"outputs": []
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"metadata": {
56+
"colab_type": "text",
57+
"id": "vNKZXgtKzU2x"
58+
},
59+
"source": [
60+
"# Damos acceso a nuestro Drive"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"metadata": {
66+
"colab_type": "code",
67+
"id": "5gu7KWnzzUQ0",
68+
"colab": {}
69+
},
70+
"source": [
71+
"from google.colab import drive\n",
72+
"drive.mount('/content/drive')"
73+
],
74+
"execution_count": null,
75+
"outputs": []
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"metadata": {
80+
"colab_type": "text",
81+
"id": "1gUxIkHWzfHV"
82+
},
83+
"source": [
84+
"# Test it"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"metadata": {
90+
"colab_type": "code",
91+
"id": "mIQt3jBMzYRE",
92+
"colab": {}
93+
},
94+
"source": [
95+
"!ls '/content/drive/My Drive' "
96+
],
97+
"execution_count": null,
98+
"outputs": []
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"metadata": {
103+
"colab_type": "text",
104+
"id": "mHsK36uN0XB-"
105+
},
106+
"source": [
107+
"# Google colab tools"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"metadata": {
113+
"colab_type": "code",
114+
"id": "kTzwfUPWzrm4",
115+
"colab": {}
116+
},
117+
"source": [
118+
"from google.colab import files # Para manejar los archivos y, por ejemplo, exportar a su navegador\n",
119+
"import glob # Para manejar los archivos y, por ejemplo, exportar a su navegador\n",
120+
"from google.colab import drive # Montar tu Google drive"
121+
],
122+
"execution_count": null,
123+
"outputs": []
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {
128+
"id": "yQQ8nLiMY6wM",
129+
"colab_type": "text"
130+
},
131+
"source": [
132+
"##Especificando la versión de TensorFlow\n",
133+
"\n",
134+
"Ejecutando \"importar tensorflow\" importará la versión por defecto (actualmente 2.x). Puedes usar la 1.x ejecutando una celda con la \"versión mágica de tensorflow\" **antes de ejecutar \"importar tensorflow\".\n",
135+
"\n",
136+
"### Si no funciona hacer el pip install\n"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"metadata": {
142+
"id": "1j---G3ZY6wN",
143+
"colab_type": "code",
144+
"colab": {}
145+
},
146+
"source": [
147+
"#!pip install tensorflow==1.14\n",
148+
"%tensorflow_version 1.x"
149+
],
150+
"execution_count": null,
151+
"outputs": []
152+
},
153+
{
154+
"cell_type": "markdown",
155+
"metadata": {
156+
"id": "S-OIfuWLujbt",
157+
"colab_type": "text"
158+
},
159+
"source": [
160+
"# Importar Tensorflow"
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"metadata": {
166+
"id": "OPSus73fumtP",
167+
"colab_type": "code",
168+
"colab": {}
169+
},
170+
"source": [
171+
"import tensorflow as tf\n",
172+
"print(tf.__version__)"
173+
],
174+
"execution_count": null,
175+
"outputs": []
176+
},
177+
{
178+
"cell_type": "markdown",
179+
"metadata": {
180+
"id": "Z9ZTNKptt8dA",
181+
"colab_type": "text"
182+
},
183+
"source": [
184+
"# Como funciona TensorFlow"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {
190+
"id": "IC_M6LlGuAp-",
191+
"colab_type": "text"
192+
},
193+
"source": [
194+
"1. Importación o generación del conjunto de datos.\n",
195+
"2. Transformación y normalización de los datos.\n",
196+
"3. Dividir el conjunto de datos en conjunto de entrenamiento, de validación y de test.\n",
197+
"4. Definir los hiperparámetros del algoritmo"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"metadata": {
203+
"id": "2-V4YdfJsCL5",
204+
"colab_type": "code",
205+
"colab": {}
206+
},
207+
"source": [
208+
"learning_rate = 0.01\n",
209+
"batch_size = 50\n",
210+
"iterations = 10000"
211+
],
212+
"execution_count": null,
213+
"outputs": []
214+
},
215+
{
216+
"cell_type": "markdown",
217+
"metadata": {
218+
"id": "7v5UxcIMuINd",
219+
"colab_type": "text"
220+
},
221+
"source": [
222+
"5. Inicializar variables y placeholders"
223+
]
224+
},
225+
{
226+
"cell_type": "code",
227+
"metadata": {
228+
"id": "AbgaGmAFuen3",
229+
"colab_type": "code",
230+
"colab": {}
231+
},
232+
"source": [
233+
"x = tf.constant(30)\n",
234+
"x_input = tf.placeholder(tf.float32, [None, 3]) #None: no sabemos cuantos vectores introducimos Input_size , vectores de 3 coordenadas\n",
235+
"y_input = tf.placeholder(tf.float32, [None, 5]) "
236+
],
237+
"execution_count": null,
238+
"outputs": []
239+
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {
243+
"id": "E6fR1pKJuLaZ",
244+
"colab_type": "text"
245+
},
246+
"source": [
247+
"6. Definir la estructura del modelo del algoritmo.\n",
248+
"$$y = mx+n$$"
249+
]
250+
},
251+
{
252+
"cell_type": "code",
253+
"metadata": {
254+
"id": "t0sPANbqu909",
255+
"colab_type": "code",
256+
"colab": {}
257+
},
258+
"source": [
259+
"y_pred = tf.add(tf.multiply(m_matrix, x_input), n_vector) #add sumar #multiply multiplicar "
260+
],
261+
"execution_count": null,
262+
"outputs": []
263+
},
264+
{
265+
"cell_type": "markdown",
266+
"metadata": {
267+
"id": "1wrcpp_PuSEL",
268+
"colab_type": "text"
269+
},
270+
"source": [
271+
"7. Declarar la función de pérdidas (loss function)\n",
272+
"$$MSE = \\frac{\\sum_{i=1}^n(y_{actual,i}-y_{pred,i})^2}{n}$$"
273+
]
274+
},
275+
{
276+
"cell_type": "code",
277+
"metadata": {
278+
"id": "PMRrdFr8vAA4",
279+
"colab_type": "code",
280+
"colab": {}
281+
},
282+
"source": [
283+
"loss = tf.reduce_mean(tf.square(y_actual - y_pred)) #reducir la media de los cuadrados"
284+
],
285+
"execution_count": null,
286+
"outputs": []
287+
},
288+
{
289+
"cell_type": "markdown",
290+
"metadata": {
291+
"id": "FF8ovbE4uUHB",
292+
"colab_type": "text"
293+
},
294+
"source": [
295+
"8. Inicializar y entrenar el modelo anterior. "
296+
]
297+
},
298+
{
299+
"cell_type": "code",
300+
"metadata": {
301+
"id": "8sv0a7czvClk",
302+
"colab_type": "code",
303+
"colab": {}
304+
},
305+
"source": [
306+
"with tf.Session(graph = graph) as session:\n",
307+
" ...\n",
308+
" session.run(...)\n",
309+
" ...."
310+
],
311+
"execution_count": null,
312+
"outputs": []
313+
},
314+
{
315+
"cell_type": "code",
316+
"metadata": {
317+
"id": "wgpFhDMpvEkn",
318+
"colab_type": "code",
319+
"colab": {}
320+
},
321+
"source": [
322+
"session = tf.Session(graph = graph)\n",
323+
"...\n",
324+
"session.run(...)\n",
325+
"..."
326+
],
327+
"execution_count": null,
328+
"outputs": []
329+
},
330+
{
331+
"cell_type": "markdown",
332+
"metadata": {
333+
"id": "rFYN2Z4yuV79",
334+
"colab_type": "text"
335+
},
336+
"source": [
337+
"9. Evaluación del modelo \n",
338+
"10. Ajustar los hiper parámetros\n",
339+
"11. Publicar (subir a producción) y predecir nuevos resultados"
340+
]
341+
}
342+
]
343+
}

0 commit comments

Comments
 (0)