{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "KdUFcDsdzRyw"
   },
   "source": [
    "# Clonamos el repositorio para obtener los dataSet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "id": "mHReFf3_y9ms",
    "outputId": "c17545fd-c7dd-42c2-e3ad-4f55db21611f"
   },
   "outputs": [],
   "source": [
    "!git clone https://github.com/joanby/machinelearning-az.git"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "vNKZXgtKzU2x"
   },
   "source": [
    "# Damos acceso a nuestro Drive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "colab_type": "code",
    "id": "5gu7KWnzzUQ0",
    "outputId": "abe602b4-3a59-470e-d508-037c6966002b"
   },
   "outputs": [],
   "source": [
    "from google.colab import drive\n",
    "drive.mount('/content/drive')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "1gUxIkHWzfHV"
   },
   "source": [
    "# Test it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "mIQt3jBMzYRE"
   },
   "outputs": [],
   "source": [
    "!ls '/content/drive/My Drive' "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "mHsK36uN0XB-"
   },
   "source": [
    "#Google colab tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "kTzwfUPWzrm4"
   },
   "outputs": [],
   "source": [
    "from google.colab import files # Para manejar los archivos y, por ejemplo, exportar a su navegador\n",
    "import glob # Para manejar los archivos y, por ejemplo, exportar a su navegador\n",
    "from google.colab import drive # Montar tu Google drive"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "uab9OAbV8hYN"
   },
   "source": [
    "#Instalar dependendias"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 122
    },
    "colab_type": "code",
    "id": "qukjDgj98kE4",
    "outputId": "95b5f2b5-7149-436a-b1fb-ad567cc783bd"
   },
   "outputs": [],
   "source": [
    "!pip install sklearn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "3yFpBwmNz70v"
   },
   "source": [
    "# Regresión con Árboles de Decisión"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "v8OxSXXSz-OP"
   },
   "source": [
    "# Cómo importar las librerías\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "edZX51YLzs59"
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "8XfXlqtF0B58"
   },
   "source": [
    "# Importar el data set\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "-nnozsHsz_-N"
   },
   "outputs": [],
   "source": [
    "dataset = pd.read_csv('/content/machinelearning-az/datasets/Part 2 - Regression/Section 8 - Decision Tree Regression/Position_Salaries.csv')\n",
    "X = dataset.iloc[:, 1:2].values\n",
    "y = dataset.iloc[:, 2].values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "SsVEdPzf4XmV"
   },
   "source": [
    "# Dividir el data set en conjunto de entrenamiento y conjunto de testing\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "v9CtwK834bjy"
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "5AH_uCEz68rb"
   },
   "source": [
    "# Escalado de variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "colab_type": "code",
    "id": "oeuAy8LI69vi",
    "outputId": "10346439-d6ac-4abd-b5bb-033e9a284716"
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "sc_X = StandardScaler()\n",
    "X_train = sc_X.fit_transform(X_train)\n",
    "X_test = sc_X.transform(X_test)\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "cgweTaJ67BOB"
   },
   "source": [
    "# Ajustar la regresión con el dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "2AwTWELX7DZQ"
   },
   "outputs": [],
   "source": [
    "from sklearn.tree import DecisionTreeRegressor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "id": "9xFOzJL77Fm4",
    "outputId": "4a6494d7-5a6e-4eed-e3f4-efa27b8317f8"
   },
   "outputs": [],
   "source": [
    "regression = DecisionTreeRegressor(random_state = 0)\n",
    "regression.fit(X, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "je3kcRlG7JV5"
   },
   "source": [
    "# Predicción de nuestros modelos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "HS-M9s587Kj3"
   },
   "outputs": [],
   "source": [
    "y_pred = regression.predict([[6.5]])\n",
    "print(y_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "JnMLSqzW8NH7"
   },
   "source": [
    "# Visualización de los resultados del Modelo Polinómico\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "1qZ3wRR08Oar"
   },
   "outputs": [],
   "source": [
    "X_grid = np.arange(min(X), max(X), 0.1)\n",
    "X_grid = X_grid.reshape(len(X_grid), 1)\n",
    "plt.scatter(X, y, color = \"red\")\n",
    "plt.plot(X, regression.predict(X), color = \"blue\")\n",
    "plt.title(\"Modelo de Regresión\")\n",
    "plt.xlabel(\"Posición del empleado\")\n",
    "plt.ylabel(\"Sueldo (en $)\")\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "multiple_linear_regression_new_version.ipynb",
   "provenance": [],
   "toc_visible": true
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
