{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#import libraries\n",
        "import pandas as pd\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import warnings \n",
        "#We do not want to see warnings\n",
        "warnings.filterwarnings(\"ignore\") "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#import data\n",
        "data = pd.read_csv(\"uber.csv\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Create a data copy\n",
        "df = data.copy()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "<bound method NDFrame.head of         Unnamed: 0                            key  fare_amount  \\\n",
              "0         24238194    2015-05-07 19:52:06.0000003          7.5   \n",
              "1         27835199    2009-07-17 20:04:56.0000002          7.7   \n",
              "2         44984355   2009-08-24 21:45:00.00000061         12.9   \n",
              "3         25894730    2009-06-26 08:22:21.0000001          5.3   \n",
              "4         17610152  2014-08-28 17:47:00.000000188         16.0   \n",
              "...            ...                            ...          ...   \n",
              "199995    42598914   2012-10-28 10:49:00.00000053          3.0   \n",
              "199996    16382965    2014-03-14 01:09:00.0000008          7.5   \n",
              "199997    27804658   2009-06-29 00:42:00.00000078         30.9   \n",
              "199998    20259894    2015-05-20 14:56:25.0000004         14.5   \n",
              "199999    11951496   2010-05-15 04:08:00.00000076         14.1   \n",
              "\n",
              "                pickup_datetime  pickup_longitude  pickup_latitude  \\\n",
              "0       2015-05-07 19:52:06 UTC        -73.999817        40.738354   \n",
              "1       2009-07-17 20:04:56 UTC        -73.994355        40.728225   \n",
              "2       2009-08-24 21:45:00 UTC        -74.005043        40.740770   \n",
              "3       2009-06-26 08:22:21 UTC        -73.976124        40.790844   \n",
              "4       2014-08-28 17:47:00 UTC        -73.925023        40.744085   \n",
              "...                         ...               ...              ...   \n",
              "199995  2012-10-28 10:49:00 UTC        -73.987042        40.739367   \n",
              "199996  2014-03-14 01:09:00 UTC        -73.984722        40.736837   \n",
              "199997  2009-06-29 00:42:00 UTC        -73.986017        40.756487   \n",
              "199998  2015-05-20 14:56:25 UTC        -73.997124        40.725452   \n",
              "199999  2010-05-15 04:08:00 UTC        -73.984395        40.720077   \n",
              "\n",
              "        dropoff_longitude  dropoff_latitude  passenger_count  \n",
              "0              -73.999512         40.723217                1  \n",
              "1              -73.994710         40.750325                1  \n",
              "2              -73.962565         40.772647                1  \n",
              "3              -73.965316         40.803349                3  \n",
              "4              -73.973082         40.761247                5  \n",
              "...                   ...               ...              ...  \n",
              "199995         -73.986525         40.740297                1  \n",
              "199996         -74.006672         40.739620                1  \n",
              "199997         -73.858957         40.692588                2  \n",
              "199998         -73.983215         40.695415                1  \n",
              "199999         -73.985508         40.768793                1  \n",
              "\n",
              "[200000 rows x 9 columns]>"
            ]
          },
          "execution_count": 6,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "#Print data\n",
        "df.head"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 200000 entries, 0 to 199999\n",
            "Data columns (total 9 columns):\n",
            " #   Column             Non-Null Count   Dtype  \n",
            "---  ------             --------------   -----  \n",
            " 0   Unnamed: 0         200000 non-null  int64  \n",
            " 1   key                200000 non-null  object \n",
            " 2   fare_amount        200000 non-null  float64\n",
            " 3   pickup_datetime    200000 non-null  object \n",
            " 4   pickup_longitude   200000 non-null  float64\n",
            " 5   pickup_latitude    200000 non-null  float64\n",
            " 6   dropoff_longitude  199999 non-null  float64\n",
            " 7   dropoff_latitude   199999 non-null  float64\n",
            " 8   passenger_count    200000 non-null  int64  \n",
            "dtypes: float64(5), int64(2), object(2)\n",
            "memory usage: 13.7+ MB\n"
          ]
        }
      ],
      "source": [
        "#Get Info\n",
        "df.info()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "0        2015-05-07 19:52:06+00:00\n",
            "1        2009-07-17 20:04:56+00:00\n",
            "2        2009-08-24 21:45:00+00:00\n",
            "3        2009-06-26 08:22:21+00:00\n",
            "4        2014-08-28 17:47:00+00:00\n",
            "                    ...           \n",
            "199995   2012-10-28 10:49:00+00:00\n",
            "199996   2014-03-14 01:09:00+00:00\n",
            "199997   2009-06-29 00:42:00+00:00\n",
            "199998   2015-05-20 14:56:25+00:00\n",
            "199999   2010-05-15 04:08:00+00:00\n",
            "Name: pickup_datetime, Length: 200000, dtype: datetime64[ns, UTC]\n"
          ]
        }
      ],
      "source": [
        "#pickup_datetime is not in required data format\n",
        "df[\"pickup_datetime\"] = pd.to_datetime(df[\"pickup_datetime\"])\n",
        "print(df[\"pickup_datetime\"])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 200000 entries, 0 to 199999\n",
            "Data columns (total 9 columns):\n",
            " #   Column             Non-Null Count   Dtype              \n",
            "---  ------             --------------   -----              \n",
            " 0   Unnamed: 0         200000 non-null  int64              \n",
            " 1   key                200000 non-null  object             \n",
            " 2   fare_amount        200000 non-null  float64            \n",
            " 3   pickup_datetime    200000 non-null  datetime64[ns, UTC]\n",
            " 4   pickup_longitude   200000 non-null  float64            \n",
            " 5   pickup_latitude    200000 non-null  float64            \n",
            " 6   dropoff_longitude  199999 non-null  float64            \n",
            " 7   dropoff_latitude   199999 non-null  float64            \n",
            " 8   passenger_count    200000 non-null  int64              \n",
            "dtypes: datetime64[ns, UTC](1), float64(5), int64(2), object(1)\n",
            "memory usage: 13.7+ MB\n"
          ]
        }
      ],
      "source": [
        "df.info()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Unnamed: 0</th>\n",
              "      <th>fare_amount</th>\n",
              "      <th>pickup_longitude</th>\n",
              "      <th>pickup_latitude</th>\n",
              "      <th>dropoff_longitude</th>\n",
              "      <th>dropoff_latitude</th>\n",
              "      <th>passenger_count</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>2.000000e+05</td>\n",
              "      <td>200000.000000</td>\n",
              "      <td>200000.000000</td>\n",
              "      <td>200000.000000</td>\n",
              "      <td>199999.000000</td>\n",
              "      <td>199999.000000</td>\n",
              "      <td>200000.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>2.771250e+07</td>\n",
              "      <td>11.359955</td>\n",
              "      <td>-72.527638</td>\n",
              "      <td>39.935885</td>\n",
              "      <td>-72.525292</td>\n",
              "      <td>39.923890</td>\n",
              "      <td>1.684535</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>1.601382e+07</td>\n",
              "      <td>9.901776</td>\n",
              "      <td>11.437787</td>\n",
              "      <td>7.720539</td>\n",
              "      <td>13.117408</td>\n",
              "      <td>6.794829</td>\n",
              "      <td>1.385997</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>1.000000e+00</td>\n",
              "      <td>-52.000000</td>\n",
              "      <td>-1340.648410</td>\n",
              "      <td>-74.015515</td>\n",
              "      <td>-3356.666300</td>\n",
              "      <td>-881.985513</td>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>1.382535e+07</td>\n",
              "      <td>6.000000</td>\n",
              "      <td>-73.992065</td>\n",
              "      <td>40.734796</td>\n",
              "      <td>-73.991407</td>\n",
              "      <td>40.733823</td>\n",
              "      <td>1.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>2.774550e+07</td>\n",
              "      <td>8.500000</td>\n",
              "      <td>-73.981823</td>\n",
              "      <td>40.752592</td>\n",
              "      <td>-73.980093</td>\n",
              "      <td>40.753042</td>\n",
              "      <td>1.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>4.155530e+07</td>\n",
              "      <td>12.500000</td>\n",
              "      <td>-73.967154</td>\n",
              "      <td>40.767158</td>\n",
              "      <td>-73.963658</td>\n",
              "      <td>40.768001</td>\n",
              "      <td>2.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>5.542357e+07</td>\n",
              "      <td>499.000000</td>\n",
              "      <td>57.418457</td>\n",
              "      <td>1644.421482</td>\n",
              "      <td>1153.572603</td>\n",
              "      <td>872.697628</td>\n",
              "      <td>208.000000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "         Unnamed: 0    fare_amount  pickup_longitude  pickup_latitude  \\\n",
              "count  2.000000e+05  200000.000000     200000.000000    200000.000000   \n",
              "mean   2.771250e+07      11.359955        -72.527638        39.935885   \n",
              "std    1.601382e+07       9.901776         11.437787         7.720539   \n",
              "min    1.000000e+00     -52.000000      -1340.648410       -74.015515   \n",
              "25%    1.382535e+07       6.000000        -73.992065        40.734796   \n",
              "50%    2.774550e+07       8.500000        -73.981823        40.752592   \n",
              "75%    4.155530e+07      12.500000        -73.967154        40.767158   \n",
              "max    5.542357e+07     499.000000         57.418457      1644.421482   \n",
              "\n",
              "       dropoff_longitude  dropoff_latitude  passenger_count  \n",
              "count      199999.000000     199999.000000    200000.000000  \n",
              "mean          -72.525292         39.923890         1.684535  \n",
              "std            13.117408          6.794829         1.385997  \n",
              "min         -3356.666300       -881.985513         0.000000  \n",
              "25%           -73.991407         40.733823         1.000000  \n",
              "50%           -73.980093         40.753042         1.000000  \n",
              "75%           -73.963658         40.768001         2.000000  \n",
              "max          1153.572603        872.697628       208.000000  "
            ]
          },
          "execution_count": 10,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "#Statistics of data\n",
        "df.describe()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Unnamed: 0           0\n",
              "key                  0\n",
              "fare_amount          0\n",
              "pickup_datetime      0\n",
              "pickup_longitude     0\n",
              "pickup_latitude      0\n",
              "dropoff_longitude    1\n",
              "dropoff_latitude     1\n",
              "passenger_count      0\n",
              "dtype: int64"
            ]
          },
          "execution_count": 11,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "#Number of missing values\n",
        "df.isnull().sum()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "                   Unnamed: 0  fare_amount  pickup_longitude  pickup_latitude  \\\n",
            "Unnamed: 0           1.000000     0.000589          0.000230        -0.000341   \n",
            "fare_amount          0.000589     1.000000          0.010457        -0.008481   \n",
            "pickup_longitude     0.000230     0.010457          1.000000        -0.816461   \n",
            "pickup_latitude     -0.000341    -0.008481         -0.816461         1.000000   \n",
            "dropoff_longitude    0.000270     0.008986          0.833026        -0.774787   \n",
            "dropoff_latitude     0.000271    -0.011014         -0.846324         0.702367   \n",
            "passenger_count      0.002257     0.010150         -0.000414        -0.001560   \n",
            "\n",
            "                   dropoff_longitude  dropoff_latitude  passenger_count  \n",
            "Unnamed: 0                  0.000270          0.000271         0.002257  \n",
            "fare_amount                 0.008986         -0.011014         0.010150  \n",
            "pickup_longitude            0.833026         -0.846324        -0.000414  \n",
            "pickup_latitude            -0.774787          0.702367        -0.001560  \n",
            "dropoff_longitude           1.000000         -0.917010         0.000033  \n",
            "dropoff_latitude           -0.917010          1.000000        -0.000659  \n",
            "passenger_count             0.000033         -0.000659         1.000000  \n"
          ]
        }
      ],
      "source": [
        "#Correlation\n",
        "cor=df.select_dtypes(include=['number']).corr()\n",
        "print(cor)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Drop the rows with missing values\n",
        "df.dropna(inplace=True)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'whiskers': [<matplotlib.lines.Line2D at 0x173fbb7f650>,\n",
              "  <matplotlib.lines.Line2D at 0x173fbb7f8d0>],\n",
              " 'caps': [<matplotlib.lines.Line2D at 0x173fbb75150>,\n",
              "  <matplotlib.lines.Line2D at 0x173fbb77010>],\n",
              " 'boxes': [<matplotlib.lines.Line2D at 0x173fbb7ce50>],\n",
              " 'medians': [<matplotlib.lines.Line2D at 0x173fbb77d90>],\n",
              " 'fliers': [<matplotlib.lines.Line2D at 0x173fbb77b90>],\n",
              " 'means': []}"
            ]
          },
          "execution_count": 14,
          "metadata": {},
          "output_type": "execute_result"
        },
        {
          "data": {
            "image/png": "[encoded data, 14416 characters]",
            "text/plain": [
              "<Figure size 640x480 with 1 Axes>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "plt.boxplot(df['fare_amount'])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "        Unnamed: 0                            key  fare_amount  \\\n",
            "0         24238194    2015-05-07 19:52:06.0000003          7.5   \n",
            "1         27835199    2009-07-17 20:04:56.0000002          7.7   \n",
            "2         44984355   2009-08-24 21:45:00.00000061         12.9   \n",
            "3         25894730    2009-06-26 08:22:21.0000001          5.3   \n",
            "4         17610152  2014-08-28 17:47:00.000000188         16.0   \n",
            "...            ...                            ...          ...   \n",
            "199994     3189201  2014-01-31 14:42:00.000000181         12.0   \n",
            "199996    16382965    2014-03-14 01:09:00.0000008          7.5   \n",
            "199997    27804658   2009-06-29 00:42:00.00000078         30.9   \n",
            "199998    20259894    2015-05-20 14:56:25.0000004         14.5   \n",
            "199999    11951496   2010-05-15 04:08:00.00000076         14.1   \n",
            "\n",
            "                 pickup_datetime  pickup_longitude  pickup_latitude  \\\n",
            "0      2015-05-07 19:52:06+00:00        -73.999817        40.738354   \n",
            "1      2009-07-17 20:04:56+00:00        -73.994355        40.728225   \n",
            "2      2009-08-24 21:45:00+00:00        -74.005043        40.740770   \n",
            "3      2009-06-26 08:22:21+00:00        -73.976124        40.790844   \n",
            "4      2014-08-28 17:47:00+00:00        -73.925023        40.744085   \n",
            "...                          ...               ...              ...   \n",
            "199994 2014-01-31 14:42:00+00:00        -73.983070        40.760770   \n",
            "199996 2014-03-14 01:09:00+00:00        -73.984722        40.736837   \n",
            "199997 2009-06-29 00:42:00+00:00        -73.986017        40.756487   \n",
            "199998 2015-05-20 14:56:25+00:00        -73.997124        40.725452   \n",
            "199999 2010-05-15 04:08:00+00:00        -73.984395        40.720077   \n",
            "\n",
            "        dropoff_longitude  dropoff_latitude  passenger_count  \n",
            "0              -73.999512         40.723217                1  \n",
            "1              -73.994710         40.750325                1  \n",
            "2              -73.962565         40.772647                1  \n",
            "3              -73.965316         40.803349                3  \n",
            "4              -73.973082         40.761247                5  \n",
            "...                   ...               ...              ...  \n",
            "199994         -73.972972         40.754177                1  \n",
            "199996         -74.006672         40.739620                1  \n",
            "199997         -73.858957         40.692588                2  \n",
            "199998         -73.983215         40.695415                1  \n",
            "199999         -73.985508         40.768793                1  \n",
            "\n",
            "[194911 rows x 9 columns]\n"
          ]
        },
        {
          "data": {
            "text/plain": [
              "{'whiskers': [<matplotlib.lines.Line2D at 0x173812bffd0>,\n",
              "  <matplotlib.lines.Line2D at 0x173812cca90>],\n",
              " 'caps': [<matplotlib.lines.Line2D at 0x173812cd410>,\n",
              "  <matplotlib.lines.Line2D at 0x173812cdd10>],\n",
              " 'boxes': [<matplotlib.lines.Line2D at 0x173812bf750>],\n",
              " 'medians': [<matplotlib.lines.Line2D at 0x173812ce650>],\n",
              " 'fliers': [<matplotlib.lines.Line2D at 0x173812cef10>],\n",
              " 'means': []}"
            ]
          },
          "execution_count": 15,
          "metadata": {},
          "output_type": "execute_result"
        },
        {
          "data": {
            "image/png": "[encoded data, 7840 characters]",
            "text/plain": [
              "<Figure size 640x480 with 1 Axes>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "#Remove Outliers\n",
        "q_low = df[\"fare_amount\"].quantile(0.01)\n",
        "q_hi  = df[\"fare_amount\"].quantile(0.99)\n",
        "\n",
        "df = df[(df[\"fare_amount\"] < q_hi) & (df[\"fare_amount\"] > q_low)]\n",
        "print(df)\n",
        "plt.boxplot(df['fare_amount'])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Unnamed: 0           0\n",
              "key                  0\n",
              "fare_amount          0\n",
              "pickup_datetime      0\n",
              "pickup_longitude     0\n",
              "pickup_latitude      0\n",
              "dropoff_longitude    0\n",
              "dropoff_latitude     0\n",
              "passenger_count      0\n",
              "dtype: int64"
            ]
          },
          "execution_count": 16,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "#Check the missing values now\n",
        "df.isnull().sum()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Time to apply learning models\n",
        "from sklearn.model_selection import train_test_split"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Take x as predictor variable\n",
        "x = df.drop(\"fare_amount\", axis = 1)\n",
        "#And y as target variable\n",
        "y = df['fare_amount']\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Necessary to apply model\n",
        "x['pickup_datetime'] = pd.to_numeric(pd.to_datetime(x['pickup_datetime']))\n",
        "x = x.loc[:, x.columns.str.contains('^Unnamed')]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 1)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "from sklearn.linear_model import LinearRegression"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<style>#sk-container-id-1 {\n",
              "  /* Definition of color scheme common for light and dark mode */\n",
              "  --sklearn-color-text: #000;\n",
              "  --sklearn-color-text-muted: #666;\n",
              "  --sklearn-color-line: gray;\n",
              "  /* Definition of color scheme for unfitted estimators */\n",
              "  --sklearn-color-unfitted-level-0: #fff5e6;\n",
              "  --sklearn-color-unfitted-level-1: #f6e4d2;\n",
              "  --sklearn-color-unfitted-level-2: #ffe0b3;\n",
              "  --sklearn-color-unfitted-level-3: chocolate;\n",
              "  /* Definition of color scheme for fitted estimators */\n",
              "  --sklearn-color-fitted-level-0: #f0f8ff;\n",
              "  --sklearn-color-fitted-level-1: #d4ebff;\n",
              "  --sklearn-color-fitted-level-2: #b3dbfd;\n",
              "  --sklearn-color-fitted-level-3: cornflowerblue;\n",
              "\n",
              "  /* Specific color for light theme */\n",
              "  --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
              "  --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
              "  --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
              "  --sklearn-color-icon: #696969;\n",
              "\n",
              "  @media (prefers-color-scheme: dark) {\n",
              "    /* Redefinition of color scheme for dark theme */\n",
              "    --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
              "    --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
              "    --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
              "    --sklearn-color-icon: #878787;\n",
              "  }\n",
              "}\n",
              "\n",
              "#sk-container-id-1 {\n",
              "  color: var(--sklearn-color-text);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 pre {\n",
              "  padding: 0;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 input.sk-hidden--visually {\n",
              "  border: 0;\n",
              "  clip: rect(1px 1px 1px 1px);\n",
              "  clip: rect(1px, 1px, 1px, 1px);\n",
              "  height: 1px;\n",
              "  margin: -1px;\n",
              "  overflow: hidden;\n",
              "  padding: 0;\n",
              "  position: absolute;\n",
              "  width: 1px;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-dashed-wrapped {\n",
              "  border: 1px dashed var(--sklearn-color-line);\n",
              "  margin: 0 0.4em 0.5em 0.4em;\n",
              "  box-sizing: border-box;\n",
              "  padding-bottom: 0.4em;\n",
              "  background-color: var(--sklearn-color-background);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-container {\n",
              "  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
              "     but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
              "     so we also need the `!important` here to be able to override the\n",
              "     default hidden behavior on the sphinx rendered scikit-learn.org.\n",
              "     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
              "  display: inline-block !important;\n",
              "  position: relative;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-text-repr-fallback {\n",
              "  display: none;\n",
              "}\n",
              "\n",
              "div.sk-parallel-item,\n",
              "div.sk-serial,\n",
              "div.sk-item {\n",
              "  /* draw centered vertical line to link estimators */\n",
              "  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
              "  background-size: 2px 100%;\n",
              "  background-repeat: no-repeat;\n",
              "  background-position: center center;\n",
              "}\n",
              "\n",
              "/* Parallel-specific style estimator block */\n",
              "\n",
              "#sk-container-id-1 div.sk-parallel-item::after {\n",
              "  content: \"\";\n",
              "  width: 100%;\n",
              "  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
              "  flex-grow: 1;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-parallel {\n",
              "  display: flex;\n",
              "  align-items: stretch;\n",
              "  justify-content: center;\n",
              "  background-color: var(--sklearn-color-background);\n",
              "  position: relative;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-parallel-item {\n",
              "  display: flex;\n",
              "  flex-direction: column;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
              "  align-self: flex-end;\n",
              "  width: 50%;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
              "  align-self: flex-start;\n",
              "  width: 50%;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
              "  width: 0;\n",
              "}\n",
              "\n",
              "/* Serial-specific style estimator block */\n",
              "\n",
              "#sk-container-id-1 div.sk-serial {\n",
              "  display: flex;\n",
              "  flex-direction: column;\n",
              "  align-items: center;\n",
              "  background-color: var(--sklearn-color-background);\n",
              "  padding-right: 1em;\n",
              "  padding-left: 1em;\n",
              "}\n",
              "\n",
              "\n",
              "/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
              "clickable and can be expanded/collapsed.\n",
              "- Pipeline and ColumnTransformer use this feature and define the default style\n",
              "- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
              "*/\n",
              "\n",
              "/* Pipeline and ColumnTransformer style (default) */\n",
              "\n",
              "#sk-container-id-1 div.sk-toggleable {\n",
              "  /* Default theme specific background. It is overwritten whether we have a\n",
              "  specific estimator or a Pipeline/ColumnTransformer */\n",
              "  background-color: var(--sklearn-color-background);\n",
              "}\n",
              "\n",
              "/* Toggleable label */\n",
              "#sk-container-id-1 label.sk-toggleable__label {\n",
              "  cursor: pointer;\n",
              "  display: flex;\n",
              "  width: 100%;\n",
              "  margin-bottom: 0;\n",
              "  padding: 0.5em;\n",
              "  box-sizing: border-box;\n",
              "  text-align: center;\n",
              "  align-items: start;\n",
              "  justify-content: space-between;\n",
              "  gap: 0.5em;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 label.sk-toggleable__label .caption {\n",
              "  font-size: 0.6rem;\n",
              "  font-weight: lighter;\n",
              "  color: var(--sklearn-color-text-muted);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
              "  /* Arrow on the left of the label */\n",
              "  content: \"▸\";\n",
              "  float: left;\n",
              "  margin-right: 0.25em;\n",
              "  color: var(--sklearn-color-icon);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
              "  color: var(--sklearn-color-text);\n",
              "}\n",
              "\n",
              "/* Toggleable content - dropdown */\n",
              "\n",
              "#sk-container-id-1 div.sk-toggleable__content {\n",
              "  max-height: 0;\n",
              "  max-width: 0;\n",
              "  overflow: hidden;\n",
              "  text-align: left;\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-0);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
              "  /* fitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-0);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-toggleable__content pre {\n",
              "  margin: 0.2em;\n",
              "  border-radius: 0.25em;\n",
              "  color: var(--sklearn-color-text);\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-0);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-0);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
              "  /* Expand drop-down */\n",
              "  max-height: 200px;\n",
              "  max-width: 100%;\n",
              "  overflow: auto;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
              "  content: \"▾\";\n",
              "}\n",
              "\n",
              "/* Pipeline/ColumnTransformer-specific style */\n",
              "\n",
              "#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
              "  color: var(--sklearn-color-text);\n",
              "  background-color: var(--sklearn-color-unfitted-level-2);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
              "  background-color: var(--sklearn-color-fitted-level-2);\n",
              "}\n",
              "\n",
              "/* Estimator-specific style */\n",
              "\n",
              "/* Colorize estimator box */\n",
              "#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-2);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
              "  /* fitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-2);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
              "#sk-container-id-1 div.sk-label label {\n",
              "  /* The background is the default theme color */\n",
              "  color: var(--sklearn-color-text-on-default-background);\n",
              "}\n",
              "\n",
              "/* On hover, darken the color of the background */\n",
              "#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
              "  color: var(--sklearn-color-text);\n",
              "  background-color: var(--sklearn-color-unfitted-level-2);\n",
              "}\n",
              "\n",
              "/* Label box, darken color on hover, fitted */\n",
              "#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
              "  color: var(--sklearn-color-text);\n",
              "  background-color: var(--sklearn-color-fitted-level-2);\n",
              "}\n",
              "\n",
              "/* Estimator label */\n",
              "\n",
              "#sk-container-id-1 div.sk-label label {\n",
              "  font-family: monospace;\n",
              "  font-weight: bold;\n",
              "  display: inline-block;\n",
              "  line-height: 1.2em;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-label-container {\n",
              "  text-align: center;\n",
              "}\n",
              "\n",
              "/* Estimator-specific */\n",
              "#sk-container-id-1 div.sk-estimator {\n",
              "  font-family: monospace;\n",
              "  border: 1px dotted var(--sklearn-color-border-box);\n",
              "  border-radius: 0.25em;\n",
              "  box-sizing: border-box;\n",
              "  margin-bottom: 0.5em;\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-0);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-estimator.fitted {\n",
              "  /* fitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-0);\n",
              "}\n",
              "\n",
              "/* on hover */\n",
              "#sk-container-id-1 div.sk-estimator:hover {\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-2);\n",
              "}\n",
              "\n",
              "#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
              "  /* fitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-2);\n",
              "}\n",
              "\n",
              "/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
              "\n",
              "/* Common style for \"i\" and \"?\" */\n",
              "\n",
              ".sk-estimator-doc-link,\n",
              "a:link.sk-estimator-doc-link,\n",
              "a:visited.sk-estimator-doc-link {\n",
              "  float: right;\n",
              "  font-size: smaller;\n",
              "  line-height: 1em;\n",
              "  font-family: monospace;\n",
              "  background-color: var(--sklearn-color-background);\n",
              "  border-radius: 1em;\n",
              "  height: 1em;\n",
              "  width: 1em;\n",
              "  text-decoration: none !important;\n",
              "  margin-left: 0.5em;\n",
              "  text-align: center;\n",
              "  /* unfitted */\n",
              "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
              "  color: var(--sklearn-color-unfitted-level-1);\n",
              "}\n",
              "\n",
              ".sk-estimator-doc-link.fitted,\n",
              "a:link.sk-estimator-doc-link.fitted,\n",
              "a:visited.sk-estimator-doc-link.fitted {\n",
              "  /* fitted */\n",
              "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
              "  color: var(--sklearn-color-fitted-level-1);\n",
              "}\n",
              "\n",
              "/* On hover */\n",
              "div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
              ".sk-estimator-doc-link:hover,\n",
              "div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
              ".sk-estimator-doc-link:hover {\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-3);\n",
              "  color: var(--sklearn-color-background);\n",
              "  text-decoration: none;\n",
              "}\n",
              "\n",
              "div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
              ".sk-estimator-doc-link.fitted:hover,\n",
              "div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
              ".sk-estimator-doc-link.fitted:hover {\n",
              "  /* fitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-3);\n",
              "  color: var(--sklearn-color-background);\n",
              "  text-decoration: none;\n",
              "}\n",
              "\n",
              "/* Span, style for the box shown on hovering the info icon */\n",
              ".sk-estimator-doc-link span {\n",
              "  display: none;\n",
              "  z-index: 9999;\n",
              "  position: relative;\n",
              "  font-weight: normal;\n",
              "  right: .2ex;\n",
              "  padding: .5ex;\n",
              "  margin: .5ex;\n",
              "  width: min-content;\n",
              "  min-width: 20ex;\n",
              "  max-width: 50ex;\n",
              "  color: var(--sklearn-color-text);\n",
              "  box-shadow: 2pt 2pt 4pt #999;\n",
              "  /* unfitted */\n",
              "  background: var(--sklearn-color-unfitted-level-0);\n",
              "  border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
              "}\n",
              "\n",
              ".sk-estimator-doc-link.fitted span {\n",
              "  /* fitted */\n",
              "  background: var(--sklearn-color-fitted-level-0);\n",
              "  border: var(--sklearn-color-fitted-level-3);\n",
              "}\n",
              "\n",
              ".sk-estimator-doc-link:hover span {\n",
              "  display: block;\n",
              "}\n",
              "\n",
              "/* \"?\"-specific style due to the `<a>` HTML tag */\n",
              "\n",
              "#sk-container-id-1 a.estimator_doc_link {\n",
              "  float: right;\n",
              "  font-size: 1rem;\n",
              "  line-height: 1em;\n",
              "  font-family: monospace;\n",
              "  background-color: var(--sklearn-color-background);\n",
              "  border-radius: 1rem;\n",
              "  height: 1rem;\n",
              "  width: 1rem;\n",
              "  text-decoration: none;\n",
              "  /* unfitted */\n",
              "  color: var(--sklearn-color-unfitted-level-1);\n",
              "  border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 a.estimator_doc_link.fitted {\n",
              "  /* fitted */\n",
              "  border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
              "  color: var(--sklearn-color-fitted-level-1);\n",
              "}\n",
              "\n",
              "/* On hover */\n",
              "#sk-container-id-1 a.estimator_doc_link:hover {\n",
              "  /* unfitted */\n",
              "  background-color: var(--sklearn-color-unfitted-level-3);\n",
              "  color: var(--sklearn-color-background);\n",
              "  text-decoration: none;\n",
              "}\n",
              "\n",
              "#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
              "  /* fitted */\n",
              "  background-color: var(--sklearn-color-fitted-level-3);\n",
              "}\n",
              "</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LinearRegression()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>LinearRegression</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.6/modules/generated/sklearn.linear_model.LinearRegression.html\">?<span>Documentation for LinearRegression</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\"><pre>LinearRegression()</pre></div> </div></div></div></div>"
            ],
            "text/plain": [
              "LinearRegression()"
            ]
          },
          "execution_count": 22,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "lrmodel = LinearRegression()\n",
        "lrmodel.fit(x_train, y_train)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Prediction\n",
        "predict = lrmodel.predict(x_test)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "RMSE error for the model is  8.063863046328835\n"
          ]
        }
      ],
      "source": [
        "#Check Error\n",
        "from sklearn.metrics import mean_squared_error\n",
        "lrmodelrmse = np.sqrt(mean_squared_error(predict, y_test))\n",
        "print(\"RMSE error for the model is \", lrmodelrmse)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Let's Apply Random Forest Regressor\n",
        "from sklearn.ensemble import RandomForestRegressor\n",
        "rfrmodel = RandomForestRegressor(n_estimators = 100, random_state = 101)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 26,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": [
        "#Fit the Forest\n",
        "rfrmodel.fit(x_train, y_train)\n",
        "rfrmodel_pred = rfrmodel.predict(x_test)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "RMSE value for Random Forest is: 9.757713738069647\n"
          ]
        }
      ],
      "source": [
        "#Errors for the forest\n",
        "rfrmodel_rmse = np.sqrt(mean_squared_error(rfrmodel_pred, y_test))\n",
        "print(\"RMSE value for Random Forest is:\",rfrmodel_rmse)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 28,
      "metadata": {
        "trusted": true
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "6.9 USD\n"
          ]
        }
      ],
      "source": [
        "X = df[['pickup_longitude', 'pickup_latitude', 'dropoff_longitude', 'dropoff_latitude']]\n",
        "y = df['fare_amount']\n",
        "rfrmodel.fit(X, y)\n",
        "\n",
        "new=[[-73.985,40.748,-73.985,40.758]]\n",
        "pr=rfrmodel.predict(new)\n",
        "print(round(pr[0],2),\"USD\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "trusted": true
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "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.11.1"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}
