diff --git a/PPT11 House Prices Numpy.ipynb b/PPT11 House Prices Numpy.ipynb new file mode 100644 index 0000000..02fd5fc --- /dev/null +++ b/PPT11 House Prices Numpy.ipynb @@ -0,0 +1,392 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Copia de Presentacion_11_alumnos.ipynb", + "provenance": [], + "collapsed_sections": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SnbKAswA5H70", + "colab_type": "text" + }, + "source": [ + " ![texto alternativo](https://drive.google.com/uc?export=view&id=14HGkNoRD0Cp4Z0KyPxvrLaj_u3eG97hC)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AFXXyEkA5TO3", + "colab_type": "text" + }, + "source": [ + " \"Simply\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "VdFUEVlOXN6J", + "colab_type": "text" + }, + "source": [ + "# **Recordando**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7gE6I95qDIgA", + "colab_type": "text" + }, + "source": [ + " \"Simply\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "30ClEV3k6oOS", + "colab_type": "text" + }, + "source": [ + " \"Simply" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xbJS8J0jJiIR", + "colab_type": "text" + }, + "source": [ + " \"Simply" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bedLAzr7Kctc", + "colab_type": "text" + }, + "source": [ + "# **Ejemplo Práctico 1**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_FOFEpBBLUhX", + "colab_type": "text" + }, + "source": [ + "* Implementaremos el método de regresion lineal simple utilizando NumpPy. Recordemos:\n", + "\n", + "\"Simply\n", + "\n", + "* Esta formulación la podiamos expresar de esta forma:\n", + "\n", + "\"Simply" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "m2JnBnpRggR-", + "colab_type": "text" + }, + "source": [ + "Formula: Minimizar el error cuadratico Medio (MSE): $W = (X^{T}X)^{-1}X^TY$" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "WMZKGIE9gNtg", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Sirve para calculo numerico, proporciona funcionalidades para trabajar con arrays, matrices y operaciones matriciales\n", + "import numpy as np \n", + "# lo mismo que hace numpy lo extiende a herramientas cientificas, lo expande. Proporciona otras funcionalidades como tratamiento de imagenes\n", + "import scipy as sc \n", + "# Liberia de visualizacion grafica (SIN EMBARGO, existen otras)\n", + "import matplotlib.pyplot as plt \n" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "-2BAksYJga83", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "Z2Srf3paPTa_", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 125 + }, + "outputId": "9785ddfc-236d-456b-a140-f459caefdae4" + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "text": [ + "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%2fround-lake.dustinice.workers.dev%3a443%2fhttps%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fround-lake.dustinice.workers.dev%3a443%2fhttps%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fround-lake.dustinice.workers.dev%3a443%2fhttps%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fround-lake.dustinice.workers.dev%3a443%2fhttps%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly&response_type=code\n", + "\n", + "Enter your authorization code:\n", + "··········\n", + "Mounted at /content/drive\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1MW7rK78t03N", + "colab_type": "text" + }, + "source": [ + "* Ahora mejoremos la solucion para resolver con todas los atributos de la base de datos" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PFLJrSImnKRo", + "colab_type": "code", + "colab": {} + }, + "source": [ + "\n" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sEE_tMhmuFj0", + "colab_type": "text" + }, + "source": [ + "* Para medir el error de nuestro Modelo, utilizamos el Error cuadratico médio: \n", + "\n", + " $rmse = \\sqrt{(\\frac{1}{n})\\sum_{i=1}^{n}(y_{i} - p_{i})^{2}}$\n", + "\n", + "\"Simply\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "dFMGCp_6utd1", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "Pwg71i0puwpO", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GS05EA58Rdph", + "colab_type": "text" + }, + "source": [ + "# **Ejemplo Práctico 2**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fpUgpOQiRdcH", + "colab_type": "text" + }, + "source": [ + "**El descenso del Gradiente**\n", + "\n", + "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", + "\n", + "Pero siempre existe una solucion!!\n", + "\n", + "Exploremos el descenso del gradiente:\n", + "\n", + " \"Simply\n", + "\n", + "Veamos mejor este ejemplo de una forma animada:\n", + "[An Interactive Tutorial on Numerical Optimization](http://www.benfrederickson.com/numerical-optimization/)\n", + "\n", + "\n", + " \"Simply\n", + "\n", + "\n", + " \"Simply\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FljnyMraDScU", + "colab_type": "text" + }, + "source": [ + "* Ahora vamos a programarlo" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "YDhbZB60Srax", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import numpy as np \n", + "import scipy as sc \n", + "import matplotlib.pyplot as plt" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nRTJAib6S1pM", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DlOUjDXlWoeS", + "colab_type": "text" + }, + "source": [ + "* Ahora generemos un punto aleatorio en nuestro mapa y comencemos a descender" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "lZengMsnWi0M", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xIoApqs_XSOw", + "colab_type": "text" + }, + "source": [ + "* Perfecto, vamos ahora descender hasta una posición minima" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "6urRRhIXXN3i", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "rZNpT2jkexga", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file