Skip to content

Commit e1471e6

Browse files
committed
Creado mediante Colaboratory
1 parent 524af79 commit e1471e6

1 file changed

Lines changed: 392 additions & 0 deletions

File tree

PPT11 House Prices Numpy.ipynb

Lines changed: 392 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,392 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Copia de Presentacion_11_alumnos.ipynb",
7+
"provenance": [],
8+
"collapsed_sections": [],
9+
"include_colab_link": true
10+
},
11+
"kernelspec": {
12+
"name": "python3",
13+
"display_name": "Python 3"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {
20+
"id": "view-in-github",
21+
"colab_type": "text"
22+
},
23+
"source": [
24+
"<a href=\"https://colab.research.google.com/github/ernestcr/DataSciencePython/blob/master/PPT11%20House%20Prices%20Numpy.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {
30+
"id": "SnbKAswA5H70",
31+
"colab_type": "text"
32+
},
33+
"source": [
34+
" ![texto alternativo](https://drive.google.com/uc?export=view&id=14HGkNoRD0Cp4Z0KyPxvrLaj_u3eG97hC)"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"metadata": {
40+
"id": "AFXXyEkA5TO3",
41+
"colab_type": "text"
42+
},
43+
"source": [
44+
" <img src=\"https://drive.google.com/uc?export=view&id=1dpWC3HxKCInKLhkhLPOyYYyV4b0E_sms\" alt=\"Simply Easy Learning\" width=\"800\" \n",
45+
" height=\"450\">\n"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {
51+
"id": "VdFUEVlOXN6J",
52+
"colab_type": "text"
53+
},
54+
"source": [
55+
"# **Recordando**"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"metadata": {
61+
"id": "7gE6I95qDIgA",
62+
"colab_type": "text"
63+
},
64+
"source": [
65+
" <img src=\"https://drive.google.com/uc?export=view&id=17iqwupvy5Nq2PO59Loj0gaU-e6IUYKSS\" alt=\"Simply Easy Learning\" width=\"800\" \n",
66+
" height=\"450\">\n"
67+
]
68+
},
69+
{
70+
"cell_type": "markdown",
71+
"metadata": {
72+
"id": "30ClEV3k6oOS",
73+
"colab_type": "text"
74+
},
75+
"source": [
76+
" <img src=\"https://drive.google.com/uc?export=view&id=12OkMjp-HFxBUrp4CxC4i6GjWuAreunKN\" alt=\"Simply Easy Learning\" width=\"800\" \n",
77+
" height=\"450\">"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {
83+
"id": "xbJS8J0jJiIR",
84+
"colab_type": "text"
85+
},
86+
"source": [
87+
" <img src=\"https://intellipaat.com/mediaFiles/2018/12/Python-NumPy-Cheat-Sheet-1.png\" alt=\"Simply Easy Learning\" width=\"850\" \n",
88+
" height=\"500\">"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"metadata": {
94+
"id": "bedLAzr7Kctc",
95+
"colab_type": "text"
96+
},
97+
"source": [
98+
"# **Ejemplo Práctico 1**"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {
104+
"id": "_FOFEpBBLUhX",
105+
"colab_type": "text"
106+
},
107+
"source": [
108+
"* Implementaremos el método de regresion lineal simple utilizando NumpPy. Recordemos:\n",
109+
"\n",
110+
"<img src=\"https://drive.google.com/uc?export=view&id=1YTC-Fz1FYb2Q7dRWdTFXjA_BWPgfJmtR\" alt=\"Simply Easy Learning\" width=\"500\" \n",
111+
" height=\"200\">\n",
112+
"\n",
113+
"* Esta formulación la podiamos expresar de esta forma:\n",
114+
"\n",
115+
"<img src=\"https://drive.google.com/uc?export=view&id=16BQtn-NZA-icSvwSdJSBqp_Qd7n5affs\" alt=\"Simply Easy Learning\" width=\"700\" \n",
116+
" height=\"200\">"
117+
]
118+
},
119+
{
120+
"cell_type": "markdown",
121+
"metadata": {
122+
"id": "m2JnBnpRggR-",
123+
"colab_type": "text"
124+
},
125+
"source": [
126+
"Formula: Minimizar el error cuadratico Medio (MSE): $W = (X^{T}X)^{-1}X^TY$"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"metadata": {
132+
"id": "WMZKGIE9gNtg",
133+
"colab_type": "code",
134+
"colab": {}
135+
},
136+
"source": [
137+
"# Sirve para calculo numerico, proporciona funcionalidades para trabajar con arrays, matrices y operaciones matriciales\n",
138+
"import numpy as np \n",
139+
"# lo mismo que hace numpy lo extiende a herramientas cientificas, lo expande. Proporciona otras funcionalidades como tratamiento de imagenes\n",
140+
"import scipy as sc \n",
141+
"# Liberia de visualizacion grafica (SIN EMBARGO, existen otras)\n",
142+
"import matplotlib.pyplot as plt \n"
143+
],
144+
"execution_count": null,
145+
"outputs": []
146+
},
147+
{
148+
"cell_type": "code",
149+
"metadata": {
150+
"id": "-2BAksYJga83",
151+
"colab_type": "code",
152+
"colab": {}
153+
},
154+
"source": [
155+
""
156+
],
157+
"execution_count": null,
158+
"outputs": []
159+
},
160+
{
161+
"cell_type": "code",
162+
"metadata": {
163+
"id": "Z2Srf3paPTa_",
164+
"colab_type": "code",
165+
"colab": {
166+
"base_uri": "https://localhost:8080/",
167+
"height": 125
168+
},
169+
"outputId": "9785ddfc-236d-456b-a140-f459caefdae4"
170+
},
171+
"source": [
172+
"from google.colab import drive\n",
173+
"drive.mount('/content/drive')"
174+
],
175+
"execution_count": null,
176+
"outputs": [
177+
{
178+
"output_type": "stream",
179+
"text": [
180+
"Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly&response_type=code\n",
181+
"\n",
182+
"Enter your authorization code:\n",
183+
"··········\n",
184+
"Mounted at /content/drive\n"
185+
],
186+
"name": "stdout"
187+
}
188+
]
189+
},
190+
{
191+
"cell_type": "markdown",
192+
"metadata": {
193+
"id": "1MW7rK78t03N",
194+
"colab_type": "text"
195+
},
196+
"source": [
197+
"* Ahora mejoremos la solucion para resolver con todas los atributos de la base de datos"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"metadata": {
203+
"id": "PFLJrSImnKRo",
204+
"colab_type": "code",
205+
"colab": {}
206+
},
207+
"source": [
208+
"\n"
209+
],
210+
"execution_count": null,
211+
"outputs": []
212+
},
213+
{
214+
"cell_type": "markdown",
215+
"metadata": {
216+
"id": "sEE_tMhmuFj0",
217+
"colab_type": "text"
218+
},
219+
"source": [
220+
"* Para medir el error de nuestro Modelo, utilizamos el Error cuadratico médio: \n",
221+
"\n",
222+
" $rmse = \\sqrt{(\\frac{1}{n})\\sum_{i=1}^{n}(y_{i} - p_{i})^{2}}$\n",
223+
"\n",
224+
"<img src=\"https://iartificial.net/wp-content/uploads/2018/12/error-regresion-lineal2.png\" alt=\"Simply Easy Learning\" width=\"300\" \n",
225+
" height=\"200\">\n",
226+
"\n"
227+
]
228+
},
229+
{
230+
"cell_type": "code",
231+
"metadata": {
232+
"id": "dFMGCp_6utd1",
233+
"colab_type": "code",
234+
"colab": {}
235+
},
236+
"source": [
237+
""
238+
],
239+
"execution_count": null,
240+
"outputs": []
241+
},
242+
{
243+
"cell_type": "code",
244+
"metadata": {
245+
"id": "Pwg71i0puwpO",
246+
"colab_type": "code",
247+
"colab": {}
248+
},
249+
"source": [
250+
""
251+
],
252+
"execution_count": null,
253+
"outputs": []
254+
},
255+
{
256+
"cell_type": "markdown",
257+
"metadata": {
258+
"id": "GS05EA58Rdph",
259+
"colab_type": "text"
260+
},
261+
"source": [
262+
"# **Ejemplo Práctico 2**"
263+
]
264+
},
265+
{
266+
"cell_type": "markdown",
267+
"metadata": {
268+
"id": "fpUgpOQiRdcH",
269+
"colab_type": "text"
270+
},
271+
"source": [
272+
"**El descenso del Gradiente**\n",
273+
"\n",
274+
"El ejemplo de regresion lineal nos dio un resultado factible calculando el valor de los pesos con error mínimo de forma ditecta, pero, en la práctica su uso es inviable debido al alto costo de calcular una matriz inversa cuando tenemos demasiado atributos por muestra.\n",
275+
"\n",
276+
"Pero siempre existe una solucion!!\n",
277+
"\n",
278+
"Exploremos el descenso del gradiente:\n",
279+
"\n",
280+
" <img src=\"https://miro.medium.com/max/694/1*7030GXGlVD-u9VyqVJdTyw.png\" alt=\"Simply Easy Learning\" width=\"500\" height=\"250\">\n",
281+
"\n",
282+
"Veamos mejor este ejemplo de una forma animada:\n",
283+
"[An Interactive Tutorial on Numerical Optimization](http://www.benfrederickson.com/numerical-optimization/)\n",
284+
"\n",
285+
"\n",
286+
" <img src=\"https://developers.google.com/machine-learning/crash-course/images/GradientDescentNegativeGradient.svg?hl=es-419\" alt=\"Simply Easy Learning\" width=\"400\">\n",
287+
"\n",
288+
"\n",
289+
" <img src=\"https://developers.google.com/machine-learning/glossary/images/nonconvex_function.svg?hl=es\" alt=\"Simply Easy Learning\" width=\"280\">\n",
290+
"\n",
291+
"\n"
292+
]
293+
},
294+
{
295+
"cell_type": "markdown",
296+
"metadata": {
297+
"id": "FljnyMraDScU",
298+
"colab_type": "text"
299+
},
300+
"source": [
301+
"* Ahora vamos a programarlo"
302+
]
303+
},
304+
{
305+
"cell_type": "code",
306+
"metadata": {
307+
"id": "YDhbZB60Srax",
308+
"colab_type": "code",
309+
"colab": {}
310+
},
311+
"source": [
312+
"import numpy as np \n",
313+
"import scipy as sc \n",
314+
"import matplotlib.pyplot as plt"
315+
],
316+
"execution_count": null,
317+
"outputs": []
318+
},
319+
{
320+
"cell_type": "code",
321+
"metadata": {
322+
"id": "nRTJAib6S1pM",
323+
"colab_type": "code",
324+
"colab": {}
325+
},
326+
"source": [
327+
""
328+
],
329+
"execution_count": null,
330+
"outputs": []
331+
},
332+
{
333+
"cell_type": "markdown",
334+
"metadata": {
335+
"id": "DlOUjDXlWoeS",
336+
"colab_type": "text"
337+
},
338+
"source": [
339+
"* Ahora generemos un punto aleatorio en nuestro mapa y comencemos a descender"
340+
]
341+
},
342+
{
343+
"cell_type": "code",
344+
"metadata": {
345+
"id": "lZengMsnWi0M",
346+
"colab_type": "code",
347+
"colab": {}
348+
},
349+
"source": [
350+
""
351+
],
352+
"execution_count": null,
353+
"outputs": []
354+
},
355+
{
356+
"cell_type": "markdown",
357+
"metadata": {
358+
"id": "xIoApqs_XSOw",
359+
"colab_type": "text"
360+
},
361+
"source": [
362+
"* Perfecto, vamos ahora descender hasta una posición minima"
363+
]
364+
},
365+
{
366+
"cell_type": "code",
367+
"metadata": {
368+
"id": "6urRRhIXXN3i",
369+
"colab_type": "code",
370+
"colab": {}
371+
},
372+
"source": [
373+
""
374+
],
375+
"execution_count": null,
376+
"outputs": []
377+
},
378+
{
379+
"cell_type": "code",
380+
"metadata": {
381+
"id": "rZNpT2jkexga",
382+
"colab_type": "code",
383+
"colab": {}
384+
},
385+
"source": [
386+
""
387+
],
388+
"execution_count": null,
389+
"outputs": []
390+
}
391+
]
392+
}

0 commit comments

Comments
 (0)