{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bdd40fcc-7066-4d44-b4bc-8666f6c4ab67", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import random\n", "import matplotlib.pylab as plt\n", "import seaborn as sns \n", "from sklearn.model_selection import train_test_split\n", "import numpy as np\n", "from sklearn.metrics import mean_squared_error\n", "from sklearn.linear_model import LinearRegression\n", "from sklearn.preprocessing import StandardScaler" ] }, { "cell_type": "code", "execution_count": 2, "id": "775356bc-0e0d-4c73-8e9f-e3560d071397", "metadata": {}, "outputs": [], "source": [ "def predict_and_submit(model,test_inputs,name):\n", " test_pred = model.predict(test_inputs)\n", " sub_data = pd.read_csv('./sample_submission.csv')\n", " sub_data['fare_amount'] = test_pred\n", " sub_data.to_csv(name,index = None)\n", " return sub_data" ] }, { "cell_type": "markdown", "id": "f367644e-c6ad-48c3-b2f5-73d3cd699a8c", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# First Step : finding info about the data\n", "#### 1. first we will see the size of our training data based on it we will make our desision\n", "#### 2. if data set is too large then we cannot use it in our padas dataframe as it will take too much time\n", "#### 3. if the data set is small or less then 300 MB or have less than 1 million rows then we can use it in pandas dataframe\n", "#### 4. we will use some basic function of python like dir for directory and some read fuction" ] }, { "cell_type": "code", "execution_count": 3, "id": "7c54cc2e-cace-4aa2-8dfc-18c5fa3aeb08", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Volume in drive C is Windows\n", " Volume Serial Number is A4AC-9906\n", "\n", " Directory of C:\\Users\\tkdsu\\scikit2\\final_project\n", "\n", "25-10-2025 10:58 .\n", "15-10-2025 15:43 ..\n", "24-10-2025 16:28 .ipynb_checkpoints\n", "18-10-2025 15:31 0 experiment.csv\n", "25-10-2025 10:58 437,566 final project.ipynb\n", "15-10-2025 14:50 486 GCP-Coupons-Instructions.rtf\n", "25-10-2025 10:54 392,173 linear_regression_submission.csv\n", "24-10-2025 14:12 parkuet_file\n", "15-10-2025 14:50 343,271 sample_submission.csv\n", "24-10-2025 14:16 submissions\n", "15-10-2025 14:50 983,020 test.csv\n", "15-10-2025 14:55 5,697,178,298 train.csv\n", " 7 File(s) 5,699,334,814 bytes\n", " 5 Dir(s) 149,026,304,000 bytes free\n" ] } ], "source": [ "!dir" ] }, { "cell_type": "code", "execution_count": 4, "id": "e7da5c7c-e2bd-4d85-842a-f0294b24f12f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\Users\\tkdsu\\scikit2\\final_project\n" ] } ], "source": [ "!cd" ] }, { "cell_type": "code", "execution_count": 5, "id": "3ae30762-79cf-453e-a5de-1da23f9b6f88", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of lines: 55423857\n" ] } ], "source": [ "filename = \"train.csv\"\n", "\n", "with open(filename, \"r\", encoding=\"utf-8\") as f:\n", " line_count = sum(1 for _ in f)\n", "\n", "print(\"Number of lines:\", line_count)\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "c552f9ff-68cb-4fbb-a56b-df132cd756b0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of lines: 9915\n" ] } ], "source": [ "filename = \"test.csv\"\n", "\n", "with open(filename, \"r\", encoding=\"utf-8\") as f:\n", " line_count = sum(1 for _ in f)\n", "\n", "print(\"Number of lines:\", line_count)\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "042d64dc-c0f6-4a07-8e16-e7317becf443", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of lines: 9915\n" ] } ], "source": [ "filename = \"sample_submission.csv\"\n", "\n", "with open(filename, \"r\", encoding=\"utf-8\") as f:\n", " line_count = sum(1 for _ in f)\n", "\n", "print(\"Number of lines:\", line_count)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3d1bc388-4bd8-49f8-9892-ad7d1f13a652", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "id": "f9b27b11-84cb-4ca6-a42b-c0c0139ceac8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key,fare_amount,pickup_datetime,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,passenger_count\n", "2009-06-15 17:26:21.0000001,4.5,2009-06-15 17:26:21 UTC,-73.844311,40.721319,-73.84161,40.712278,1\n", "2010-01-05 16:52:16.0000002,16.9,2010-01-05 16:52:16 UTC,-74.016048,40.711303,-73.979268,40.782004,1\n", "2011-08-18 00:35:00.00000049,5.7,2011-08-18 00:35:00 UTC,-73.982738,40.76127,-73.991242,40.750562,2\n", "2012-04-21 04:30:42.0000001,7.7,2012-04-21 04:30:42 UTC,-73.98713,40.733143,-73.991567,40.758092,1\n", "2010-03-09 07:51:00.000000135,5.3,2010-03-09 07:51:00 UTC,-73.968095,40.768008,-73.956655,40.783762,1\n", "2011-01-06 09:50:45.0000002,12.1,2011-01-06 09:50:45 UTC,-74.000964,40.73163,-73.972892,40.758233,1\n", "2012-11-20 20:35:00.0000001,7.5,2012-11-20 20:35:00 UTC,-73.980002,40.751662,-73.973802,40.764842,1\n", "2012-01-04 17:22:00.00000081,16.5,2012-01-04 17:22:00 UTC,-73.9513,40.774138,-73.990095,40.751048,1\n", "2012-12-03 13:10:00.000000125,9,2012-12-03 13:10:00 UTC,-74.006462,40.726713,-73.993078,40.731628,1\n" ] } ], "source": [ "filename = \"train.csv\"\n", "\n", "with open(filename, \"r\", encoding=\"utf-8\") as f:\n", " for i in range(10):\n", " line = f.readline()\n", " if not line:\n", " break # stop if file has less than 10 lines\n", " print(line.strip())\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "234e6719-c012-4e0a-b4ce-dc4947e3fbb2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key,pickup_datetime,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,passenger_count\n", "2015-01-27 13:08:24.0000002,2015-01-27 13:08:24 UTC,-73.973320007324219,40.7638053894043,-73.981430053710938,40.74383544921875,1\n", "2015-01-27 13:08:24.0000003,2015-01-27 13:08:24 UTC,-73.986862182617188,40.719383239746094,-73.998886108398438,40.739200592041016,1\n", "2011-10-08 11:53:44.0000002,2011-10-08 11:53:44 UTC,-73.982524,40.75126,-73.979654,40.746139,1\n", "2012-12-01 21:12:12.0000002,2012-12-01 21:12:12 UTC,-73.98116,40.767807,-73.990448,40.751635,1\n", "2012-12-01 21:12:12.0000003,2012-12-01 21:12:12 UTC,-73.966046,40.789775,-73.988565,40.744427,1\n", "2012-12-01 21:12:12.0000005,2012-12-01 21:12:12 UTC,-73.960983,40.765547,-73.979177,40.740053,1\n", "2011-10-06 12:10:20.0000001,2011-10-06 12:10:20 UTC,-73.949013,40.773204,-73.959622,40.770893,1\n", "2011-10-06 12:10:20.0000003,2011-10-06 12:10:20 UTC,-73.777282,40.646636,-73.985083,40.759368,1\n", "2011-10-06 12:10:20.0000002,2011-10-06 12:10:20 UTC,-74.014099,40.709638,-73.995106,40.741365,1\n" ] } ], "source": [ "filename = \"test.csv\"\n", "\n", "with open(filename, \"r\", encoding=\"utf-8\") as f:\n", " for i in range(10):\n", " line = f.readline()\n", " if not line:\n", " break # stop if file has less than 10 lines\n", " print(line.strip())\n" ] }, { "cell_type": "markdown", "id": "9ca203bd-7354-41bf-a5a5-d101c58540ff", "metadata": {}, "source": [ "## observation\n", "#### 1. we can see the train set is 5.5 GB which will be hard to handle with pandas\n", "#### 2. we can observe the set is also huge with 55 million rows \n", "#### 3. the test set is pretty small with respect to the train set and only consist 9915 row \n", "#### 4. then we saw the first 10 row of our dataset which have 7 columns as follow --:\n", "- key(unique identification)\n", "- fare_amount(target column)\n", "- pickup_datetime\n", "- pickup_longitude\n", "- pickup_latitude\n", "- dropoff_longitude\n", "- dropoff_latitude\n", "- passenger_count\n", "#### 5. the test set have all the columns except fare_amount.Hence it is the target column" ] }, { "cell_type": "markdown", "id": "35e04fdf-3d32-483c-801d-65215d0812d0", "metadata": {}, "source": [ "# Second Step : loading our dataset on basis of observation\n", "### we cannot dirrectly dord this huge data dirctly by pandas as it will take a large amount of time\n", "### so it will be a small procedure shown below\n", "- most importantly we need to deal with large dataset so to deal with it we experiment and itrate the sample of 1% of all the dataset and apply then apply te process to complete dataset\n", "- column 'key' is a unique idenfitity of it will of no use so we will remove it\n", "- we can deal with the pickup_datetime column with the use of the datetime fuction offered by the pandas\n", "- we will aso specify the datatype of all the columns we are using\n", "- - 'float32' for all cordinate columns\n", " - 'int8' for pessenger count" ] }, { "cell_type": "code", "execution_count": 10, "id": "c8f7c32a-eaa8-4c7c-b509-7bae7a142167", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import random\n", "import matplotlib.pylab as plt\n", "import seaborn as sns \n" ] }, { "cell_type": "code", "execution_count": 11, "id": "e6b5f730-9f94-4375-adb3-7cc61c050fe6", "metadata": {}, "outputs": [], "source": [ "sample = 0.01" ] }, { "cell_type": "code", "execution_count": 13, "id": "756661f6-6fb1-42e1-961c-0471a2835f99", "metadata": {}, "outputs": [], "source": [ "cols = 'fare_amount,pickup_datetime,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,passenger_count'.split(',')" ] }, { "cell_type": "code", "execution_count": 14, "id": "f7913441-ba7e-46ca-b66e-5a78388c2b8a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['fare_amount',\n", " 'pickup_datetime',\n", " 'pickup_longitude',\n", " 'pickup_latitude',\n", " 'dropoff_longitude',\n", " 'dropoff_latitude',\n", " 'passenger_count']" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cols" ] }, { "cell_type": "code", "execution_count": 15, "id": "975b17f3-3b99-4e4c-93ba-c70c767ab180", "metadata": {}, "outputs": [], "source": [ "d_type = {\n", " 'fare_amount':'float32',\n", " 'pickup_longitude':'float32',\n", " 'pickup_latitude':'float32',\n", " 'dropoff_longitude':'float32',\n", " 'dropoff_latitude':'float32',\n", " 'passenger_count':'uint8'\n", "}\n", "def selected_row(row_indx):\n", " if row_indx == 0:\n", " return False\n", " return random.random() > sample \n", "random.seed(43)#this will initialize by 42" ] }, { "cell_type": "code", "execution_count": 16, "id": "c528c908-45e6-4b60-9c0f-489096ce918b", "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv('./train.csv',usecols=cols,dtype=d_type,skiprows=selected_row,parse_dates=['pickup_datetime'])" ] }, { "cell_type": "code", "execution_count": 17, "id": "4e404da4-ab21-418d-8129-a3f60bec39a7", "metadata": {}, "outputs": [], "source": [ "test_data = pd.read_csv('./test.csv',dtype=d_type,parse_dates=['pickup_datetime'])" ] }, { "cell_type": "code", "execution_count": 18, "id": "75f392c9-ca89-4a01-bda6-405bb131f9a7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
016.52014-12-08 16:00:01+00:00-73.98280340.745289-74.01425240.7029341
16.52012-10-06 15:47:00+00:00-73.98213240.774807-73.97357940.7896465
213.52013-03-02 15:47:27+00:00-73.98265140.753750-74.00792740.7419201
36.52014-10-08 06:49:18+00:000.0000000.0000000.0000000.0000001
438.52012-07-09 07:54:34+00:00-73.86257240.769066-74.00828640.7052761
........................
5537598.52009-09-21 00:09:00+00:00-73.99507140.760201-73.96798740.7555662
55376011.02012-09-19 13:29:00+00:00-73.98902140.752953-73.99367540.7310561
5537618.12009-02-04 14:04:32+00:00-73.99255440.689758-74.01063540.6721801
5537624.52011-02-05 12:14:00+00:00-73.94972240.784592-73.95623840.7783131
5537635.72010-11-18 07:08:58+00:00-73.99758940.735889-73.98455840.7540551
\n", "

553764 rows × 7 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "0 16.5 2014-12-08 16:00:01+00:00 -73.982803 \n", "1 6.5 2012-10-06 15:47:00+00:00 -73.982132 \n", "2 13.5 2013-03-02 15:47:27+00:00 -73.982651 \n", "3 6.5 2014-10-08 06:49:18+00:00 0.000000 \n", "4 38.5 2012-07-09 07:54:34+00:00 -73.862572 \n", "... ... ... ... \n", "553759 8.5 2009-09-21 00:09:00+00:00 -73.995071 \n", "553760 11.0 2012-09-19 13:29:00+00:00 -73.989021 \n", "553761 8.1 2009-02-04 14:04:32+00:00 -73.992554 \n", "553762 4.5 2011-02-05 12:14:00+00:00 -73.949722 \n", "553763 5.7 2010-11-18 07:08:58+00:00 -73.997589 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \n", "0 40.745289 -74.014252 40.702934 1 \n", "1 40.774807 -73.973579 40.789646 5 \n", "2 40.753750 -74.007927 40.741920 1 \n", "3 0.000000 0.000000 0.000000 1 \n", "4 40.769066 -74.008286 40.705276 1 \n", "... ... ... ... ... \n", "553759 40.760201 -73.967987 40.755566 2 \n", "553760 40.752953 -73.993675 40.731056 1 \n", "553761 40.689758 -74.010635 40.672180 1 \n", "553762 40.784592 -73.956238 40.778313 1 \n", "553763 40.735889 -73.984558 40.754055 1 \n", "\n", "[553764 rows x 7 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "code", "execution_count": 19, "id": "5bc085cf-c75a-4ccf-a810-58757f40b23a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keypickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
02015-01-27 13:08:24.00000022015-01-27 13:08:24+00:00-73.97332040.763805-73.98143040.7438351
12015-01-27 13:08:24.00000032015-01-27 13:08:24+00:00-73.98686240.719383-73.99888640.7392011
22011-10-08 11:53:44.00000022011-10-08 11:53:44+00:00-73.98252140.751259-73.97965240.7461401
32012-12-01 21:12:12.00000022012-12-01 21:12:12+00:00-73.98116340.767807-73.99044840.7516371
42012-12-01 21:12:12.00000032012-12-01 21:12:12+00:00-73.96604940.789776-73.98856440.7444271
........................
99092015-05-10 12:37:51.00000022015-05-10 12:37:51+00:00-73.96812440.796997-73.95564340.7803886
99102015-01-12 17:05:51.00000012015-01-12 17:05:51+00:00-73.94551140.803600-73.96021340.7763716
99112015-04-19 20:44:15.00000012015-04-19 20:44:15+00:00-73.99160040.726608-73.78974240.6470116
99122015-01-31 01:05:19.00000052015-01-31 01:05:19+00:00-73.98557340.735432-73.93917840.8017316
99132015-01-18 14:06:23.00000062015-01-18 14:06:23+00:00-73.98802240.754070-74.00028240.7592206
\n", "

9914 rows × 7 columns

\n", "
" ], "text/plain": [ " key pickup_datetime pickup_longitude \\\n", "0 2015-01-27 13:08:24.0000002 2015-01-27 13:08:24+00:00 -73.973320 \n", "1 2015-01-27 13:08:24.0000003 2015-01-27 13:08:24+00:00 -73.986862 \n", "2 2011-10-08 11:53:44.0000002 2011-10-08 11:53:44+00:00 -73.982521 \n", "3 2012-12-01 21:12:12.0000002 2012-12-01 21:12:12+00:00 -73.981163 \n", "4 2012-12-01 21:12:12.0000003 2012-12-01 21:12:12+00:00 -73.966049 \n", "... ... ... ... \n", "9909 2015-05-10 12:37:51.0000002 2015-05-10 12:37:51+00:00 -73.968124 \n", "9910 2015-01-12 17:05:51.0000001 2015-01-12 17:05:51+00:00 -73.945511 \n", "9911 2015-04-19 20:44:15.0000001 2015-04-19 20:44:15+00:00 -73.991600 \n", "9912 2015-01-31 01:05:19.0000005 2015-01-31 01:05:19+00:00 -73.985573 \n", "9913 2015-01-18 14:06:23.0000006 2015-01-18 14:06:23+00:00 -73.988022 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \n", "0 40.763805 -73.981430 40.743835 1 \n", "1 40.719383 -73.998886 40.739201 1 \n", "2 40.751259 -73.979652 40.746140 1 \n", "3 40.767807 -73.990448 40.751637 1 \n", "4 40.789776 -73.988564 40.744427 1 \n", "... ... ... ... ... \n", "9909 40.796997 -73.955643 40.780388 6 \n", "9910 40.803600 -73.960213 40.776371 6 \n", "9911 40.726608 -73.789742 40.647011 6 \n", "9912 40.735432 -73.939178 40.801731 6 \n", "9913 40.754070 -74.000282 40.759220 6 \n", "\n", "[9914 rows x 7 columns]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_data" ] }, { "cell_type": "markdown", "id": "5dafd3a7-4b00-44cc-9cab-d0c5f67c2ba3", "metadata": {}, "source": [ " ### now we are done with our process of loading our dataset\n", " ### next step will be exploring our dataset" ] }, { "cell_type": "markdown", "id": "cff78b3d-5c8a-4937-b4c4-bae5c02c2899", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# Step 3 : Exploring Our Dataset\n", "#### 1. We first known the basic info about our dataset\n", "#### 2. Then we will grint info about our test set\n", "#### 3. Finally we will move toward exploratory data analysis and visualisig our data" ] }, { "cell_type": "markdown", "id": "83c21fcf-c18c-4b34-aab6-a77766021b47", "metadata": {}, "source": [ "### Training Dataset" ] }, { "cell_type": "code", "execution_count": 20, "id": "9883192e-9b48-4ace-abc8-989845d9aeb8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 553764 entries, 0 to 553763\n", "Data columns (total 7 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 fare_amount 553764 non-null float32 \n", " 1 pickup_datetime 553764 non-null datetime64[ns, UTC]\n", " 2 pickup_longitude 553764 non-null float32 \n", " 3 pickup_latitude 553764 non-null float32 \n", " 4 dropoff_longitude 553761 non-null float32 \n", " 5 dropoff_latitude 553761 non-null float32 \n", " 6 passenger_count 553764 non-null uint8 \n", "dtypes: datetime64[ns, UTC](1), float32(5), uint8(1)\n", "memory usage: 15.3 MB\n" ] } ], "source": [ "data.info()" ] }, { "cell_type": "code", "execution_count": 21, "id": "d4986f60-0c14-426d-b681-379f6aa4351f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
count553764.000000553764.000000553764.000000553761.000000553761.000000553764.000000
mean11.322119-72.52758839.928112-72.55308539.9417301.688389
std9.76254311.3404758.94920412.3484198.1104081.340297
min-89.750000-1253.975342-2937.208252-3367.929443-1188.1740720.000000
25%6.000000-73.99211140.734932-73.99142540.7340661.000000
50%8.500000-73.98182740.752686-73.98017940.7531391.000000
75%12.500000-73.96713340.767174-73.96376040.7681392.000000
max430.0000002417.4414062209.220459471.2862552895.645996208.000000
\n", "
" ], "text/plain": [ " fare_amount pickup_longitude pickup_latitude dropoff_longitude \\\n", "count 553764.000000 553764.000000 553764.000000 553761.000000 \n", "mean 11.322119 -72.527588 39.928112 -72.553085 \n", "std 9.762543 11.340475 8.949204 12.348419 \n", "min -89.750000 -1253.975342 -2937.208252 -3367.929443 \n", "25% 6.000000 -73.992111 40.734932 -73.991425 \n", "50% 8.500000 -73.981827 40.752686 -73.980179 \n", "75% 12.500000 -73.967133 40.767174 -73.963760 \n", "max 430.000000 2417.441406 2209.220459 471.286255 \n", "\n", " dropoff_latitude passenger_count \n", "count 553761.000000 553764.000000 \n", "mean 39.941730 1.688389 \n", "std 8.110408 1.340297 \n", "min -1188.174072 0.000000 \n", "25% 40.734066 1.000000 \n", "50% 40.753139 1.000000 \n", "75% 40.768139 2.000000 \n", "max 2895.645996 208.000000 " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.describe()" ] }, { "cell_type": "code", "execution_count": 22, "id": "71667089-2668-423f-a88a-13b656987dab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(Timestamp('2009-01-01 00:11:11+0000', tz='UTC'),\n", " Timestamp('2015-06-30 23:53:15+0000', tz='UTC'))" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data['pickup_datetime'].min(),data['pickup_datetime'].max()" ] }, { "cell_type": "markdown", "id": "714e2378-4c0f-49f9-b804-9bb729fbe5ba", "metadata": {}, "source": [ "## Observation from Training set\n", "##### 1. There are 550k rows as expected\n", "##### 2. There are zero null value hence no imputer is required\n", "##### 3. We can see that the passenger range is from 0 to 208\n", "##### 4. the fare amount are from range -89 to 430\n", "##### 5. there are garentied errors in the cordinnates of the pickup and drop point as they cannot be that huge\n", "##### 6. We have already find the starting date and the ending date of this data with date time function of pandas\n", "##### 7. We also discovered that the training set is occuping the the 15.3MB of space in ram so we can experiment with it quiet easily\n", "### Now we need to do some simple preprocessing of explained above" ] }, { "cell_type": "code", "execution_count": 23, "id": "d1841875-f206-405c-84f4-228861e898db", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 9914 entries, 0 to 9913\n", "Data columns (total 7 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 key 9914 non-null object \n", " 1 pickup_datetime 9914 non-null datetime64[ns, UTC]\n", " 2 pickup_longitude 9914 non-null float32 \n", " 3 pickup_latitude 9914 non-null float32 \n", " 4 dropoff_longitude 9914 non-null float32 \n", " 5 dropoff_latitude 9914 non-null float32 \n", " 6 passenger_count 9914 non-null uint8 \n", "dtypes: datetime64[ns, UTC](1), float32(4), object(1), uint8(1)\n", "memory usage: 319.6+ KB\n" ] } ], "source": [ "test_data.info()" ] }, { "cell_type": "code", "execution_count": 24, "id": "929a9874-47e8-4cf3-a638-e2569d971d8e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
count9914.0000009914.0000009914.0000009914.0000009914.000000
mean-73.97471640.751041-73.97365640.7517401.671273
std0.0427990.0335420.0390930.0354361.278747
min-74.25219040.573143-74.26324540.5689741.000000
25%-73.99250040.736125-73.99124940.7352531.000000
50%-73.98232740.753052-73.98001540.7540651.000000
75%-73.96801240.767113-73.96406240.7687572.000000
max-72.98653441.709557-72.99096741.6966826.000000
\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude dropoff_latitude \\\n", "count 9914.000000 9914.000000 9914.000000 9914.000000 \n", "mean -73.974716 40.751041 -73.973656 40.751740 \n", "std 0.042799 0.033542 0.039093 0.035436 \n", "min -74.252190 40.573143 -74.263245 40.568974 \n", "25% -73.992500 40.736125 -73.991249 40.735253 \n", "50% -73.982327 40.753052 -73.980015 40.754065 \n", "75% -73.968012 40.767113 -73.964062 40.768757 \n", "max -72.986534 41.709557 -72.990967 41.696682 \n", "\n", " passenger_count \n", "count 9914.000000 \n", "mean 1.671273 \n", "std 1.278747 \n", "min 1.000000 \n", "25% 1.000000 \n", "50% 1.000000 \n", "75% 2.000000 \n", "max 6.000000 " ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_data.describe()" ] }, { "cell_type": "code", "execution_count": 25, "id": "2502f4ee-e94b-4dc0-88ce-6c6329334f0d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(Timestamp('2009-01-01 11:04:24+0000', tz='UTC'),\n", " Timestamp('2015-06-30 20:03:50+0000', tz='UTC'))" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_data['pickup_datetime'].min(),test_data['pickup_datetime'].max()" ] }, { "cell_type": "markdown", "id": "5e66f518-f6d4-45e9-b090-4bf3631a9a26", "metadata": {}, "source": [ "## Observation from Test set\n", "##### 1. There are 9914 rows \n", "##### 2. There are zero null value hence no imputer is required\n", "##### 3. We can see that the passenger range is from 1 to 6(so we can change the training set) accordingly\n", "##### 4. no such coordinate error\n", "##### 5. We have already find the starting date and the ending date of this data with date time function of pandas\n", "##### 6. We also discovered that the test set is occuping the the 330KB of space in ram so we can experiment with it quiet easily\n", "### Now we need to do some simple preprocessing of explained above" ] }, { "cell_type": "code", "execution_count": 26, "id": "cca053b2-dc59-4e83-b926-1af789b56f1c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkIAAAG0CAYAAADehEiZAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAQ1VJREFUeJzt3X9UVPeB9/EPAZkggRsShGEMq24TWQmaNpAimgTjD9AjGpvnqbYkE9m6JKk/CAeMWZruE9c2YhLEtrq1bdon1h8tebqGrK1KIaZiqKBIYANqjG00YASxCQ5qzUDwPn90uacjxogRidz365x7jnPvZ2a+30nLfM79NX6maZoCAACwoRv6ewAAAAD9hSIEAABsiyIEAABsiyIEAABsiyIEAABsiyIEAABsiyIEAABsiyIEAABsiyIEAABsiyIEAABs63MVofz8fPn5+Sk7O9taZ5qmli5dKpfLpaCgIE2YMEH79+/3eZ7X69WiRYsUHh6u4OBgzZw5U8eOHfPJtLW1ye12yzAMGYYht9utU6dO+WQaGxs1Y8YMBQcHKzw8XFlZWero6PDJ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M5WWlqaYmBhJUkpKimJjY+V2u1VbW6sdO3Zo8eLFyszMtPbipKeny+FwKCMjQw0NDSouLtby5cuVk5NzWVeMAQCAgS2gN+G1a9dKkiZMmOCz/uWXX1ZGRoYkacmSJTp37pzmz5+vtrY2JSYmqrS0VCEhIVZ+1apVCggI0OzZs3Xu3DlNmjRJ69atk7+/v5XZtGmTsrKyrKvLZs6cqTVr1ljb/f39tXXrVs2fP1/jx49XUFCQ0tPTVVBQYGUMw1BZWZkWLFighIQEhYWFKScnRzk5Ob2ZNgAAGKA+132E7ID7CPXEfYQAAF901+Q+QgAAANczihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALAtihAAALCtXhehXbt2acaMGXK5XPLz89Nrr73msz0jI0N+fn4+y9ixY30yXq9XixYtUnh4uIKDgzVz5kwdO3bMJ9PW1ia32y3DMGQYhtxut06dOuWTaWxs1IwZMxQcHKzw8HBlZWWpo6PDJ1NfX6/k5GQFBQVp6NChWrZsmUzT7O20AQDAANTrInT27FndddddWrNmzadmpk6dqubmZmvZtm2bz/bs7GwVFxerqKhIFRUVOnPmjNLS0tTV1WVl0tPTVVdXp5KSEpWUlKiurk5ut9va3tXVpenTp+vs2bOqqKhQUVGRNm/erNzcXCvT3t6uKVOmyOVyqbq6WqtXr1ZBQYEKCwt7O20AADAABfT2CdOmTdO0adMumXE4HHI6nRfd5vF49Itf/EIbNmzQ5MmTJUkbN25UdHS0Xn/9daWmpurgwYMqKSlRVVWVEhMTJUkvvfSSkpKSdOjQIcXExKi0tFQHDhxQU1OTXC6XJGnlypXKyMjQc889p9DQUG3atEkff/yx1q1bJ4fDobi4OL377rsqLCxUTk6O/Pz8ejt9A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tvXrVunm2++Wb/73e8UGxsrh8Oh999//zM/u//7f/+v7rzzTjkcDkVFRWnhwoXWtsbGRj344IO66aabFBoaqtmzZ+vEiRPW9oyMDM2aNcvn9bKzszVhwgSf/zZZWVlasmSJbrnlFjmdTi1dutTaPnz4cEnS1772Nfn5+VmPAfREEQLwqX75y18qICBAe/bs0Y9+9COtWrVKP//5zyX9rUR873vf03//93/rtdde05EjR5SRkWE999/+7d904MABbd++XQcPHtTatWsVHh4uSfrRj36kLVu26P/9v/+nQ4cOaePGjdaXtWmamj59ulpaWrRt2zbV1NTo7rvv1qRJk/TRRx9Zr//nP/9Zr732mn73u9/pd7/7ncrLy7VixQpre05Ojv74xz9qy5YtKisr05tvvqm33nrLZ37//M//rD/+8Y8qKirS22+/ra9//euaOnWqDh8+bGX++te/Kj8/Xz//+c+1f/9+RUREXPIzW7t2rRYsWKDHHntM9fX12rJli26//XZrbrNmzdJHH32k8vJylZWV6c9//rPmzJlzRf9tgoODtWfPHr3wwgtatmyZysrKJEnV1dWSpJdfflnNzc3WYwAXcc1/7x7AdSE5OdkcNWqUef78eWvd008/bY4aNeqi+b1795qSzNOnT5umaZozZsww//mf//mi2UWLFpkTJ070ee1uO3bsMENDQ82PP/7YZ/2XvvQl86c//alpmqb57LPPmoMHDzbb29ut7U899ZSZmJhomqZptre3m4MGDTJ/85vfWNtPnTplDh482HzyySdN0zTNP/3pT6afn5/5wQcf+LzPpEmTzLy8PNM0TfPll182JZl1dXUXncfFuFwu85lnnrnottLSUtPf399sbGy01u3fv9+UZO7du9c0TdOcO3eu+eCDD/o878knnzSTk5Otx8nJyea9997rk7nnnnvMp59+2nosySwuLr7scQN2xR4hAJ9q7Nix8vPzsx4nJSXp8OHD6urqUm1trR588EENGzZMISEh1qGbxsZGSdK3v/1tFRUV6ctf/rKWLFmi3bt3W6+TkZGhuro6xcTEKCsrS6Wlpda2mpoanTlzRrfeeqtuuukmazly5Ij+/Oc/W7nhw4crJCTEehwVFWUdmnvvvffU2dmpr371q9Z2wzAUExNjPX7rrbdkmqZGjhzp8z7l5eU+7xMYGKgxY8Zc1ufV2tqq48ePa9KkSRfdfvDgQUVHRys6OtpaFxsbq5tvvlkHDx68rPfoduGY/n7+AC5fQH8PAMD15+OPP1ZKSopSUlK0ceNGDRkyRI2NjUpNTVVHR4ckadq0aXr//fe1detWvf7665o0aZIWLFiggoIC3X333Tpy5Ii2b9+u119/XbNnz9bkyZP1n//5nzp//ryioqJ8ztXpdvPNN1v/HjRokM82Pz8/60Rm83/OY/r7Evf36yXp/Pnz8vf3V01Njfz9/X1yN910k/XvoKCgHq/zaYKCgi653TTNi77W36+/4YYbfMYpSZ2dnT2ec6n5A7h8FCEAn6qqqqrH4zvuuEPvvPOO/vKXv2jFihXW3o19+/b1eP6QIUOUkZGhjIwM3XfffXrqqadUUFAgSQoNDdWcOXM0Z84c/e///b81depUffTRR7r77rvV0tKigICAKz7J90tf+pIGDRqkvXv3WuNrb2/X4cOHlZycLEn6yle+oq6uLrW2tuq+++67ove5UEhIiIYPH64dO3bogQce6LE9NjZWjY2NampqssZ14MABeTwejRo1StLfPrOGhgaf59XV1fUoPp9l0KBB6urqusKZAPbBoTEAn6qpqUk5OTk6dOiQfv3rX2v16tV68skn9Q//8A8KDAzU6tWr9d5772nLli363ve+5/Pc//N//o/+67/+S3/605+0f/9+/e53v7O+7FetWqWioiK98847evfdd/Wb3/xGTqdTN998syZPnqykpCTNmjVLv//973X06FHt3r1b3/3udy9ati4mJCREc+fO1VNPPaU//OEP2r9/v771rW/phhtusPa8jBw5Ug8//LAeffRRvfrqqzpy5Iiqq6v1/PPPa9u2bVf8mS1dulQrV67Uj370Ix0+fFhvvfWWVq9eLUmaPHmyxowZo4cfflhvvfWW9u7dq0cffVTJyclKSEiQJE2cOFH79u3T+vXrdfjwYT377LM9itHl6C5kLS0tamtru+L5AAMdRQjAp3r00Ud17tw5ffWrX9WCBQu0aNEiPfbYYxoyZIjWrVun3/zmN4qNjdWKFSusPT3dAgMDlZeXpzFjxuj++++Xv7+/ioqKJP3t0NPzzz+vhIQE3XPPPTp69Ki2bdtmFZVt27bp/vvv17e+9S2NHDlS3/jGN3T06FFFRkZe9tgLCwuVlJSktLQ0TZ48WePHj9eoUaN04403WpmXX35Zjz76qHJzcxUTE6OZM2dqz549Pufw9NbcuXP1gx/8QD/+8Y915513Ki0tzboKrfsmh2FhYbr//vs1efJk/eM//qNeeeUV6/mpqan6t3/7Ny1ZskT33HOPTp8+rUcffbTX41i5cqXKysoUHR2tr3zlK1c8H2Cg8zMvPBgNAPrbvWq+/OUv6wc/+EF/D+WqOHv2rIYOHaqVK1dq3rx5/T0cAF8QnCMEYECqra3VO++8o69+9avyeDxatmyZJOnBBx/s55EB+CKhCAEYsAoKCnTo0CEFBgYqPj5eb775pnVTxyv191eUXWj79u1X7cRrANcGh8YAoBf+9Kc/feq2oUOHfuYl9AC+WChCAADAtrhqDAAA2BZFCAAA2BZFCAAA2BZFCAAA2BZFCAAA2BZFCAAA2BZFCAAA2Nb/B2wvQYqNF6VUAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "passenger_counts = data['passenger_count'].value_counts().sort_index()\n", "\n", "sns.barplot(x= passenger_counts.index,y=passenger_counts.values)" ] }, { "cell_type": "markdown", "id": "59c1e538-cc45-4a2a-84ba-ecae3b9c0dba", "metadata": {}, "source": [ "## we can see by our bar plot that mostly all the passenger are 1" ] }, { "cell_type": "code", "execution_count": 27, "id": "9cfc1e7a-1b16-4728-8f01-ced1744fba57", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "passenger_count\n", "1 382675\n", "2 81702\n", "5 39452\n", "3 24570\n", "6 11862\n", "4 11635\n", "0 1867\n", "208 1\n", "Name: count, dtype: int64" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data['passenger_count'].value_counts()" ] }, { "cell_type": "code", "execution_count": 28, "id": "b6cd0198-8e50-4a76-9821-b8abd6765a0a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjMAAAGwCAYAAABcnuQpAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAALAlJREFUeJzt3XtYVXWi//HPFmGriJAXBIoEL5nXNDGPqYlpTo6Z5qm0LLVmaiovGI0apUk2iXXKLC0b82Q5VjhNaZzSSTJvU5kIkoTmFYWjEk+jAWGCwvf3R8f9i0DF7d6svfD9ep71PKzvWnvvzwLd+/Os23YYY4wAAABsqp7VAQAAAC4GZQYAANgaZQYAANgaZQYAANgaZQYAANgaZQYAANgaZQYAANhafasDeFtFRYWOHDmioKAgORwOq+MAAIAaMMaouLhYERERqlfv3Pte6nyZOXLkiCIjI62OAQAA3JCXl6crrrjinOvU+TITFBQk6ZdfRpMmTSxOAwAAaqKoqEiRkZGuz/FzqfNl5syhpSZNmlBmAACwmZqcIsIJwAAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNYoMwAAwNbq/LdmAwBwMYwxKikpcc0HBgbW6JucUXsoMwAAnENJSYmGDx/umv/oo4/UuHFjCxPhtzjMBAAAbI0yAwAAbI0yAwAAbI0yAwAAbI0TgAHgAnF1C+BbKDMAcIG4usX39Ji6zGvP7ThdpuBfzcfOTJapH+CV10r/r7Feed66ztLDTJs2bdKwYcMUEREhh8OhVatWuZadOnVK06dPV5cuXRQYGKiIiAiNHTtWR44csS4wAADwOZaWmZKSEl1zzTVauHBhlWUnTpxQRkaGZs6cqYyMDH344Yfas2ePbr31VguSAgAAX2XpYaYhQ4ZoyJAh1S4LDg5WampqpbEFCxbouuuuU25urq688spqH1daWqrS0l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ccDoc6duyo7t27eyoXAABAjbhVZgoKCjR69Ght2LBBISEhMsaosLBQAwYMUHJyslq0aOHpnAAAANVy62qmSZMmqaioSNnZ2Tp27JiOHz+ub7/9VkVFRZo8ebKnMwIAAJyVW3tm/vnPf+qzzz5Thw4dXGMdO3bUq6++ygnAAACgVrm1Z6aiokL+/v5Vxv39/VVRUXHRoQAAAGrKrTJz4403Ki4uTkeOHHGNHT58WI8++qgGDhzosXAAAADn41aZWbhwoYqLixUVFaU2bdqobdu2io6OVnFxsRYsWODpjAAAAGfl1jkzkZGRysjIUGpqqr777jsZY9SxY0cNGjTI0/kAAADO6aLuM3PTTTfppptu8lQWAACAC+Z2mdm6das2bNiggoKCKif9zps376KDAQAA1IRbZWbOnDmaMWOG2rdvr5YtW8rhcLiW/fpnAAAAb3OrzLz88st68803NX78eA/HAQAAuDBuXc1Ur1499enTx9NZAAAALphbZebRRx/Vq6++6uksAAAAF8ytw0x//vOfNXToULVp00YdO3ascjfgDz/80CPhAAAAzsetMjNp0iStX79eAwYMULNmzTjpFwAAWMatMrNs2TJ98MEHGjp0qKfzAAAAXBC3zplp2rSp2rRp4+ksAAAAF8ytMpOYmKhZs2bpxIkTns4DAABwQdw6zPTKK69o//79atmypaKioqqcAJyRkeGRcAAAAOfjVpkZMWKEh2MAAAC4x60yM2vWLE/nAAAAcItb58wAAAD4Crf2zJSXl+ull17S3//+d+Xm5qqsrKzS8mPHjnkkHAAAwPm4tWfm6aef1rx583TnnXeqsLBQ8fHxGjlypOrVq6fExEQPRwQAADg7t8rMO++8ozfeeEN//vOfVb9+fd11111asmSJnnrqKW3ZssXTGQEAAM7KrTKTn5+vLl26SJIaN26swsJCSdItt9yiTz75xHPpAAAAzsOtMnPFFVfo6NGjkqS2bdtq7dq1kqS0tDQ5nU7PpQMAADgPt8rMbbfdpnXr1kmS4uLiNHPmTLVr105jx47V/fff79GAknT48GHdc889atasmRo1aqRu3bopPT3d468DAADsx62rmebOnev6+fbbb1dkZKS++OILtW3bVr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9Z5/sMmzFjho4fP67PPvtMzZs316pVq3THHXdo8+bN6tKli9ez/xplxguaN28uPz+/KnthCgoKqjRd1B2TJk1SSkqKNm3apCuuuMLqOLUiICBAbdu2lSTFxMQoLS1NL7/8sv76179anMw70tPTVVBQoB49erjGysvLtWnTJi1cuFClpaXy8/OzMGHtCQwMVJcuXbR3716ro3hVeHh4lXLeoUMHffDBBxYl8pyzvWeduUotPz9f4eHhrvFff4bt379fCxcu1LfffqtOnTpJkq655hpt3rxZr776ql5//fVa3BKuZvKKgIAA9ejRQ6mpqZXGU1NTdf3111uUCt5ijNHEiRP14Ycf6vPPP1d0dLTVkSxjjFFpaanVMbxm4MCBysrKUmZmpmuKiYnRmDFjlJmZeckUGUkqLS3Vrl27Kn3Y1UV9+vSpctnynj17bPFlx2dzvves6OhohYWFVfoMKysr08aNG12fYSdOnJAk1atXuUb4+fmpoqLCy1tQjVo/5fgSkZycbPz9/c1///d/m507d5opU6aYwMBAc/DgQaujeU1xcbHZvn272b59u5Fk5s2bZ7Zv324OHTpkdTSvevjhh01wcLDZsGGDOXr0qGs6ceKE1dG8KiEhwWzatMnk5OSYHTt2mCeeeMLUq1fPrF271upotepSuZrpscceMxs2bDAHDhwwW7ZsMbfccosJCgqq0+9pxhizdetWU79+ffPss8+avXv3mnfeecc0atTILF++3OpobqvJe9bcuXNNcHCw+fDDD01WVpa56667THh4uCkqKjLGGFNWVmbatm1r+vXrZ77++muzb98+88ILLxiHw2E++eSTWt8myowXvfrqq6ZVq1YmICDAXHvttXX+Ut3169cbSVWmcePGWR3Nq6rbZklm6dKlVkfzqvvvv9/177tFixZm4MCBl1yRMebSKTOjRo0y4eHhxt/f30RERJiRI0ea7Oxsq2PViv/5n/8xnTt3Nk6n01x99dVm8eLFVke6KDV5z6qoqDCzZs0yYWFhxul0mhtuuMFkZWVVep49e/aYkSNHmtDQUNOoUSPTtWvXKpdq1xaHMcbU9t4gAAAAT+GcGQAAYGuUGQAAYGuUGQAAYGuUGQAAYGuUG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/sl156ScnJyfruu++0Z88evf/++woLC1NISIgGDRqk3r17a8SIEfr000918OBBffnll5oxY0a1hak6QUFBGjdunKZOnar169crOztb999/v+rVq+faA3LVVVdpzJgxGjt2rD788EPl5OQoLS1Nzz33nFavXu327ywxMVEvvviiXnnlFe3du1cZGRlasGCBJGnQoEHq2rWrxowZo4yMDG3dulVjx45V//79FRMTI0m68cYbtW3bNi1btkx79+7VrFmzqpSbmjhTqvLz83X8+HG3twe4FFBmgDps7Nix+vnnn3XddddpwoQJmjRpkh588EG1aNFCb731lt5//3117NhRc+fOde1xOSMgIEAJCQnq2rWrbrjhBvn5+Sk5OVnSL4dxnnvuOcXExKhnz546ePCgVq9e7Sobq1ev1g033KD7779fV111lUaPHq2DBw+qZcuWNc4+b9489e7dW7fccosGDRqkPn36qEOHDmrQoIFrnaVLl2rs2LF67LHH1L59e9166636+uuvK53TcqHGjRun+fPn67XXXlOnTp10yy23uK6OOnMju8suu0w33HCDBg0apNatW2vFihWux//ud7/TzJkzNW3aNPXs2VPFxcUaO3bsBed48cUXlZqaqsjISHXv3t3t7QEuBQ7z24O7AOqE2NhYdevWTfPnz7c6ikeUlJTo8ssv14svvqg//OEPVscB4EM4ZwaAT9q+fbu+++47XXfddSosLNTs2bMlScOHD7c4GQBfQ5kB4LNeeOEF7d69WwEBAerRo4c2b97sunGfu359pdNvrVmzxmMnEwOoPRxmAnBJ2bdv31mXXX755ee9PBuA76HMAAAAW+NqJgAAYGuUGQAAYGuUGQAAYGuUGQAAYGuUGQAAYGuUGQAAYGuUGQAAYGv/D1VS8oNVo3wYAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sns.barplot(x= data.passenger_count,y=data.fare_amount)" ] }, { "cell_type": "markdown", "id": "8638b12c-cfdd-4aeb-92bb-135eda5a5464", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "#### from above bar plot mostly the variation is in 0 passenger but we can remove it as there is no 0 passenger in training set" ] }, { "cell_type": "markdown", "id": "68ed6778-5a48-4746-99bd-8726900da5ce", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# Step 4 : Preperation of Data for Training a Model\n", "### 1.We will do the train and validation set split \n", "### 2.Filling of the missing value or irrelevent values\n", "### 3.Extraction of the inputs and the target for training and validation set" ] }, { "cell_type": "markdown", "id": "69c66e02-c2a6-44f9-a4fd-2d39b7a89f03", "metadata": {}, "source": [ "##### spliting of the data" ] }, { "cell_type": "code", "execution_count": 29, "id": "b2a7da60-7cfb-4b38-8630-24306d357d29", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "code", "execution_count": 30, "id": "1739e138-dbe1-4424-982a-d2767e24b7db", "metadata": {}, "outputs": [], "source": [ "train_data ,val_data = train_test_split(data,test_size=0.2,random_state=42)" ] }, { "cell_type": "code", "execution_count": 31, "id": "9a4365fa-736e-43db-8af0-652ae0173e06", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(443011, 110753)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(train_data),len(val_data)" ] }, { "cell_type": "code", "execution_count": 32, "id": "030daa73-4b30-42b8-9b0c-17a360101af3", "metadata": {}, "outputs": [], "source": [ "train_data= train_data.dropna()\n", "test_data= test_data.dropna()" ] }, { "cell_type": "markdown", "id": "7035d06b-bdad-4a32-b530-19236d27356a", "metadata": {}, "source": [ "##### extraction of inputs and targets" ] }, { "cell_type": "code", "execution_count": 33, "id": "50fd3f24-05ab-444a-9707-22526ed8270a", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "Index(['fare_amount', 'pickup_datetime', 'pickup_longitude', 'pickup_latitude',\n", " 'dropoff_longitude', 'dropoff_latitude', 'passenger_count'],\n", " dtype='object')" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data.columns" ] }, { "cell_type": "code", "execution_count": 34, "id": "56fbdc6e-edff-4f10-a0e5-3a9092266993", "metadata": {}, "outputs": [], "source": [ "inputs_cols = ['pickup_longitude', 'pickup_latitude','dropoff_longitude', 'dropoff_latitude', 'passenger_count']\n", "target_cols = 'fare_amount'" ] }, { "cell_type": "code", "execution_count": 35, "id": "f1cd753a-fc3b-41c9-90cd-b6febca3ad3a", "metadata": {}, "outputs": [], "source": [ "train_inputs = train_data[inputs_cols]\n", "train_target = train_data[target_cols]\n", "val_inputs = val_data[inputs_cols]\n", "val_target = val_data[target_cols]\n", "test_inputs = test_data[inputs_cols]" ] }, { "cell_type": "code", "execution_count": 36, "id": "7cbd8566-5952-4bc3-8bcb-2ba579d11a33", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
0-73.97332040.763805-73.98143040.7438351
1-73.98686240.719383-73.99888640.7392011
2-73.98252140.751259-73.97965240.7461401
3-73.98116340.767807-73.99044840.7516371
4-73.96604940.789776-73.98856440.7444271
..................
9909-73.96812440.796997-73.95564340.7803886
9910-73.94551140.803600-73.96021340.7763716
9911-73.99160040.726608-73.78974240.6470116
9912-73.98557340.735432-73.93917840.8017316
9913-73.98802240.754070-74.00028240.7592206
\n", "

9914 rows × 5 columns

\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude dropoff_latitude \\\n", "0 -73.973320 40.763805 -73.981430 40.743835 \n", "1 -73.986862 40.719383 -73.998886 40.739201 \n", "2 -73.982521 40.751259 -73.979652 40.746140 \n", "3 -73.981163 40.767807 -73.990448 40.751637 \n", "4 -73.966049 40.789776 -73.988564 40.744427 \n", "... ... ... ... ... \n", "9909 -73.968124 40.796997 -73.955643 40.780388 \n", "9910 -73.945511 40.803600 -73.960213 40.776371 \n", "9911 -73.991600 40.726608 -73.789742 40.647011 \n", "9912 -73.985573 40.735432 -73.939178 40.801731 \n", "9913 -73.988022 40.754070 -74.000282 40.759220 \n", "\n", " passenger_count \n", "0 1 \n", "1 1 \n", "2 1 \n", "3 1 \n", "4 1 \n", "... ... \n", "9909 6 \n", "9910 6 \n", "9911 6 \n", "9912 6 \n", "9913 6 \n", "\n", "[9914 rows x 5 columns]" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_inputs" ] }, { "cell_type": "code", "execution_count": 37, "id": "a0ec0563-0501-4243-90b6-606fa6016d45", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
413567-73.99230240.750355-73.95075240.7783811
6916-73.96386040.767841-73.95462040.7657091
425472-74.01065840.702446-73.98209440.7743196
398223-73.94042240.711983-73.90527340.7128525
498398-73.87070540.773640-73.98465040.6845401
..................
110268-73.98255240.757084-73.98604640.7757301
259178-73.98307040.754841-73.98307040.7548411
365838-73.98832740.754261-73.98097240.7288971
131932-73.97643340.756386-73.97860040.7773821
121958-73.98092740.763386-73.98232340.7510453
\n", "

443008 rows × 5 columns

\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude \\\n", "413567 -73.992302 40.750355 -73.950752 \n", "6916 -73.963860 40.767841 -73.954620 \n", "425472 -74.010658 40.702446 -73.982094 \n", "398223 -73.940422 40.711983 -73.905273 \n", "498398 -73.870705 40.773640 -73.984650 \n", "... ... ... ... \n", "110268 -73.982552 40.757084 -73.986046 \n", "259178 -73.983070 40.754841 -73.983070 \n", "365838 -73.988327 40.754261 -73.980972 \n", "131932 -73.976433 40.756386 -73.978600 \n", "121958 -73.980927 40.763386 -73.982323 \n", "\n", " dropoff_latitude passenger_count \n", "413567 40.778381 1 \n", "6916 40.765709 1 \n", "425472 40.774319 6 \n", "398223 40.712852 5 \n", "498398 40.684540 1 \n", "... ... ... \n", "110268 40.775730 1 \n", "259178 40.754841 1 \n", "365838 40.728897 1 \n", "131932 40.777382 1 \n", "121958 40.751045 3 \n", "\n", "[443008 rows x 5 columns]" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_inputs" ] }, { "cell_type": "code", "execution_count": 38, "id": "61aaceda-3d31-4597-9f05-83f7b809d594", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "413567 17.500000\n", "6916 5.300000\n", "425472 25.500000\n", "398223 6.900000\n", "498398 25.700001\n", " ... \n", "110268 8.500000\n", "259178 6.100000\n", "365838 15.000000\n", "131932 10.000000\n", "121958 7.500000\n", "Name: fare_amount, Length: 443008, dtype: float32" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_target" ] }, { "cell_type": "code", "execution_count": 39, "id": "59182874-c9d0-4a24-9320-c193b7def660", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
105568-73.99965740.730942-73.98842640.7199211
316033-73.98162840.773514-73.99141740.7601551
47404-73.93552440.744961-73.90776840.7418941
220563-73.98834240.753689-74.00198440.7386701
244830-73.96627040.761730-73.96074740.7758905
..................
357796-73.97678440.762791-73.99085240.7507061
232475-73.97948540.763718-73.87285640.7744522
121899-73.98956340.729935-73.99939040.7335212
480104-74.01277940.701851-73.99596440.7163354
73692-73.98276540.727356-73.98342140.7531852
\n", "

110753 rows × 5 columns

\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude \\\n", "105568 -73.999657 40.730942 -73.988426 \n", "316033 -73.981628 40.773514 -73.991417 \n", "47404 -73.935524 40.744961 -73.907768 \n", "220563 -73.988342 40.753689 -74.001984 \n", "244830 -73.966270 40.761730 -73.960747 \n", "... ... ... ... \n", "357796 -73.976784 40.762791 -73.990852 \n", "232475 -73.979485 40.763718 -73.872856 \n", "121899 -73.989563 40.729935 -73.999390 \n", "480104 -74.012779 40.701851 -73.995964 \n", "73692 -73.982765 40.727356 -73.983421 \n", "\n", " dropoff_latitude passenger_count \n", "105568 40.719921 1 \n", "316033 40.760155 1 \n", "47404 40.741894 1 \n", "220563 40.738670 1 \n", "244830 40.775890 5 \n", "... ... ... \n", "357796 40.750706 1 \n", "232475 40.774452 2 \n", "121899 40.733521 2 \n", "480104 40.716335 4 \n", "73692 40.753185 2 \n", "\n", "[110753 rows x 5 columns]" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val_inputs" ] }, { "cell_type": "code", "execution_count": 40, "id": "b78915e8-90fa-49e7-8941-c32a0bf3baa4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "105568 11.70\n", "316033 4.50\n", "47404 6.50\n", "220563 7.00\n", "244830 6.10\n", " ... \n", "357796 6.50\n", "232475 31.07\n", "121899 4.90\n", "480104 10.00\n", "73692 8.90\n", "Name: fare_amount, Length: 110753, dtype: float32" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val_target" ] }, { "cell_type": "markdown", "id": "4b71809f-66ac-4c9e-bd5c-f6432ee3c087", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# Step 5 : Hardcoded and baseline model\n", "##### Hardcoded Model : this model basically predict only the men value\n", "##### Baseline Model : this model is most basic model based on linear regression(easy to train and low complexity)" ] }, { "cell_type": "code", "execution_count": 41, "id": "b9d7c992-fa86-4799-a493-516edd7a6010", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from sklearn.metrics import mean_squared_error\n", "from sklearn.linear_model import LinearRegression" ] }, { "cell_type": "code", "execution_count": 42, "id": "8d214395-a777-4098-82df-d83b5c832e06", "metadata": {}, "outputs": [], "source": [ "class hardcoded:\n", " def fit(self,inputs,targets):\n", " self.mean = targets.mean()\n", " def predict(self,inputs):\n", " return np.full(inputs.shape[0],self.mean)\n", " " ] }, { "cell_type": "code", "execution_count": 43, "id": "d95b2c11-b90a-430b-a8e4-382e31e89cff", "metadata": {}, "outputs": [], "source": [ "model = hardcoded()" ] }, { "cell_type": "code", "execution_count": 44, "id": "7584b406-049f-480d-bc0e-65e869b93bd2", "metadata": {}, "outputs": [], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 45, "id": "88bf5b0a-cf40-446a-85fe-1345c0e73518", "metadata": {}, "outputs": [], "source": [ "val_hardcoded_prediction =model.predict(val_inputs)" ] }, { "cell_type": "code", "execution_count": 46, "id": "c88ad62e-052c-4e65-956f-0d5b86eb21a6", "metadata": {}, "outputs": [], "source": [ "train_hardcoded_prediction =model.predict(train_inputs)" ] }, { "cell_type": "code", "execution_count": 47, "id": "5d92c369-f8df-4e56-9db0-4320f7a64da9", "metadata": {}, "outputs": [], "source": [ "def rmse(inputs,targets):\n", " return np.sqrt(mean_squared_error(inputs,targets))" ] }, { "cell_type": "markdown", "id": "f697e553-3fc0-402b-bf2c-49523a9f8537", "metadata": {}, "source": [ "#### let check the accuracy of our model" ] }, { "cell_type": "code", "execution_count": 48, "id": "e39ffdb4-f576-4bff-b5b8-473aa930bb25", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.float64(9.788363371632522)" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rmse(train_hardcoded_prediction,train_target)" ] }, { "cell_type": "code", "execution_count": 49, "id": "15c8f91a-aa46-4c20-b546-9353fd81efab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.float64(9.651922842780515)" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rmse(val_hardcoded_prediction,val_target)" ] }, { "cell_type": "markdown", "id": "feb9b8af-1919-46af-ae90-22ef5bb3e54b", "metadata": {}, "source": [ "##### our hardcoded model is pretty bad and off by 9.78 as the average is 11.35.now lets try a linear regression model" ] }, { "cell_type": "code", "execution_count": 50, "id": "9904fe14-7fe0-403f-bbb5-b0feb4ebd0a6", "metadata": {}, "outputs": [], "source": [ "model = LinearRegression()" ] }, { "cell_type": "code", "execution_count": 51, "id": "2343b47a-e222-4ed3-9388-51ac47504279", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "LinearRegression()" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 52, "id": "eecd4d0a-2364-40ff-ac26-07de15887d61", "metadata": {}, "outputs": [], "source": [ "train_linear_prediction = model.predict(train_inputs)\n", "val_linear_prediction = model.predict(val_inputs)" ] }, { "cell_type": "code", "execution_count": 53, "id": "f25c2f3f-e3c8-47af-a0fb-da20ffbb12b8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.float64(9.78741514283637)" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rmse(train_linear_prediction,train_target)" ] }, { "cell_type": "code", "execution_count": 54, "id": "66e30305-fd9e-4eaf-8424-80a901e3ee47", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.float64(9.651903871882002)" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rmse(val_linear_prediction,val_target)" ] }, { "cell_type": "markdown", "id": "46b11f02-60a4-4817-8570-372c4e7df63c", "metadata": {}, "source": [ "### conclusion of above models\n", "##### From the linear model we can come to conclusion that our linear model very bad as its is just like predicting only average of all the fare\n", "##### According to me the major reason is that the location coordinates are creating a issue .Hence ,model is not able to use them properly for predicting the values." ] }, { "cell_type": "markdown", "id": "245715ee-717a-4c37-89b2-6dab241d382d", "metadata": {}, "source": [ "## lets make our first submission" ] }, { "cell_type": "code", "execution_count": 55, "id": "30f6e2d0-64d4-4d5b-9ce9-175a5274d069", "metadata": {}, "outputs": [], "source": [ "test_prediction = model.predict(test_inputs)" ] }, { "cell_type": "code", "execution_count": 56, "id": "b99ca219-bff1-40c1-95aa-865c380e3b1a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000211.35
12015-01-27 13:08:24.000000311.35
22011-10-08 11:53:44.000000211.35
32012-12-01 21:12:12.000000211.35
42012-12-01 21:12:12.000000311.35
.........
99092015-05-10 12:37:51.000000211.35
99102015-01-12 17:05:51.000000111.35
99112015-04-19 20:44:15.000000111.35
99122015-01-31 01:05:19.000000511.35
99132015-01-18 14:06:23.000000611.35
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 11.35\n", "1 2015-01-27 13:08:24.0000003 11.35\n", "2 2011-10-08 11:53:44.0000002 11.35\n", "3 2012-12-01 21:12:12.0000002 11.35\n", "4 2012-12-01 21:12:12.0000003 11.35\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 11.35\n", "9910 2015-01-12 17:05:51.0000001 11.35\n", "9911 2015-04-19 20:44:15.0000001 11.35\n", "9912 2015-01-31 01:05:19.0000005 11.35\n", "9913 2015-01-18 14:06:23.0000006 11.35\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sub_data = pd.read_csv('./sample_submission.csv')\n", "sub_data" ] }, { "cell_type": "code", "execution_count": 57, "id": "ef082330-43e1-4240-a147-8664315d4342", "metadata": {}, "outputs": [], "source": [ "sub_data['fare_amount']= test_prediction" ] }, { "cell_type": "code", "execution_count": 58, "id": "75694ff9-a6a4-429c-9b3c-e454aa8c52f7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000211.260682
12015-01-27 13:08:24.000000311.261002
22011-10-08 11:53:44.000000211.260826
32012-12-01 21:12:12.000000211.260595
42012-12-01 21:12:12.000000311.260422
.........
99092015-05-10 12:37:51.000000211.675143
99102015-01-12 17:05:51.000000111.674895
99112015-04-19 20:44:15.000000111.678352
99122015-01-31 01:05:19.000000511.675489
99132015-01-18 14:06:23.000000611.675550
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 11.260682\n", "1 2015-01-27 13:08:24.0000003 11.261002\n", "2 2011-10-08 11:53:44.0000002 11.260826\n", "3 2012-12-01 21:12:12.0000002 11.260595\n", "4 2012-12-01 21:12:12.0000003 11.260422\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 11.675143\n", "9910 2015-01-12 17:05:51.0000001 11.674895\n", "9911 2015-04-19 20:44:15.0000001 11.678352\n", "9912 2015-01-31 01:05:19.0000005 11.675489\n", "9913 2015-01-18 14:06:23.0000006 11.675550\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sub_data" ] }, { "cell_type": "code", "execution_count": 59, "id": "a0d1ac36-aa3c-4d16-ab0e-b568960e17d6", "metadata": {}, "outputs": [], "source": [ "sub_data.to_csv('./linear_regression_submission.csv',index=None)" ] }, { "cell_type": "code", "execution_count": 60, "id": "bfb6c69f-c49e-4a5a-a2e7-65e0a97f181e", "metadata": {}, "outputs": [], "source": [ "def predict_and_submit(model,test_inputs,name):\n", " test_pred = model.predict(test_inputs)\n", " sub_data = pd.read_csv('./sample_submission.csv')\n", " sub_data['fare_amount'] = test_pred\n", " sub_data.to_csv(name,index = None)\n", " return sub_data" ] }, { "cell_type": "markdown", "id": "090565d6-ba82-463b-9ebc-3751e135db2d", "metadata": {}, "source": [ "##### Now we have seen our basic models which are performing horriblewhich take us to the next step of ML " ] }, { "cell_type": "markdown", "id": "6d9adf50-578a-41fa-960d-5c186b35ff65", "metadata": {}, "source": [ "# Step 6 : Feature Engineering\n", "##### 1. Extration of the date information\n", "##### 2. Removal of outliers and invalid data\n", "##### 3. Add distance between pickup point and drop point\n", "##### 4. Add distance from the landmark " ] }, { "cell_type": "markdown", "id": "845b80ef-21b5-4449-b741-134e6cab934d", "metadata": {}, "source": [ "### Extration of informarion from Date\n", "- Year\n", "- Month\n", "- Day\n", "- Weekday\n", "- Hour" ] }, { "cell_type": "code", "execution_count": 61, "id": "fdbc3279-874e-41b4-a32d-722890fc0e30", "metadata": {}, "outputs": [], "source": [ "def extract_info(data,col):\n", " data[col+'_year'] = data[col].dt.year\n", " data[col+'_month'] = data[col].dt.month\n", " data[col+'_day'] = data[col].dt.day\n", " data[col+'_weekday'] = data[col].dt.weekday\n", " data[col+'_hour'] = data[col].dt.hour\n", " " ] }, { "cell_type": "code", "execution_count": 62, "id": "a938bd35-150e-4d49-a5a6-7207d49030c1", "metadata": {}, "outputs": [], "source": [ "extract_info(train_data,'pickup_datetime')\n", "extract_info(val_data,'pickup_datetime')\n", "extract_info(test_data,'pickup_datetime')" ] }, { "cell_type": "code", "execution_count": 63, "id": "f347bec9-7a42-4bcc-92d0-45231eb016d2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hour
41356717.5000002015-01-02 10:55:04+00:00-73.99230240.750355-73.95075240.7783811201512410
69165.3000002009-11-23 09:02:09+00:00-73.96386040.767841-73.95462040.76570912009112309
42547225.5000002013-01-29 17:02:00+00:00-74.01065840.702446-73.98209440.77431962013129117
3982236.9000002012-05-03 04:31:00+00:00-73.94042240.711983-73.90527340.712852520125334
49839825.7000012012-08-26 16:38:30+00:00-73.87070540.773640-73.98465040.68454012012826616
.......................................
1102688.5000002010-09-10 16:24:23+00:00-73.98255240.757084-73.98604640.77573012010910416
2591786.1000002012-07-19 18:25:00+00:00-73.98307040.754841-73.98307040.75484112012719318
36583815.0000002013-05-03 10:56:31+00:00-73.98832740.754261-73.98097240.7288971201353410
13193210.0000002012-11-02 08:00:47+00:00-73.97643340.756386-73.97860040.7773821201211248
1219587.5000002014-11-04 21:26:38+00:00-73.98092740.763386-73.98232340.75104532014114121
\n", "

443008 rows × 12 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "413567 17.500000 2015-01-02 10:55:04+00:00 -73.992302 \n", "6916 5.300000 2009-11-23 09:02:09+00:00 -73.963860 \n", "425472 25.500000 2013-01-29 17:02:00+00:00 -74.010658 \n", "398223 6.900000 2012-05-03 04:31:00+00:00 -73.940422 \n", "498398 25.700001 2012-08-26 16:38:30+00:00 -73.870705 \n", "... ... ... ... \n", "110268 8.500000 2010-09-10 16:24:23+00:00 -73.982552 \n", "259178 6.100000 2012-07-19 18:25:00+00:00 -73.983070 \n", "365838 15.000000 2013-05-03 10:56:31+00:00 -73.988327 \n", "131932 10.000000 2012-11-02 08:00:47+00:00 -73.976433 \n", "121958 7.500000 2014-11-04 21:26:38+00:00 -73.980927 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \\\n", "413567 40.750355 -73.950752 40.778381 1 \n", "6916 40.767841 -73.954620 40.765709 1 \n", "425472 40.702446 -73.982094 40.774319 6 \n", "398223 40.711983 -73.905273 40.712852 5 \n", "498398 40.773640 -73.984650 40.684540 1 \n", "... ... ... ... ... \n", "110268 40.757084 -73.986046 40.775730 1 \n", "259178 40.754841 -73.983070 40.754841 1 \n", "365838 40.754261 -73.980972 40.728897 1 \n", "131932 40.756386 -73.978600 40.777382 1 \n", "121958 40.763386 -73.982323 40.751045 3 \n", "\n", " pickup_datetime_year pickup_datetime_month pickup_datetime_day \\\n", "413567 2015 1 2 \n", "6916 2009 11 23 \n", "425472 2013 1 29 \n", "398223 2012 5 3 \n", "498398 2012 8 26 \n", "... ... ... ... \n", "110268 2010 9 10 \n", "259178 2012 7 19 \n", "365838 2013 5 3 \n", "131932 2012 11 2 \n", "121958 2014 11 4 \n", "\n", " pickup_datetime_weekday pickup_datetime_hour \n", "413567 4 10 \n", "6916 0 9 \n", "425472 1 17 \n", "398223 3 4 \n", "498398 6 16 \n", "... ... ... \n", "110268 4 16 \n", "259178 3 18 \n", "365838 4 10 \n", "131932 4 8 \n", "121958 1 21 \n", "\n", "[443008 rows x 12 columns]" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data" ] }, { "cell_type": "code", "execution_count": 64, "id": "b17958b9-4402-4c11-9094-d3a6d8ad4257", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keypickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hour
02015-01-27 13:08:24.00000022015-01-27 13:08:24+00:00-73.97332040.763805-73.98143040.74383512015127113
12015-01-27 13:08:24.00000032015-01-27 13:08:24+00:00-73.98686240.719383-73.99888640.73920112015127113
22011-10-08 11:53:44.00000022011-10-08 11:53:44+00:00-73.98252140.751259-73.97965240.74614012011108511
32012-12-01 21:12:12.00000022012-12-01 21:12:12+00:00-73.98116340.767807-73.99044840.75163712012121521
42012-12-01 21:12:12.00000032012-12-01 21:12:12+00:00-73.96604940.789776-73.98856440.74442712012121521
.......................................
99092015-05-10 12:37:51.00000022015-05-10 12:37:51+00:00-73.96812440.796997-73.95564340.78038862015510612
99102015-01-12 17:05:51.00000012015-01-12 17:05:51+00:00-73.94551140.803600-73.96021340.77637162015112017
99112015-04-19 20:44:15.00000012015-04-19 20:44:15+00:00-73.99160040.726608-73.78974240.64701162015419620
99122015-01-31 01:05:19.00000052015-01-31 01:05:19+00:00-73.98557340.735432-73.93917840.8017316201513151
99132015-01-18 14:06:23.00000062015-01-18 14:06:23+00:00-73.98802240.754070-74.00028240.75922062015118614
\n", "

9914 rows × 12 columns

\n", "
" ], "text/plain": [ " key pickup_datetime pickup_longitude \\\n", "0 2015-01-27 13:08:24.0000002 2015-01-27 13:08:24+00:00 -73.973320 \n", "1 2015-01-27 13:08:24.0000003 2015-01-27 13:08:24+00:00 -73.986862 \n", "2 2011-10-08 11:53:44.0000002 2011-10-08 11:53:44+00:00 -73.982521 \n", "3 2012-12-01 21:12:12.0000002 2012-12-01 21:12:12+00:00 -73.981163 \n", "4 2012-12-01 21:12:12.0000003 2012-12-01 21:12:12+00:00 -73.966049 \n", "... ... ... ... \n", "9909 2015-05-10 12:37:51.0000002 2015-05-10 12:37:51+00:00 -73.968124 \n", "9910 2015-01-12 17:05:51.0000001 2015-01-12 17:05:51+00:00 -73.945511 \n", "9911 2015-04-19 20:44:15.0000001 2015-04-19 20:44:15+00:00 -73.991600 \n", "9912 2015-01-31 01:05:19.0000005 2015-01-31 01:05:19+00:00 -73.985573 \n", "9913 2015-01-18 14:06:23.0000006 2015-01-18 14:06:23+00:00 -73.988022 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \\\n", "0 40.763805 -73.981430 40.743835 1 \n", "1 40.719383 -73.998886 40.739201 1 \n", "2 40.751259 -73.979652 40.746140 1 \n", "3 40.767807 -73.990448 40.751637 1 \n", "4 40.789776 -73.988564 40.744427 1 \n", "... ... ... ... ... \n", "9909 40.796997 -73.955643 40.780388 6 \n", "9910 40.803600 -73.960213 40.776371 6 \n", "9911 40.726608 -73.789742 40.647011 6 \n", "9912 40.735432 -73.939178 40.801731 6 \n", "9913 40.754070 -74.000282 40.759220 6 \n", "\n", " pickup_datetime_year pickup_datetime_month pickup_datetime_day \\\n", "0 2015 1 27 \n", "1 2015 1 27 \n", "2 2011 10 8 \n", "3 2012 12 1 \n", "4 2012 12 1 \n", "... ... ... ... \n", "9909 2015 5 10 \n", "9910 2015 1 12 \n", "9911 2015 4 19 \n", "9912 2015 1 31 \n", "9913 2015 1 18 \n", "\n", " pickup_datetime_weekday pickup_datetime_hour \n", "0 1 13 \n", "1 1 13 \n", "2 5 11 \n", "3 5 21 \n", "4 5 21 \n", "... ... ... \n", "9909 6 12 \n", "9910 0 17 \n", "9911 6 20 \n", "9912 5 1 \n", "9913 6 14 \n", "\n", "[9914 rows x 12 columns]" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_data" ] }, { "cell_type": "code", "execution_count": 65, "id": "224a4296-550d-4baf-8716-1414916a8631", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hour
10556811.702010-07-24 01:47:52+00:00-73.99965740.730942-73.98842640.7199211201072451
3160334.502009-03-29 12:11:20+00:00-73.98162840.773514-73.99141740.76015512009329612
474046.502012-08-09 20:55:00+00:00-73.93552440.744961-73.90776840.7418941201289320
2205637.002014-10-22 21:08:00+00:00-73.98834240.753689-74.00198440.738670120141022221
2448306.102011-08-03 12:23:00+00:00-73.96627040.761730-73.96074740.7758905201183212
.......................................
3577966.502010-07-10 23:55:00+00:00-73.97678440.762791-73.99085240.75070612010710523
23247531.072010-05-26 07:46:34+00:00-73.97948540.763718-73.87285640.7744522201052627
1218994.902010-01-24 19:58:40+00:00-73.98956340.729935-73.99939040.73352122010124619
48010410.002012-09-10 13:59:59+00:00-74.01277940.701851-73.99596440.71633542012910013
736928.902009-09-29 06:03:00+00:00-73.98276540.727356-73.98342140.7531852200992916
\n", "

110753 rows × 12 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "105568 11.70 2010-07-24 01:47:52+00:00 -73.999657 \n", "316033 4.50 2009-03-29 12:11:20+00:00 -73.981628 \n", "47404 6.50 2012-08-09 20:55:00+00:00 -73.935524 \n", "220563 7.00 2014-10-22 21:08:00+00:00 -73.988342 \n", "244830 6.10 2011-08-03 12:23:00+00:00 -73.966270 \n", "... ... ... ... \n", "357796 6.50 2010-07-10 23:55:00+00:00 -73.976784 \n", "232475 31.07 2010-05-26 07:46:34+00:00 -73.979485 \n", "121899 4.90 2010-01-24 19:58:40+00:00 -73.989563 \n", "480104 10.00 2012-09-10 13:59:59+00:00 -74.012779 \n", "73692 8.90 2009-09-29 06:03:00+00:00 -73.982765 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \\\n", "105568 40.730942 -73.988426 40.719921 1 \n", "316033 40.773514 -73.991417 40.760155 1 \n", "47404 40.744961 -73.907768 40.741894 1 \n", "220563 40.753689 -74.001984 40.738670 1 \n", "244830 40.761730 -73.960747 40.775890 5 \n", "... ... ... ... ... \n", "357796 40.762791 -73.990852 40.750706 1 \n", "232475 40.763718 -73.872856 40.774452 2 \n", "121899 40.729935 -73.999390 40.733521 2 \n", "480104 40.701851 -73.995964 40.716335 4 \n", "73692 40.727356 -73.983421 40.753185 2 \n", "\n", " pickup_datetime_year pickup_datetime_month pickup_datetime_day \\\n", "105568 2010 7 24 \n", "316033 2009 3 29 \n", "47404 2012 8 9 \n", "220563 2014 10 22 \n", "244830 2011 8 3 \n", "... ... ... ... \n", "357796 2010 7 10 \n", "232475 2010 5 26 \n", "121899 2010 1 24 \n", "480104 2012 9 10 \n", "73692 2009 9 29 \n", "\n", " pickup_datetime_weekday pickup_datetime_hour \n", "105568 5 1 \n", "316033 6 12 \n", "47404 3 20 \n", "220563 2 21 \n", "244830 2 12 \n", "... ... ... \n", "357796 5 23 \n", "232475 2 7 \n", "121899 6 19 \n", "480104 0 13 \n", "73692 1 6 \n", "\n", "[110753 rows x 12 columns]" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val_data" ] }, { "cell_type": "markdown", "id": "bf4bd86c-9080-46ba-88a7-d07363c9290f", "metadata": {}, "source": [ "#### Now we should do some thing for the coordinates so that our model can actually utilise them\n", "#### For that I got a formula named Haversine Formula .There are many formula for this process but i found it quite easy" ] }, { "cell_type": "code", "execution_count": 66, "id": "47d0df27-b905-45ba-9370-dc567aa30b15", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "' \\nCalculate the great circle distance between two points\\non the earth (specified in decimal degrees)\\nAll args must be of equal length.\\n\\n'" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "def haversine_np(lon1, lat1, lon2, lat2):\n", " lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])\n", " dlon = lon2 - lon1\n", " dlat = lat2 - lat1\n", " a= np.sin(dlat/2.0) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2.0) ** 2\n", " c = 2 * np.arcsin(np.sqrt(a))\n", " km = 6367 * c\n", " return km\n", "''' \n", "Calculate the great circle distance between two points\n", "on the earth (specified in decimal degrees)\n", "All args must be of equal length.\n", "\n", "'''" ] }, { "cell_type": "code", "execution_count": 67, "id": "f3319b87-0403-4fcd-a559-be478e399d6e", "metadata": {}, "outputs": [], "source": [ "def distance_evaluator(data):\n", " data['trip_distance'] = haversine_np(data['pickup_longitude'],\n", " data['pickup_latitude'],\n", " data['dropoff_longitude'],\n", " data['dropoff_latitude'])" ] }, { "cell_type": "code", "execution_count": 68, "id": "de2d9fcf-bbbe-4fa7-9ac8-c4ce473419b3", "metadata": {}, "outputs": [], "source": [ "distance_evaluator(train_data)\n", "distance_evaluator(val_data)\n", "distance_evaluator(test_data)\n" ] }, { "cell_type": "code", "execution_count": 69, "id": "7cbe027e-8ed1-4a56-af0c-ad0e45b21336", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distance
41356717.5000002015-01-02 10:55:04+00:00-73.99230240.750355-73.95075240.77838112015124104.682865
69165.3000002009-11-23 09:02:09+00:00-73.96386040.767841-73.95462040.765709120091123090.813136
42547225.5000002013-01-29 17:02:00+00:00-74.01065840.702446-73.98209440.774319620131291178.340901
3982236.9000002012-05-03 04:31:00+00:00-73.94042240.711983-73.90527340.7128525201253342.962758
49839825.7000012012-08-26 16:38:30+00:00-73.87070540.773640-73.98465040.6845401201282661613.788083
..........................................
1102688.5000002010-09-10 16:24:23+00:00-73.98255240.757084-73.98604640.775730120109104162.092803
2591786.1000002012-07-19 18:25:00+00:00-73.98307040.754841-73.98307040.754841120127193180.000000
36583815.0000002013-05-03 10:56:31+00:00-73.98832740.754261-73.98097240.72889712013534102.885813
13193210.0000002012-11-02 08:00:47+00:00-73.97643340.756386-73.97860040.77738212012112482.340289
1219587.5000002014-11-04 21:26:38+00:00-73.98092740.763386-73.98232340.751045320141141211.376151
\n", "

443008 rows × 13 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "413567 17.500000 2015-01-02 10:55:04+00:00 -73.992302 \n", "6916 5.300000 2009-11-23 09:02:09+00:00 -73.963860 \n", "425472 25.500000 2013-01-29 17:02:00+00:00 -74.010658 \n", "398223 6.900000 2012-05-03 04:31:00+00:00 -73.940422 \n", "498398 25.700001 2012-08-26 16:38:30+00:00 -73.870705 \n", "... ... ... ... \n", "110268 8.500000 2010-09-10 16:24:23+00:00 -73.982552 \n", "259178 6.100000 2012-07-19 18:25:00+00:00 -73.983070 \n", "365838 15.000000 2013-05-03 10:56:31+00:00 -73.988327 \n", "131932 10.000000 2012-11-02 08:00:47+00:00 -73.976433 \n", "121958 7.500000 2014-11-04 21:26:38+00:00 -73.980927 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \\\n", "413567 40.750355 -73.950752 40.778381 1 \n", "6916 40.767841 -73.954620 40.765709 1 \n", "425472 40.702446 -73.982094 40.774319 6 \n", "398223 40.711983 -73.905273 40.712852 5 \n", "498398 40.773640 -73.984650 40.684540 1 \n", "... ... ... ... ... \n", "110268 40.757084 -73.986046 40.775730 1 \n", "259178 40.754841 -73.983070 40.754841 1 \n", "365838 40.754261 -73.980972 40.728897 1 \n", "131932 40.756386 -73.978600 40.777382 1 \n", "121958 40.763386 -73.982323 40.751045 3 \n", "\n", " pickup_datetime_year pickup_datetime_month pickup_datetime_day \\\n", "413567 2015 1 2 \n", "6916 2009 11 23 \n", "425472 2013 1 29 \n", "398223 2012 5 3 \n", "498398 2012 8 26 \n", "... ... ... ... \n", "110268 2010 9 10 \n", "259178 2012 7 19 \n", "365838 2013 5 3 \n", "131932 2012 11 2 \n", "121958 2014 11 4 \n", "\n", " pickup_datetime_weekday pickup_datetime_hour trip_distance \n", "413567 4 10 4.682865 \n", "6916 0 9 0.813136 \n", "425472 1 17 8.340901 \n", "398223 3 4 2.962758 \n", "498398 6 16 13.788083 \n", "... ... ... ... \n", "110268 4 16 2.092803 \n", "259178 3 18 0.000000 \n", "365838 4 10 2.885813 \n", "131932 4 8 2.340289 \n", "121958 1 21 1.376151 \n", "\n", "[443008 rows x 13 columns]" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data" ] }, { "cell_type": "markdown", "id": "c752a7a1-8eb0-4b1c-81eb-ce4d517542bd", "metadata": {}, "source": [ "#### Adding distance from outliers" ] }, { "cell_type": "markdown", "id": "f6c3669a-b24e-4304-8589-17bc008be190", "metadata": {}, "source": [ "#### Adding some popular landmark as the fare price will be quite high for them\n", "- JFK Airport\n", "- LGA Airport\n", "- EWR Airport\n", "- Times Square\n", "- Met Meuseum\n", "- World Trade Center" ] }, { "cell_type": "code", "execution_count": 70, "id": "ae23ba32-db4f-4ffe-b006-92ddeb0cdb5d", "metadata": {}, "outputs": [], "source": [ "jfk_lonlat = -73.7781, 40.6413\n", "lga_lonlat = -73.8740, 40.7769\n", "ewr_lonlat = -74.1745, 40.6895\n", "met_lonlat = -73.9632, 40.7794\n", "wtc_lonlat = -74.0099, 40.7126" ] }, { "cell_type": "code", "execution_count": 71, "id": "4be3f5b1-1fbd-4f86-b6fc-e788d556515a", "metadata": {}, "outputs": [], "source": [ "def landmark_dropoff_distance(data,landmark_name,landmark_loglat):\n", " log,lat = landmark_loglat\n", " data[landmark_name+'_drop_distance']= haversine_np(log ,lat ,data['dropoff_longitude'],data['dropoff_latitude'])" ] }, { "cell_type": "code", "execution_count": 72, "id": "7122270d-8d4a-43d2-b8d6-8250f7a15feb", "metadata": {}, "outputs": [], "source": [ "def add_landmark(data):\n", " landmarks = [('jfk',jfk_lonlat),\n", " ('lga',lga_lonlat),\n", " ('ewr',ewr_lonlat),\n", " ('met',met_lonlat),\n", " ('wtc',wtc_lonlat)]\n", " for name,loglat in landmarks:\n", " landmark_dropoff_distance(data,name,loglat)" ] }, { "cell_type": "code", "execution_count": 73, "id": "438f2d00-1ac5-4c3b-9639-7c50593f3462", "metadata": {}, "outputs": [], "source": [ "add_landmark(train_data)\n", "add_landmark(val_data)\n", "add_landmark(test_data)" ] }, { "cell_type": "code", "execution_count": 74, "id": "46e4faca-78fe-4a0f-ba02-dff1df1cf822", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distancejfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
41356717.5000002015-01-02 10:55:04+00:00-73.99230240.750355-73.95075240.77838112015124104.68286521.0609916.46064321.2727741.0538488.845014
69165.3000002009-11-23 09:02:09+00:00-73.96386040.767841-73.95462040.765709120091123090.81313620.3042346.89754220.3617101.6842757.516408
42547225.5000002013-01-29 17:02:00+00:00-74.01065840.702446-73.98209440.774319620131291178.34090122.6670749.10090418.7441411.6871107.246914
3982236.9000002012-05-03 04:31:00+00:00-73.94042240.711983-73.90527340.7128525201253342.96275813.3450517.58845922.8297868.8586068.813344
49839825.7000012012-08-26 16:38:30+00:00-73.87070540.773640-73.98465040.6845401201282661613.78808318.06212813.86192916.00720210.6946573.774618
.........................................................
1102688.5000002010-09-10 16:24:23+00:00-73.98255240.757084-73.98604640.775730120109104162.09280323.0217139.42939418.5381241.9647317.297377
2591786.1000002012-07-19 18:25:00+00:00-73.98307040.754841-73.98307040.754841120127193180.00000021.3873419.50154317.6818053.2005985.209414
36583815.0000002013-05-03 10:56:31+00:00-73.98832740.754261-73.98097240.72889712013534102.88581319.67233510.46603216.8801045.8079223.036025
13193210.0000002012-11-02 08:00:47+00:00-73.97643340.756386-73.97860040.77738212012112482.34028922.6699168.80205719.1700861.3147597.666023
1219587.5000002014-11-04 21:26:38+00:00-73.98092740.763386-73.98232340.751045320141141211.37615121.0900739.55886417.5715773.5377264.862882
\n", "

443008 rows × 18 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "413567 17.500000 2015-01-02 10:55:04+00:00 -73.992302 \n", "6916 5.300000 2009-11-23 09:02:09+00:00 -73.963860 \n", "425472 25.500000 2013-01-29 17:02:00+00:00 -74.010658 \n", "398223 6.900000 2012-05-03 04:31:00+00:00 -73.940422 \n", "498398 25.700001 2012-08-26 16:38:30+00:00 -73.870705 \n", "... ... ... ... \n", "110268 8.500000 2010-09-10 16:24:23+00:00 -73.982552 \n", "259178 6.100000 2012-07-19 18:25:00+00:00 -73.983070 \n", "365838 15.000000 2013-05-03 10:56:31+00:00 -73.988327 \n", "131932 10.000000 2012-11-02 08:00:47+00:00 -73.976433 \n", "121958 7.500000 2014-11-04 21:26:38+00:00 -73.980927 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \\\n", "413567 40.750355 -73.950752 40.778381 1 \n", "6916 40.767841 -73.954620 40.765709 1 \n", "425472 40.702446 -73.982094 40.774319 6 \n", "398223 40.711983 -73.905273 40.712852 5 \n", "498398 40.773640 -73.984650 40.684540 1 \n", "... ... ... ... ... \n", "110268 40.757084 -73.986046 40.775730 1 \n", "259178 40.754841 -73.983070 40.754841 1 \n", "365838 40.754261 -73.980972 40.728897 1 \n", "131932 40.756386 -73.978600 40.777382 1 \n", "121958 40.763386 -73.982323 40.751045 3 \n", "\n", " pickup_datetime_year pickup_datetime_month pickup_datetime_day \\\n", "413567 2015 1 2 \n", "6916 2009 11 23 \n", "425472 2013 1 29 \n", "398223 2012 5 3 \n", "498398 2012 8 26 \n", "... ... ... ... \n", "110268 2010 9 10 \n", "259178 2012 7 19 \n", "365838 2013 5 3 \n", "131932 2012 11 2 \n", "121958 2014 11 4 \n", "\n", " pickup_datetime_weekday pickup_datetime_hour trip_distance \\\n", "413567 4 10 4.682865 \n", "6916 0 9 0.813136 \n", "425472 1 17 8.340901 \n", "398223 3 4 2.962758 \n", "498398 6 16 13.788083 \n", "... ... ... ... \n", "110268 4 16 2.092803 \n", "259178 3 18 0.000000 \n", "365838 4 10 2.885813 \n", "131932 4 8 2.340289 \n", "121958 1 21 1.376151 \n", "\n", " jfk_drop_distance lga_drop_distance ewr_drop_distance \\\n", "413567 21.060991 6.460643 21.272774 \n", "6916 20.304234 6.897542 20.361710 \n", "425472 22.667074 9.100904 18.744141 \n", "398223 13.345051 7.588459 22.829786 \n", "498398 18.062128 13.861929 16.007202 \n", "... ... ... ... \n", "110268 23.021713 9.429394 18.538124 \n", "259178 21.387341 9.501543 17.681805 \n", "365838 19.672335 10.466032 16.880104 \n", "131932 22.669916 8.802057 19.170086 \n", "121958 21.090073 9.558864 17.571577 \n", "\n", " met_drop_distance wtc_drop_distance \n", "413567 1.053848 8.845014 \n", "6916 1.684275 7.516408 \n", "425472 1.687110 7.246914 \n", "398223 8.858606 8.813344 \n", "498398 10.694657 3.774618 \n", "... ... ... \n", "110268 1.964731 7.297377 \n", "259178 3.200598 5.209414 \n", "365838 5.807922 3.036025 \n", "131932 1.314759 7.666023 \n", "121958 3.537726 4.862882 \n", "\n", "[443008 rows x 18 columns]" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data" ] }, { "cell_type": "code", "execution_count": 75, "id": "cb5b0400-4919-4fd5-bc27-8bd99b242b6e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distancejfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
count9914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.0000009914.000000
mean-73.97471640.751041-73.97365640.7517401.6712732011.8158166.85797916.1941702.85283413.4674203.43321620.9167549.67518018.5466594.5128986.037652
std0.0427990.0335420.0390930.0354361.2787471.8033473.3532728.8384821.9944516.8685843.9698773.3039403.2956464.0358164.0184224.252535
min-74.25219040.573143-74.26324540.5689741.0000002009.0000001.0000001.0000000.0000000.0000000.0000000.4019000.2856290.2846800.0857470.040269
25%-73.99250040.736125-73.99124940.7352531.0000002010.0000004.0000009.0000001.0000008.0000001.29726120.5133378.31156516.5205172.1262873.670107
50%-73.98232740.753052-73.98001540.7540651.0000002012.0000007.00000016.0000003.00000015.0000002.21564821.1814729.47779718.0243503.6981235.541466
75%-73.96801240.767113-73.96406240.7687572.0000002014.00000010.00000025.0000005.00000019.0000004.04305121.90979410.96527219.8805365.9225447.757612
max-72.98653441.709557-72.99096741.6966826.0000002015.00000012.00000031.0000006.00000023.00000099.933281134.497726126.062576149.400787130.347153138.619492
\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude dropoff_latitude \\\n", "count 9914.000000 9914.000000 9914.000000 9914.000000 \n", "mean -73.974716 40.751041 -73.973656 40.751740 \n", "std 0.042799 0.033542 0.039093 0.035436 \n", "min -74.252190 40.573143 -74.263245 40.568974 \n", "25% -73.992500 40.736125 -73.991249 40.735253 \n", "50% -73.982327 40.753052 -73.980015 40.754065 \n", "75% -73.968012 40.767113 -73.964062 40.768757 \n", "max -72.986534 41.709557 -72.990967 41.696682 \n", "\n", " passenger_count pickup_datetime_year pickup_datetime_month \\\n", "count 9914.000000 9914.000000 9914.000000 \n", "mean 1.671273 2011.815816 6.857979 \n", "std 1.278747 1.803347 3.353272 \n", "min 1.000000 2009.000000 1.000000 \n", "25% 1.000000 2010.000000 4.000000 \n", "50% 1.000000 2012.000000 7.000000 \n", "75% 2.000000 2014.000000 10.000000 \n", "max 6.000000 2015.000000 12.000000 \n", "\n", " pickup_datetime_day pickup_datetime_weekday pickup_datetime_hour \\\n", "count 9914.000000 9914.000000 9914.000000 \n", "mean 16.194170 2.852834 13.467420 \n", "std 8.838482 1.994451 6.868584 \n", "min 1.000000 0.000000 0.000000 \n", "25% 9.000000 1.000000 8.000000 \n", "50% 16.000000 3.000000 15.000000 \n", "75% 25.000000 5.000000 19.000000 \n", "max 31.000000 6.000000 23.000000 \n", "\n", " trip_distance jfk_drop_distance lga_drop_distance ewr_drop_distance \\\n", "count 9914.000000 9914.000000 9914.000000 9914.000000 \n", "mean 3.433216 20.916754 9.675180 18.546659 \n", "std 3.969877 3.303940 3.295646 4.035816 \n", "min 0.000000 0.401900 0.285629 0.284680 \n", "25% 1.297261 20.513337 8.311565 16.520517 \n", "50% 2.215648 21.181472 9.477797 18.024350 \n", "75% 4.043051 21.909794 10.965272 19.880536 \n", "max 99.933281 134.497726 126.062576 149.400787 \n", "\n", " met_drop_distance wtc_drop_distance \n", "count 9914.000000 9914.000000 \n", "mean 4.512898 6.037652 \n", "std 4.018422 4.252535 \n", "min 0.085747 0.040269 \n", "25% 2.126287 3.670107 \n", "50% 3.698123 5.541466 \n", "75% 5.922544 7.757612 \n", "max 130.347153 138.619492 " ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_data.describe()" ] }, { "cell_type": "markdown", "id": "c5eb6048-b7e3-41ec-984f-5afa6249ef39", "metadata": {}, "source": [ "#### Removal of outlier and invalid data" ] }, { "cell_type": "code", "execution_count": 76, "id": "14e8f3d6-12f9-45da-a179-8de2a7b501e1", "metadata": {}, "outputs": [], "source": [ "def remove_outliers(df):\n", " return df[(df['fare_amount'] >= 1.) &\n", " (df['fare_amount' ] <= 500.) &\n", " (df['pickup_longitude' ] >= -75) &\n", " (df['pickup_longitude' ] <= -72) &\n", " (df['dropoff_longitude' ] >= -75) &\n", " (df['dropoff_longitude' ] <= -72) &\n", " (df['pickup_latitude' ] >= 40) &\n", " (df['pickup_latitude' ] <= 42) &\n", " (df['dropoff_latitude' ] >=40) &\n", " (df['dropoff_latitude' ] <= 42) &\n", " (df['passenger_count' ] >= 1) &\n", " (df['passenger_count'] <= 6)]" ] }, { "cell_type": "code", "execution_count": 77, "id": "41cfbb4d-caf8-4abd-9c54-d0f96a41ca73", "metadata": {}, "outputs": [], "source": [ "train_data =remove_outliers(train_data)" ] }, { "cell_type": "code", "execution_count": 78, "id": "440fb509-52cd-4d4a-b49b-1f1db480cf18", "metadata": {}, "outputs": [], "source": [ "val_data=remove_outliers(val_data)" ] }, { "cell_type": "code", "execution_count": 79, "id": "ef2baf73-b7a6-4d59-ac18-f9333cb8e6e7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distancejfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
count432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000
mean11.322276-73.97522740.751091-73.97432740.7514611.6941402011.7383536.27705415.7274783.03993613.4955933.32597520.9118739.67711418.4781884.4792605.964223
std9.7203830.0450100.0914960.0447890.0931341.3089911.8626933.4348058.6828641.9507836.5232323.7493943.0805433.0372623.7155003.7459023.955843
min2.000000-74.73700040.042759-74.85617840.0418131.0000002009.0000001.0000001.0000000.0000000.0000000.0000000.3741310.2044640.2721860.0436130.011009
25%6.000000-73.99230240.736542-73.99161540.7356411.0000002010.0000003.0000008.0000001.0000009.0000001.25467520.5238088.31692116.4785922.1358523.587798
50%8.500000-73.98210940.753387-73.98060640.7538531.0000002012.0000006.00000016.0000003.00000014.0000002.15329321.1789159.52005917.9630743.7139105.494621
75%12.500000-73.96832340.767616-73.96534740.7684292.0000002013.0000009.00000023.0000005.00000019.0000003.91656421.90390510.98402219.7894245.8931037.653542
max430.000000-72.33237541.949165-72.33573241.9639976.0000002015.00000012.00000031.0000006.00000023.000000104.961227150.597977153.665161171.514008160.247757160.129211
\n", "
" ], "text/plain": [ " fare_amount pickup_longitude pickup_latitude dropoff_longitude \\\n", "count 432270.000000 432270.000000 432270.000000 432270.000000 \n", "mean 11.322276 -73.975227 40.751091 -73.974327 \n", "std 9.720383 0.045010 0.091496 0.044789 \n", "min 2.000000 -74.737000 40.042759 -74.856178 \n", "25% 6.000000 -73.992302 40.736542 -73.991615 \n", "50% 8.500000 -73.982109 40.753387 -73.980606 \n", "75% 12.500000 -73.968323 40.767616 -73.965347 \n", "max 430.000000 -72.332375 41.949165 -72.335732 \n", "\n", " dropoff_latitude passenger_count pickup_datetime_year \\\n", "count 432270.000000 432270.000000 432270.000000 \n", "mean 40.751461 1.694140 2011.738353 \n", "std 0.093134 1.308991 1.862693 \n", "min 40.041813 1.000000 2009.000000 \n", "25% 40.735641 1.000000 2010.000000 \n", "50% 40.753853 1.000000 2012.000000 \n", "75% 40.768429 2.000000 2013.000000 \n", "max 41.963997 6.000000 2015.000000 \n", "\n", " pickup_datetime_month pickup_datetime_day pickup_datetime_weekday \\\n", "count 432270.000000 432270.000000 432270.000000 \n", "mean 6.277054 15.727478 3.039936 \n", "std 3.434805 8.682864 1.950783 \n", "min 1.000000 1.000000 0.000000 \n", "25% 3.000000 8.000000 1.000000 \n", "50% 6.000000 16.000000 3.000000 \n", "75% 9.000000 23.000000 5.000000 \n", "max 12.000000 31.000000 6.000000 \n", "\n", " pickup_datetime_hour trip_distance jfk_drop_distance \\\n", "count 432270.000000 432270.000000 432270.000000 \n", "mean 13.495593 3.325975 20.911873 \n", "std 6.523232 3.749394 3.080543 \n", "min 0.000000 0.000000 0.374131 \n", "25% 9.000000 1.254675 20.523808 \n", "50% 14.000000 2.153293 21.178915 \n", "75% 19.000000 3.916564 21.903905 \n", "max 23.000000 104.961227 150.597977 \n", "\n", " lga_drop_distance ewr_drop_distance met_drop_distance \\\n", "count 432270.000000 432270.000000 432270.000000 \n", "mean 9.677114 18.478188 4.479260 \n", "std 3.037262 3.715500 3.745902 \n", "min 0.204464 0.272186 0.043613 \n", "25% 8.316921 16.478592 2.135852 \n", "50% 9.520059 17.963074 3.713910 \n", "75% 10.984022 19.789424 5.893103 \n", "max 153.665161 171.514008 160.247757 \n", "\n", " wtc_drop_distance \n", "count 432270.000000 \n", "mean 5.964223 \n", "std 3.955843 \n", "min 0.011009 \n", "25% 3.587798 \n", "50% 5.494621 \n", "75% 7.653542 \n", "max 160.129211 " ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data.describe()" ] }, { "cell_type": "markdown", "id": "acb38c53-4fc9-443e-8864-30a600844fb3", "metadata": {}, "source": [ "#### Creation of parquet file to save our progress\n", "##### this help in not doing preprocessing again and again as processes data is saved\n", "##### we used parquet as it is faster then csv. As csv ccovert data to string" ] }, { "cell_type": "code", "execution_count": 80, "id": "f051879f-fc29-4434-bddd-613f9439a679", "metadata": {}, "outputs": [], "source": [ "train_data.to_parquet('./parkuet_file/train.parquet')\n", "val_data.to_parquet('./parkuet_file/val.parquet')\n", "test_data.to_parquet('./parkuet_file/test.parquet')" ] }, { "cell_type": "markdown", "id": "e994e987-aa41-4e28-91b0-e988f11b932a", "metadata": {}, "source": [ "# Step 7 : Preprocessing before Fitting\n", "- Loading of the parquet file to load processed file\n", "- Determining of columns to be used as input and target columns\n", "- Loading of input and target columnsof the training set\n", "- Preperation of the function for diretly fitting the dataset ,get prediction and then check accuracy" ] }, { "cell_type": "code", "execution_count": 81, "id": "7bec07d5-7b54-45cd-aa02-8bb6c7ec569e", "metadata": {}, "outputs": [], "source": [ "train_data = pd.read_parquet('./parkuet_file/train.parquet')\n", "val_data = pd.read_parquet('./parkuet_file/val.parquet')\n", "test_data = pd.read_parquet('./parkuet_file/test.parquet')" ] }, { "cell_type": "code", "execution_count": 82, "id": "bc05676d-71fc-48b3-bfa6-7e5be661c838", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keypickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distancejfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
02015-01-27 13:08:24.00000022015-01-27 13:08:24+00:00-73.97332040.763805-73.98143040.743835120151271132.32189920.5749119.76016717.3468424.2393434.218709
12015-01-27 13:08:24.00000032015-01-27 13:08:24+00:00-73.98686240.719383-73.99888640.739201120151271132.42377721.55097611.31599015.7896235.3828793.098136
22011-10-08 11:53:44.00000022011-10-08 11:53:44+00:00-73.98252140.751259-73.97965240.746140120111085110.61801520.5940699.52682917.5769653.9467214.514503
32012-12-01 21:12:12.00000022012-12-01 21:12:12+00:00-73.98116340.767807-73.99044840.751637120121215211.95968121.68936510.19509116.9696503.8438924.637048
42012-12-01 21:12:12.00000032012-12-01 21:12:12+00:00-73.96604940.789776-73.98856440.744427120121215215.38382921.11399310.29585716.8083674.4337643.967223
.........................................................
99092015-05-10 12:37:51.00000022015-05-10 12:37:51+00:00-73.96812440.796997-73.95564340.780388620155106122.12326521.5071816.88090521.0150130.6456838.809922
99102015-01-12 17:05:51.00000012015-01-12 17:05:51+00:00-73.94551140.803600-73.96021340.776371620151120173.26908421.4621837.25493120.4644570.4203418.229158
99112015-04-19 20:44:15.00000012015-04-19 20:44:15+00:00-73.99160040.726608-73.78974240.6470116201541962019.1715341.16910516.08449432.77236920.73423819.933737
99122015-01-31 01:05:19.00000052015-01-31 01:05:19+00:00-73.98557340.735432-73.93917840.80173162015131518.33815422.4024186.13851823.4107723.20079011.556184
99132015-01-18 14:06:23.00000062015-01-18 14:06:23+00:00-73.98802240.754070-74.00028240.759220620151186141.18007222.84943010.80827916.5919913.8428875.243497
\n", "

9914 rows × 18 columns

\n", "
" ], "text/plain": [ " key pickup_datetime pickup_longitude \\\n", "0 2015-01-27 13:08:24.0000002 2015-01-27 13:08:24+00:00 -73.973320 \n", "1 2015-01-27 13:08:24.0000003 2015-01-27 13:08:24+00:00 -73.986862 \n", "2 2011-10-08 11:53:44.0000002 2011-10-08 11:53:44+00:00 -73.982521 \n", "3 2012-12-01 21:12:12.0000002 2012-12-01 21:12:12+00:00 -73.981163 \n", "4 2012-12-01 21:12:12.0000003 2012-12-01 21:12:12+00:00 -73.966049 \n", "... ... ... ... \n", "9909 2015-05-10 12:37:51.0000002 2015-05-10 12:37:51+00:00 -73.968124 \n", "9910 2015-01-12 17:05:51.0000001 2015-01-12 17:05:51+00:00 -73.945511 \n", "9911 2015-04-19 20:44:15.0000001 2015-04-19 20:44:15+00:00 -73.991600 \n", "9912 2015-01-31 01:05:19.0000005 2015-01-31 01:05:19+00:00 -73.985573 \n", "9913 2015-01-18 14:06:23.0000006 2015-01-18 14:06:23+00:00 -73.988022 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \\\n", "0 40.763805 -73.981430 40.743835 1 \n", "1 40.719383 -73.998886 40.739201 1 \n", "2 40.751259 -73.979652 40.746140 1 \n", "3 40.767807 -73.990448 40.751637 1 \n", "4 40.789776 -73.988564 40.744427 1 \n", "... ... ... ... ... \n", "9909 40.796997 -73.955643 40.780388 6 \n", "9910 40.803600 -73.960213 40.776371 6 \n", "9911 40.726608 -73.789742 40.647011 6 \n", "9912 40.735432 -73.939178 40.801731 6 \n", "9913 40.754070 -74.000282 40.759220 6 \n", "\n", " pickup_datetime_year pickup_datetime_month pickup_datetime_day \\\n", "0 2015 1 27 \n", "1 2015 1 27 \n", "2 2011 10 8 \n", "3 2012 12 1 \n", "4 2012 12 1 \n", "... ... ... ... \n", "9909 2015 5 10 \n", "9910 2015 1 12 \n", "9911 2015 4 19 \n", "9912 2015 1 31 \n", "9913 2015 1 18 \n", "\n", " pickup_datetime_weekday pickup_datetime_hour trip_distance \\\n", "0 1 13 2.321899 \n", "1 1 13 2.423777 \n", "2 5 11 0.618015 \n", "3 5 21 1.959681 \n", "4 5 21 5.383829 \n", "... ... ... ... \n", "9909 6 12 2.123265 \n", "9910 0 17 3.269084 \n", "9911 6 20 19.171534 \n", "9912 5 1 8.338154 \n", "9913 6 14 1.180072 \n", "\n", " jfk_drop_distance lga_drop_distance ewr_drop_distance \\\n", "0 20.574911 9.760167 17.346842 \n", "1 21.550976 11.315990 15.789623 \n", "2 20.594069 9.526829 17.576965 \n", "3 21.689365 10.195091 16.969650 \n", "4 21.113993 10.295857 16.808367 \n", "... ... ... ... \n", "9909 21.507181 6.880905 21.015013 \n", "9910 21.462183 7.254931 20.464457 \n", "9911 1.169105 16.084494 32.772369 \n", "9912 22.402418 6.138518 23.410772 \n", "9913 22.849430 10.808279 16.591991 \n", "\n", " met_drop_distance wtc_drop_distance \n", "0 4.239343 4.218709 \n", "1 5.382879 3.098136 \n", "2 3.946721 4.514503 \n", "3 3.843892 4.637048 \n", "4 4.433764 3.967223 \n", "... ... ... \n", "9909 0.645683 8.809922 \n", "9910 0.420341 8.229158 \n", "9911 20.734238 19.933737 \n", "9912 3.200790 11.556184 \n", "9913 3.842887 5.243497 \n", "\n", "[9914 rows x 18 columns]" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_data" ] }, { "cell_type": "code", "execution_count": 83, "id": "215dcac2-dfcd-45ca-a8ae-47c1660ac61f", "metadata": {}, "outputs": [], "source": [ "input_cols = ['pickup_longitude', 'pickup_latitude',\n", " 'dropoff_longitude', 'dropoff_latitude', 'passenger_count',\n", " 'pickup_datetime_year', 'pickup_datetime_month', 'pickup_datetime_day',\n", " 'pickup_datetime_weekday', 'pickup_datetime_hour', 'trip_distance',\n", " 'jfk_drop_distance', 'lga_drop_distance', 'ewr_drop_distance',\n", " 'met_drop_distance', 'wtc_drop_distance']" ] }, { "cell_type": "code", "execution_count": 84, "id": "dbb0be7a-6976-4e83-b8fd-0afca4507e66", "metadata": {}, "outputs": [], "source": [ "target_col = 'fare_amount'" ] }, { "cell_type": "code", "execution_count": 85, "id": "6e0e6e2d-244b-4c92-afc5-5bee2d081249", "metadata": {}, "outputs": [], "source": [ "train_inputs = train_data[input_cols]\n", "train_target = train_data[target_col]\n", "val_inputs = val_data[input_cols]\n", "val_target = val_data[target_col]\n", "test_inputs = test_data[input_cols]\n" ] }, { "cell_type": "code", "execution_count": 86, "id": "2497c455-f904-4a01-9008-5aa6be502a49", "metadata": {}, "outputs": [], "source": [ "def score_evaluator(model):\n", " train_pred = model.predict(train_inputs)\n", " train_rmse = np.sqrt(mean_squared_error(train_target,train_pred))\n", " val_pred = model.predict(val_inputs)\n", " val_rmse = np.sqrt(mean_squared_error(val_pred,val_target))\n", " return train_pred,train_rmse,val_pred,val_rmse" ] }, { "cell_type": "code", "execution_count": 87, "id": "63d246ce-bf5c-4e46-9443-bcf8390c4d8c", "metadata": {}, "outputs": [], "source": [ "def params_applier(model,**params):\n", " model = model(**params)\n", " model.fit(train_inputs,train_target)\n", " train_pred = model.predict(train_inputs)\n", " train_rmse = np.sqrt(mean_squared_error(train_target,train_pred))\n", " val_pred = model.predict(val_inputs)\n", " val_rmse = np.sqrt(mean_squared_error(val_pred,val_target))\n", " return train_pred,train_rmse,val_pred,val_rmse" ] }, { "cell_type": "markdown", "id": "fd716ce6-451f-4160-b8c9-01ef6e6b3404", "metadata": {}, "source": [ "# Step 8 : Training and Evaluating Diffrent Model\n", "##### Now we are in the phase where we are gong to train some highly efficient model \n", "##### Model we are going to use --:\n", "- Linear Regression (might perform better after feature engineering)\n", "- Random Forest\n", "- GBM(gradient boosting machine)\n", "- Ridge\n", "- Lasso\n", "- SVM(Support Vector Machine)\n", "- KNN(K-Nearest Neighbour)" ] }, { "cell_type": "markdown", "id": "c7caeeb1-edcc-4bdb-b10a-a6d36afbfba9", "metadata": {}, "source": [ "### Model 1 : Ridge Regression" ] }, { "cell_type": "code", "execution_count": 88, "id": "1ed379de-c93e-49c7-a527-b439be149ac8", "metadata": {}, "outputs": [], "source": [ "from sklearn.linear_model import Ridge" ] }, { "cell_type": "code", "execution_count": 90, "id": "0d528184-a477-40d9-8245-4770b30f90a2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.8858981 , 4.85035913, 20.80086663, ..., 9.84399425,\n", " 9.17181959, 8.71264336]),\n", " np.float64(5.212731128448278),\n", " array([ 6.12756065, 5.80709989, 12.71209526, ..., 5.56511114,\n", " 9.35171355, 9.10211576]),\n", " np.float64(4.844422446865962))" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(Ridge,random_state=42 ,alpha =0.9)" ] }, { "cell_type": "code", "execution_count": 91, "id": "587e1d7c-e2cb-422f-ac40-13dd85388aae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88537449, 4.85004809, 20.80101813, ..., 9.84372732,\n", " 9.17189279, 8.71253538]),\n", " np.float64(5.212730390861352),\n", " array([ 6.1275987 , 5.80707533, 12.71221857, ..., 5.56553648,\n", " 9.35201411, 9.10241875]),\n", " np.float64(4.844431673689443))" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(Ridge,random_state=42 ,alpha =0.8)" ] }, { "cell_type": "code", "execution_count": 92, "id": "603a3046-ef38-400f-999f-ee476191c44d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88484734, 4.8497348 , 20.80116931, ..., 9.84345953,\n", " 9.17196614, 8.71242712]),\n", " np.float64(5.2127297342168655),\n", " array([ 6.12763709, 5.80705139, 12.71234161, ..., 5.565964 ,\n", " 9.35231582, 9.10272265]),\n", " np.float64(4.844441026668556))" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(Ridge,random_state=42 ,alpha =0.7)" ] }, { "cell_type": "code", "execution_count": 93, "id": "bbf3192f-9b57-4fac-90e8-0c8c07c9f264", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88431661, 4.84941925, 20.80132015, ..., 9.84319089,\n", " 9.17203964, 8.71231858]),\n", " np.float64(5.212729160001666),\n", " array([ 6.12767582, 5.80702808, 12.71246438, ..., 5.56639373,\n", " 9.35261868, 9.10302745]),\n", " np.float64(4.844450507907827))" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(Ridge,random_state=42 ,alpha =0.6)" ] }, { "cell_type": "code", "execution_count": 94, "id": "878a6a09-8b62-47b1-9240-323ab9bb2118", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88378225, 4.84910142, 20.80147064, ..., 9.84292138,\n", " 9.17211329, 8.71220975]),\n", " np.float64(5.212728669734149),\n", " array([ 6.12771491, 5.8070054 , 12.71258687, ..., 5.56682567,\n", " 9.35292271, 9.10333316]),\n", " np.float64(4.844460119554494))" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(Ridge,random_state=42 ,alpha =0.5)" ] }, { "cell_type": "code", "execution_count": 95, "id": "ddbf61e5-bf33-41f0-99c3-e659c31f0527", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distancejfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
count432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000432270.000000
mean-73.97522740.751091-73.97432740.7514611.6941402011.7383536.27705415.7274783.03993613.4955933.32597520.9118739.67711418.4781884.4792605.964223
std0.0450100.0914960.0447890.0931341.3089911.8626933.4348058.6828641.9507836.5232323.7493943.0805433.0372623.7155003.7459023.955843
min-74.73700040.042759-74.85617840.0418131.0000002009.0000001.0000001.0000000.0000000.0000000.0000000.3741310.2044640.2721860.0436130.011009
25%-73.99230240.736542-73.99161540.7356411.0000002010.0000003.0000008.0000001.0000009.0000001.25467520.5238088.31692116.4785922.1358523.587798
50%-73.98210940.753387-73.98060640.7538531.0000002012.0000006.00000016.0000003.00000014.0000002.15329321.1789159.52005917.9630743.7139105.494621
75%-73.96832340.767616-73.96534740.7684292.0000002013.0000009.00000023.0000005.00000019.0000003.91656421.90390510.98402219.7894245.8931037.653542
max-72.33237541.949165-72.33573241.9639976.0000002015.00000012.00000031.0000006.00000023.000000104.961227150.597977153.665161171.514008160.247757160.129211
\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude dropoff_latitude \\\n", "count 432270.000000 432270.000000 432270.000000 432270.000000 \n", "mean -73.975227 40.751091 -73.974327 40.751461 \n", "std 0.045010 0.091496 0.044789 0.093134 \n", "min -74.737000 40.042759 -74.856178 40.041813 \n", "25% -73.992302 40.736542 -73.991615 40.735641 \n", "50% -73.982109 40.753387 -73.980606 40.753853 \n", "75% -73.968323 40.767616 -73.965347 40.768429 \n", "max -72.332375 41.949165 -72.335732 41.963997 \n", "\n", " passenger_count pickup_datetime_year pickup_datetime_month \\\n", "count 432270.000000 432270.000000 432270.000000 \n", "mean 1.694140 2011.738353 6.277054 \n", "std 1.308991 1.862693 3.434805 \n", "min 1.000000 2009.000000 1.000000 \n", "25% 1.000000 2010.000000 3.000000 \n", "50% 1.000000 2012.000000 6.000000 \n", "75% 2.000000 2013.000000 9.000000 \n", "max 6.000000 2015.000000 12.000000 \n", "\n", " pickup_datetime_day pickup_datetime_weekday pickup_datetime_hour \\\n", "count 432270.000000 432270.000000 432270.000000 \n", "mean 15.727478 3.039936 13.495593 \n", "std 8.682864 1.950783 6.523232 \n", "min 1.000000 0.000000 0.000000 \n", "25% 8.000000 1.000000 9.000000 \n", "50% 16.000000 3.000000 14.000000 \n", "75% 23.000000 5.000000 19.000000 \n", "max 31.000000 6.000000 23.000000 \n", "\n", " trip_distance jfk_drop_distance lga_drop_distance ewr_drop_distance \\\n", "count 432270.000000 432270.000000 432270.000000 432270.000000 \n", "mean 3.325975 20.911873 9.677114 18.478188 \n", "std 3.749394 3.080543 3.037262 3.715500 \n", "min 0.000000 0.374131 0.204464 0.272186 \n", "25% 1.254675 20.523808 8.316921 16.478592 \n", "50% 2.153293 21.178915 9.520059 17.963074 \n", "75% 3.916564 21.903905 10.984022 19.789424 \n", "max 104.961227 150.597977 153.665161 171.514008 \n", "\n", " met_drop_distance wtc_drop_distance \n", "count 432270.000000 432270.000000 \n", "mean 4.479260 5.964223 \n", "std 3.745902 3.955843 \n", "min 0.043613 0.011009 \n", "25% 2.135852 3.587798 \n", "50% 3.713910 5.494621 \n", "75% 5.893103 7.653542 \n", "max 160.247757 160.129211 " ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_inputs.describe()" ] }, { "cell_type": "code", "execution_count": null, "id": "efc54bb8-c415-487f-9e90-029e53ac0d98", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 96, "id": "0030eb9b-9882-4ec0-a007-003631f6a799", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_countpickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourtrip_distancejfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
0-73.97332040.763805-73.98143040.743835120151271132.32189920.5749119.76016717.3468424.2393434.218709
1-73.98686240.719383-73.99888640.739201120151271132.42377721.55097611.31599015.7896235.3828793.098136
2-73.98252140.751259-73.97965240.746140120111085110.61801520.5940699.52682917.5769653.9467214.514503
3-73.98116340.767807-73.99044840.751637120121215211.95968121.68936510.19509116.9696503.8438924.637048
4-73.96604940.789776-73.98856440.744427120121215215.38382921.11399310.29585716.8083674.4337643.967223
...................................................
9909-73.96812440.796997-73.95564340.780388620155106122.12326521.5071816.88090521.0150130.6456838.809922
9910-73.94551140.803600-73.96021340.776371620151120173.26908421.4621837.25493120.4644570.4203418.229158
9911-73.99160040.726608-73.78974240.6470116201541962019.1715341.16910516.08449432.77236920.73423819.933737
9912-73.98557340.735432-73.93917840.80173162015131518.33815422.4024186.13851823.4107723.20079011.556184
9913-73.98802240.754070-74.00028240.759220620151186141.18007222.84943010.80827916.5919913.8428875.243497
\n", "

9914 rows × 16 columns

\n", "
" ], "text/plain": [ " pickup_longitude pickup_latitude dropoff_longitude dropoff_latitude \\\n", "0 -73.973320 40.763805 -73.981430 40.743835 \n", "1 -73.986862 40.719383 -73.998886 40.739201 \n", "2 -73.982521 40.751259 -73.979652 40.746140 \n", "3 -73.981163 40.767807 -73.990448 40.751637 \n", "4 -73.966049 40.789776 -73.988564 40.744427 \n", "... ... ... ... ... \n", "9909 -73.968124 40.796997 -73.955643 40.780388 \n", "9910 -73.945511 40.803600 -73.960213 40.776371 \n", "9911 -73.991600 40.726608 -73.789742 40.647011 \n", "9912 -73.985573 40.735432 -73.939178 40.801731 \n", "9913 -73.988022 40.754070 -74.000282 40.759220 \n", "\n", " passenger_count pickup_datetime_year pickup_datetime_month \\\n", "0 1 2015 1 \n", "1 1 2015 1 \n", "2 1 2011 10 \n", "3 1 2012 12 \n", "4 1 2012 12 \n", "... ... ... ... \n", "9909 6 2015 5 \n", "9910 6 2015 1 \n", "9911 6 2015 4 \n", "9912 6 2015 1 \n", "9913 6 2015 1 \n", "\n", " pickup_datetime_day pickup_datetime_weekday pickup_datetime_hour \\\n", "0 27 1 13 \n", "1 27 1 13 \n", "2 8 5 11 \n", "3 1 5 21 \n", "4 1 5 21 \n", "... ... ... ... \n", "9909 10 6 12 \n", "9910 12 0 17 \n", "9911 19 6 20 \n", "9912 31 5 1 \n", "9913 18 6 14 \n", "\n", " trip_distance jfk_drop_distance lga_drop_distance ewr_drop_distance \\\n", "0 2.321899 20.574911 9.760167 17.346842 \n", "1 2.423777 21.550976 11.315990 15.789623 \n", "2 0.618015 20.594069 9.526829 17.576965 \n", "3 1.959681 21.689365 10.195091 16.969650 \n", "4 5.383829 21.113993 10.295857 16.808367 \n", "... ... ... ... ... \n", "9909 2.123265 21.507181 6.880905 21.015013 \n", "9910 3.269084 21.462183 7.254931 20.464457 \n", "9911 19.171534 1.169105 16.084494 32.772369 \n", "9912 8.338154 22.402418 6.138518 23.410772 \n", "9913 1.180072 22.849430 10.808279 16.591991 \n", "\n", " met_drop_distance wtc_drop_distance \n", "0 4.239343 4.218709 \n", "1 5.382879 3.098136 \n", "2 3.946721 4.514503 \n", "3 3.843892 4.637048 \n", "4 4.433764 3.967223 \n", "... ... ... \n", "9909 0.645683 8.809922 \n", "9910 0.420341 8.229158 \n", "9911 20.734238 19.933737 \n", "9912 3.200790 11.556184 \n", "9913 3.842887 5.243497 \n", "\n", "[9914 rows x 16 columns]" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_inputs" ] }, { "cell_type": "code", "execution_count": 97, "id": "3ca2786c-716e-4045-8fda-3a667050eefb", "metadata": {}, "outputs": [], "source": [ "model = Ridge(random_state=42,alpha=0.9).fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 98, "id": "c0de2f15-500e-4e8e-9265-d0f3e27a80c8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.066323
12015-01-27 13:08:24.000000311.506266
22011-10-08 11:53:44.00000025.384196
32012-12-01 21:12:12.00000028.663776
42012-12-01 21:12:12.000000314.299980
.........
99092015-05-10 12:37:51.00000028.952122
99102015-01-12 17:05:51.000000111.103142
99112015-04-19 20:44:15.000000147.551853
99122015-01-31 01:05:19.000000522.631507
99132015-01-18 14:06:23.00000069.029021
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.066323\n", "1 2015-01-27 13:08:24.0000003 11.506266\n", "2 2011-10-08 11:53:44.0000002 5.384196\n", "3 2012-12-01 21:12:12.0000002 8.663776\n", "4 2012-12-01 21:12:12.0000003 14.299980\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 8.952122\n", "9910 2015-01-12 17:05:51.0000001 11.103142\n", "9911 2015-04-19 20:44:15.0000001 47.551853\n", "9912 2015-01-31 01:05:19.0000005 22.631507\n", "9913 2015-01-18 14:06:23.0000006 9.029021\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model,test_inputs,'./submissions/Ridge_submission.csv')" ] }, { "cell_type": "markdown", "id": "a6b38fe8-9f54-4384-8097-72f91e411de2", "metadata": {}, "source": [ "#### the hyper parammeters are not working in this case as there is not a massive variation the values we will fix this by Standard Scaler or min max scaler" ] }, { "cell_type": "markdown", "id": "34a57987-24f6-49e0-bf17-df2c9c81fe2e", "metadata": {}, "source": [ "### Model 2 : Random Forest" ] }, { "cell_type": "code", "execution_count": 99, "id": "95bf5af7-6959-4fb1-bc74-5c743dc64ba7", "metadata": {}, "outputs": [], "source": [ "from sklearn.ensemble import RandomForestRegressor" ] }, { "cell_type": "code", "execution_count": 100, "id": "5a6cdf98-0708-454d-a354-55094236059d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.17115336, 5.23969457, 25.15222804, ..., 12.90097606,\n", " 10.21886948, 7.06778299]),\n", " np.float64(2.4135996889460505),\n", " array([ 6.50760981, 6.72618106, 8.98320984, ..., 4.9921903 ,\n", " 10.31905095, 8.19662529]),\n", " np.float64(3.722005238041751))" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 19)" ] }, { "cell_type": "code", "execution_count": null, "id": "44e667ea-f9ed-4dc8-9ca1-5a90d62f7938", "metadata": {}, "outputs": [], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 20)" ] }, { "cell_type": "code", "execution_count": null, "id": "b01ff1c2-e6f8-42c5-9c54-a49cc168d5df", "metadata": {}, "outputs": [], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 21)" ] }, { "cell_type": "code", "execution_count": null, "id": "abfbabaf-7ffa-4f7d-b9f6-839fb143806d", "metadata": {}, "outputs": [], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 22)" ] }, { "cell_type": "code", "execution_count": null, "id": "bd7f0085-31fd-4bdc-bbc3-b52eb90e558d", "metadata": {}, "outputs": [], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 18)" ] }, { "cell_type": "code", "execution_count": null, "id": "7faa0ca2-9068-4248-8a1f-c718bae86eec", "metadata": {}, "outputs": [], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 23)" ] }, { "cell_type": "code", "execution_count": null, "id": "35b709b8-3327-4774-9a4e-3452dfa95085", "metadata": {}, "outputs": [], "source": [ "params_applier(RandomForestRegressor,random_state=42 ,n_jobs =-1,max_depth = 24)" ] }, { "cell_type": "code", "execution_count": null, "id": "058fb9c8-f9ed-4ad7-bdcd-5fdac2ef74cd", "metadata": {}, "outputs": [], "source": [ "model = RandomForestRegressor(random_state=42,n_jobs=-1 ,max_depth = 20).fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": null, "id": "12d76c0d-7a6f-442b-bf1f-e887c12185a7", "metadata": {}, "outputs": [], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": null, "id": "642a18de-8151-4a30-b68a-340518bc7e67", "metadata": {}, "outputs": [], "source": [ "predict_and_submit(model,test_inputs,'./submissions/random_forest_submission.csv')" ] }, { "cell_type": "markdown", "id": "0227e708-d691-4fa4-a110-5548945f2272", "metadata": {}, "source": [ "### Model 3 : GBM(Gradient Boosting Machine)" ] }, { "cell_type": "code", "execution_count": 88, "id": "93f7d101-10da-4d79-afb1-1d445a3cd735", "metadata": {}, "outputs": [], "source": [ "from xgboost import XGBRegressor" ] }, { "cell_type": "code", "execution_count": 90, "id": "22ff402b-765b-49d2-9403-74b3af3955ad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.567661, 4.820446, 24.02429 , ..., 12.95379 , 10.486221,\n", " 7.398918], dtype=float32),\n", " np.float64(2.311588829543463),\n", " array([ 7.282046 , 6.0706053, 8.413757 , ..., 5.2669835, 10.183635 ,\n", " 8.341952 ], dtype=float32),\n", " np.float64(3.698129624516502))" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.1, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3a361507-2051-4d01-9f7a-6447b26d492f", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.02, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "345a605b-effd-4f83-bee7-2bfed3e40756", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.03, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "b27a998a-2d31-4259-be56-eeed22a637de", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.04, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "34e91201-a3e3-4e94-a6bb-218874e43d5f", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.05, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a60e7e6b-5c69-4156-926e-644fbb9483db", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.06, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2893799f-b186-4b60-9c0f-aecf71bdcb8e", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.07, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "bbc68115-9eab-4645-b5ef-fdfc2cdbdc0d", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.08, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "757d30d0-f4c5-4491-bc19-a8e2e9c81e9e", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=0.09, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " subsample=0.8, # random rows for each tree\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "5df4b5bf-0a92-4783-85c0-55bdf1aa0493", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " n_estimators=500, # many trees, but we’ll use early stopping\n", " learning_rate=1, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " subsample=0.8, # random rows for each tree\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": 91, "id": "acfb0c05-ddad-4c08-a106-1bcff4f5e83b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([18.064085 , 4.9267673, 24.552856 , ..., 12.997943 , 10.359231 ,\n", " 7.601675 ], dtype=float32),\n", " np.float64(2.2264792978903545),\n", " array([7.2461348, 5.805906 , 8.681773 , ..., 5.4522758, 9.944087 ,\n", " 8.325776 ], dtype=float32),\n", " np.float64(3.641137737792094))" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " eval_metric='rmse',\n", " tree_method='hist', # fast, memory-efficient\n", " n_estimators=4000, # many trees, but we’ll use early stopping\n", " learning_rate=0.02, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " min_child_weight=6, # avoid overfitting\n", " subsample=0.8, # random rows for each tree\n", " colsample_bytree=0.8, # random columns for each tree\n", " gamma=0.2, # pruning parameter, reduces noise\n", " reg_alpha=0.5, # L1 regularization (feature selection)\n", " reg_lambda=1.2, # L2 regularization (reduces overfit)\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", " )" ] }, { "cell_type": "code", "execution_count": 92, "id": "f7848b32-6b1a-4ecc-8d53-b075499f3541", "metadata": {}, "outputs": [], "source": [ "\n", "model = XGBRegressor(\n", " objective='reg:squarederror',\n", " eval_metric='rmse',\n", " tree_method='hist', # fast, memory-efficient\n", " n_estimators=4000, # many trees, but we’ll use early stopping\n", " learning_rate=0.02, # small step for smoother learning\n", " max_depth=8, # balanced complexity\n", " min_child_weight=6, # avoid overfitting\n", " subsample=0.8, # random rows for each tree\n", " colsample_bytree=0.8, # random columns for each tree\n", " gamma=0.2, # pruning parameter, reduces noise\n", " reg_alpha=0.5, # L1 regularization (feature selection)\n", " reg_lambda=1.2, # L2 regularization (reduces overfit)\n", " n_jobs=-1, # use all CPU cores\n", " random_state=42\n", ")\n" ] }, { "cell_type": "code", "execution_count": 93, "id": "cfe6a573-fb67-40d8-ba3b-7baf2d21ebde", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
XGBRegressor(base_score=None, booster=None, callbacks=None,\n",
       "             colsample_bylevel=None, colsample_bynode=None,\n",
       "             colsample_bytree=0.8, device=None, early_stopping_rounds=None,\n",
       "             enable_categorical=False, eval_metric='rmse', feature_types=None,\n",
       "             feature_weights=None, gamma=0.2, grow_policy=None,\n",
       "             importance_type=None, interaction_constraints=None,\n",
       "             learning_rate=0.02, max_bin=None, max_cat_threshold=None,\n",
       "             max_cat_to_onehot=None, max_delta_step=None, max_depth=8,\n",
       "             max_leaves=None, min_child_weight=6, missing=nan,\n",
       "             monotone_constraints=None, multi_strategy=None, n_estimators=4000,\n",
       "             n_jobs=-1, num_parallel_tree=None, ...)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "XGBRegressor(base_score=None, booster=None, callbacks=None,\n", " colsample_bylevel=None, colsample_bynode=None,\n", " colsample_bytree=0.8, device=None, early_stopping_rounds=None,\n", " enable_categorical=False, eval_metric='rmse', feature_types=None,\n", " feature_weights=None, gamma=0.2, grow_policy=None,\n", " importance_type=None, interaction_constraints=None,\n", " learning_rate=0.02, max_bin=None, max_cat_threshold=None,\n", " max_cat_to_onehot=None, max_delta_step=None, max_depth=8,\n", " max_leaves=None, min_child_weight=6, missing=nan,\n", " monotone_constraints=None, multi_strategy=None, n_estimators=4000,\n", " n_jobs=-1, num_parallel_tree=None, ...)" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 94, "id": "7943b050-a0d8-4564-be45-d0d17d43793e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.266763
12015-01-27 13:08:24.000000311.007244
22011-10-08 11:53:44.00000024.400728
32012-12-01 21:12:12.00000028.995536
42012-12-01 21:12:12.000000316.094498
.........
99092015-05-10 12:37:51.00000029.485765
99102015-01-12 17:05:51.000000111.701119
99112015-04-19 20:44:15.000000154.602818
99122015-01-31 01:05:19.000000518.712271
99132015-01-18 14:06:23.00000066.980755
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.266763\n", "1 2015-01-27 13:08:24.0000003 11.007244\n", "2 2011-10-08 11:53:44.0000002 4.400728\n", "3 2012-12-01 21:12:12.0000002 8.995536\n", "4 2012-12-01 21:12:12.0000003 16.094498\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 9.485765\n", "9910 2015-01-12 17:05:51.0000001 11.701119\n", "9911 2015-04-19 20:44:15.0000001 54.602818\n", "9912 2015-01-31 01:05:19.0000005 18.712271\n", "9913 2015-01-18 14:06:23.0000006 6.980755\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model,test_inputs,'./submissions/xgboost_submission.csv')" ] }, { "cell_type": "markdown", "id": "5c2c12d1-6ded-48ef-98a4-9bd6a8d6d0f8", "metadata": {}, "source": [ "### Model 4 : Lasso" ] }, { "cell_type": "code", "execution_count": 95, "id": "a0e1f07c-d68c-4066-9db3-4d55fb0b4cde", "metadata": {}, "outputs": [], "source": [ "from sklearn.linear_model import Lasso" ] }, { "cell_type": "markdown", "id": "ceed9df5-2b93-4e8b-9d10-57a578439673", "metadata": {}, "source": [ "#### model testing" ] }, { "cell_type": "code", "execution_count": null, "id": "7b7f9aea-4472-4531-9f7f-9ded937d9282", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42)" ] }, { "cell_type": "code", "execution_count": null, "id": "167a7c31-e6d1-4a19-9f3f-6891199fb314", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.1)" ] }, { "cell_type": "code", "execution_count": null, "id": "5d20b818-28a3-476f-a28c-108535c28bc8", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.02)" ] }, { "cell_type": "code", "execution_count": null, "id": "652b6109-0aab-4ea8-ba3c-6b781d25009f", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.03)" ] }, { "cell_type": "code", "execution_count": null, "id": "df7edda3-39bf-4f3c-8afc-962f1a8b640e", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.04)" ] }, { "cell_type": "code", "execution_count": null, "id": "389df387-70e9-42b2-b64d-d7694fb901d8", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.05)" ] }, { "cell_type": "code", "execution_count": null, "id": "d1a8132b-0d76-48a1-8129-32f15361e393", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.06)" ] }, { "cell_type": "code", "execution_count": null, "id": "827928da-bce7-4c88-aed5-cd92d20b2d19", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.07)" ] }, { "cell_type": "code", "execution_count": null, "id": "af1b269f-7a22-4bb4-b04d-a9cc3096dd4d", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.08)" ] }, { "cell_type": "code", "execution_count": null, "id": "4ed96bc1-4f39-40ae-9193-8984c961c302", "metadata": {}, "outputs": [], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.09)" ] }, { "cell_type": "code", "execution_count": 97, "id": "184aa1c6-0c63-4889-a776-370a8c0c1e9c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([14.1664275 , 4.87547865, 20.57409508, ..., 10.20023428,\n", " 9.0744549 , 8.84762177]),\n", " np.float64(5.241563368057679),\n", " array([ 6.15215026, 6.05087325, 12.21088332, ..., 5.25300044,\n", " 9.0400371 , 8.73151714]),\n", " np.float64(4.859581797861735))" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(Lasso,random_state =42,alpha = 0.01)" ] }, { "cell_type": "code", "execution_count": 98, "id": "fabe02ba-083d-48c4-a712-2e923778f165", "metadata": {}, "outputs": [], "source": [ "model= Lasso(random_state =42,alpha = 0.01)" ] }, { "cell_type": "code", "execution_count": 99, "id": "83d4474c-717f-4a9e-b772-6fbc85e8da46", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Lasso(alpha=0.01, random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "Lasso(alpha=0.01, random_state=42)" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 100, "id": "b47e5634-b68b-448e-8c86-2ad633ce3e7e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.263045
12015-01-27 13:08:24.000000311.024202
22011-10-08 11:53:44.00000025.343182
32012-12-01 21:12:12.00000028.888580
42012-12-01 21:12:12.000000315.063936
.........
99092015-05-10 12:37:51.00000029.545672
99102015-01-12 17:05:51.000000111.658337
99112015-04-19 20:44:15.000000148.470643
99122015-01-31 01:05:19.000000522.541895
99132015-01-18 14:06:23.00000068.872193
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.263045\n", "1 2015-01-27 13:08:24.0000003 11.024202\n", "2 2011-10-08 11:53:44.0000002 5.343182\n", "3 2012-12-01 21:12:12.0000002 8.888580\n", "4 2012-12-01 21:12:12.0000003 15.063936\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 9.545672\n", "9910 2015-01-12 17:05:51.0000001 11.658337\n", "9911 2015-04-19 20:44:15.0000001 48.470643\n", "9912 2015-01-31 01:05:19.0000005 22.541895\n", "9913 2015-01-18 14:06:23.0000006 8.872193\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model , test_inputs,'./submissions/lasso_submission.csv')" ] }, { "cell_type": "markdown", "id": "7e864739-fa6a-43df-9d8f-6e78fc97e258", "metadata": {}, "source": [ "### Model 5 : Linear Regression" ] }, { "cell_type": "code", "execution_count": 101, "id": "75642fe8-3297-4fca-b95b-f992f43ed2ee", "metadata": {}, "outputs": [], "source": [ "from sklearn.linear_model import LinearRegression" ] }, { "cell_type": "code", "execution_count": 102, "id": "5d05a951-d900-48ab-bb02-2ab60de76629", "metadata": {}, "outputs": [], "source": [ "model = LinearRegression(n_jobs=-1)" ] }, { "cell_type": "code", "execution_count": 103, "id": "a5e17b4c-fbed-4991-ae38-825eeeeba596", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
LinearRegression(n_jobs=-1)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "LinearRegression(n_jobs=-1)" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 104, "id": "f007bf8e-001e-4faf-8d2a-b5224f3984b5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88105453, 4.84747705, 20.80221742, ..., 9.84156059,\n", " 9.17248384, 8.71166125]),\n", " np.float64(5.21272753306564),\n", " array([ 6.12791575, 5.80690178, 12.71319517, ..., 5.5690196 ,\n", " 9.35446076, 9.10487566]),\n", " np.float64(4.844510212174774))" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(LinearRegression,n_jobs = -1)" ] }, { "cell_type": "markdown", "id": "ba25b48a-b4b6-4cad-b33d-92e4d8dbc9c2", "metadata": {}, "source": [ "##### we can clearly see that even after small amount of feature engineering we created a major diffrence in the accuracy of the model" ] }, { "cell_type": "code", "execution_count": 105, "id": "c7be685f-4bb8-4b0e-991a-abb118e9cf27", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.064925
12015-01-27 13:08:24.000000311.511247
22011-10-08 11:53:44.00000025.384524
32012-12-01 21:12:12.00000028.663195
42012-12-01 21:12:12.000000314.294987
.........
99092015-05-10 12:37:51.00000028.944990
99102015-01-12 17:05:51.000000111.095755
99112015-04-19 20:44:15.000000147.559781
99122015-01-31 01:05:19.000000522.633088
99132015-01-18 14:06:23.00000069.032454
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.064925\n", "1 2015-01-27 13:08:24.0000003 11.511247\n", "2 2011-10-08 11:53:44.0000002 5.384524\n", "3 2012-12-01 21:12:12.0000002 8.663195\n", "4 2012-12-01 21:12:12.0000003 14.294987\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 8.944990\n", "9910 2015-01-12 17:05:51.0000001 11.095755\n", "9911 2015-04-19 20:44:15.0000001 47.559781\n", "9912 2015-01-31 01:05:19.0000005 22.633088\n", "9913 2015-01-18 14:06:23.0000006 9.032454\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model,test_inputs,'./submissions/linear_regression_scaled.csv')" ] }, { "cell_type": "markdown", "id": "7f0b18d1-c78a-42c6-a660-72cc8a83d86a", "metadata": {}, "source": [ "lets check the model accuracy on competition" ] }, { "cell_type": "markdown", "id": "9a9baad9-2552-4dcd-9233-d3b4b818c222", "metadata": {}, "source": [ "### Let do scaling as some model may perform better with scaled data" ] }, { "cell_type": "code", "execution_count": 106, "id": "a6efc65e-a2cf-4b89-8fda-072d9a23c4f0", "metadata": {}, "outputs": [], "source": [ "scaler = StandardScaler()" ] }, { "cell_type": "code", "execution_count": 108, "id": "4c0763aa-cbe1-46f6-a510-d9b0166dd7f5", "metadata": {}, "outputs": [], "source": [ "train_inputs1 = scaler.fit_transform(train_inputs)\n", "val_inputs1 = scaler.transform(val_inputs)\n", "test_inputs1 = scaler.transform(test_inputs)" ] }, { "cell_type": "code", "execution_count": 109, "id": "e7e06b9d-eb3d-460a-9a29-457d88bbd79f", "metadata": {}, "outputs": [], "source": [ "def params_applier1(model,**params):\n", " model = model(**params)\n", " model.fit(train_inputs1,train_target)\n", " train_pred = model.predict(train_inputs1)\n", " train_rmse = np.sqrt(mean_squared_error(train_target,train_pred))\n", " val_pred = model.predict(val_inputs1)\n", " val_rmse = np.sqrt(mean_squared_error(val_pred,val_target))\n", " return train_pred,train_rmse,val_pred,val_rmse" ] }, { "cell_type": "markdown", "id": "6278b3b5-6dbf-4400-808c-84aecdd7d4f2", "metadata": {}, "source": [ "### Model 6 : Ridge Regression (scaled)" ] }, { "cell_type": "code", "execution_count": 110, "id": "600bedd8-d7c8-45e0-ace5-0a4403663b89", "metadata": {}, "outputs": [], "source": [ "from sklearn.linear_model import Ridge" ] }, { "cell_type": "code", "execution_count": 111, "id": "99d73de6-3c64-4f17-b4f4-96ef3620dd76", "metadata": {}, "outputs": [], "source": [ "model = Ridge(random_state=42)" ] }, { "cell_type": "code", "execution_count": 112, "id": "71ca7e36-ad6b-4575-88cf-f2ab49ad67c9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Ridge(random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "Ridge(random_state=42)" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs1,train_target)" ] }, { "cell_type": "code", "execution_count": 113, "id": "30463315-acbe-4816-b7d9-784808268ac9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88106817, 4.84750549, 20.80219489, ..., 9.84161182,\n", " 9.17247872, 8.71166593]),\n", " np.float64(5.2127275339338315),\n", " array([ 6.12798161, 5.8068803 , 12.71316717, ..., 5.56902565,\n", " 9.35451934, 9.1048808 ]),\n", " np.float64(4.844510651280792))" ] }, "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier1(Ridge,random_state = 42,alpha =0.9)" ] }, { "cell_type": "code", "execution_count": 114, "id": "2ad6bd7a-95f8-4dee-ae35-5a1c5fe71d3b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88106968, 4.84750865, 20.80219239, ..., 9.84161751,\n", " 9.17247815, 8.71166645]),\n", " np.float64(5.212727534137456),\n", " array([ 6.12798893, 5.80687791, 12.71316406, ..., 5.56902632,\n", " 9.35452585, 9.10488137]),\n", " np.float64(4.844510700172296))" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier1(Ridge,random_state = 42,alpha =1)" ] }, { "cell_type": "code", "execution_count": 115, "id": "2a46cf09-f94a-40a7-931a-9f30a5c126c9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([13.88106665, 4.84750233, 20.8021974 , ..., 9.84160613,\n", " 9.17247929, 8.71166541]),\n", " np.float64(5.212727533751635),\n", " array([ 6.1279743 , 5.80688268, 12.71317028, ..., 5.56902498,\n", " 9.35451283, 9.10488023]),\n", " np.float64(4.844510602409672))" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier1(Ridge,random_state = 42,alpha =0.8)" ] }, { "cell_type": "code", "execution_count": 116, "id": "526361e1-f88e-4da6-938f-5a81ba56a4e9", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(array([13.88106514, 4.84749917, 20.8021999 , ..., 9.84160044,\n", " 9.17247986, 8.71166489]),\n", " np.float64(5.212727533590868),\n", " array([ 6.12796698, 5.80688507, 12.71317339, ..., 5.56902431,\n", " 9.35450632, 9.10487966]),\n", " np.float64(4.84451055355894))" ] }, "execution_count": 116, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier1(Ridge,random_state = 42,alpha =0.7)" ] }, { "cell_type": "code", "execution_count": 117, "id": "b03c09af-1a52-4acb-afb8-86a9d2277ae9", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.064949
12015-01-27 13:08:24.000000311.511232
22011-10-08 11:53:44.00000025.384549
32012-12-01 21:12:12.00000028.663182
42012-12-01 21:12:12.000000314.295001
.........
99092015-05-10 12:37:51.00000028.945018
99102015-01-12 17:05:51.000000111.095790
99112015-04-19 20:44:15.000000147.559758
99122015-01-31 01:05:19.000000522.633054
99132015-01-18 14:06:23.00000069.032389
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.064949\n", "1 2015-01-27 13:08:24.0000003 11.511232\n", "2 2011-10-08 11:53:44.0000002 5.384549\n", "3 2012-12-01 21:12:12.0000002 8.663182\n", "4 2012-12-01 21:12:12.0000003 14.295001\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 8.945018\n", "9910 2015-01-12 17:05:51.0000001 11.095790\n", "9911 2015-04-19 20:44:15.0000001 47.559758\n", "9912 2015-01-31 01:05:19.0000005 22.633054\n", "9913 2015-01-18 14:06:23.0000006 9.032389\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model,test_inputs1,'./submissions/ridge_scaled_submission.csv')" ] }, { "cell_type": "markdown", "id": "c365e0eb-17f1-4d88-b38e-b47d5de23cb4", "metadata": {}, "source": [ "#### we can clearly see that the scling of data is not creating a major impact" ] }, { "cell_type": "markdown", "id": "d737b23c-9932-4228-8a5e-de055ca6d977", "metadata": {}, "source": [ "### Model 7 : SVM(support vector machine)" ] }, { "cell_type": "code", "execution_count": null, "id": "d0a2bc36-b825-48be-a8c9-68407168e1e1", "metadata": {}, "outputs": [], "source": [ "from sklearn.svm import SVR" ] }, { "cell_type": "code", "execution_count": null, "id": "6877622e-0179-406b-8a9d-73be87408c13", "metadata": {}, "outputs": [], "source": [ "?SVR" ] }, { "cell_type": "code", "execution_count": null, "id": "c4112823-318d-4803-adba-93495ac513c1", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "5cd229d4-2101-4de7-9493-b98ecaefbf73", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.9)" ] }, { "cell_type": "code", "execution_count": null, "id": "6129fe5a-b4ad-42a2-a496-42b6280c8dcb", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.8)" ] }, { "cell_type": "code", "execution_count": null, "id": "a9b55824-c40e-4bbf-85aa-e95440e63fba", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.7)" ] }, { "cell_type": "code", "execution_count": null, "id": "f6ad9cb4-2221-4128-a92d-2e47505a43d1", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.6)" ] }, { "cell_type": "code", "execution_count": null, "id": "e411d89f-c977-4700-b270-5aaf2ef3b3ee", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.5)" ] }, { "cell_type": "code", "execution_count": null, "id": "bf070e60-09ca-4323-98a1-fa9a38a32525", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.4)" ] }, { "cell_type": "code", "execution_count": null, "id": "3b528494-2b5e-4bdd-b4dc-b8b42596951c", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.3)" ] }, { "cell_type": "code", "execution_count": null, "id": "cda415c6-e31e-474c-a96c-2198aaf021de", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.2)" ] }, { "cell_type": "code", "execution_count": null, "id": "5c891f4a-ec81-4c6c-98b8-80a9e8857300", "metadata": {}, "outputs": [], "source": [ "params_applier1(SVR,C=0.1)" ] }, { "cell_type": "markdown", "id": "201ab5bf-2e55-44af-ae0a-4f82d591e829", "metadata": {}, "source": [ "#### it can take hours for training and hyper parameter tuning So I am not determining its accuracy as it is not useful in the practical world" ] }, { "cell_type": "markdown", "id": "caf93974-a543-4d03-b5b5-a96137a819b1", "metadata": {}, "source": [ "### Model 8 :KNN(K-nearest neighbour)" ] }, { "cell_type": "code", "execution_count": 118, "id": "a3311899-ce20-4a93-ac88-025183bacbeb", "metadata": {}, "outputs": [], "source": [ "from sklearn.neighbors import KNeighborsRegressor" ] }, { "cell_type": "code", "execution_count": 120, "id": "87b3f15e-ff5d-490d-b106-9a3c5371b861", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.499999 , 5.30000048, 25.49999543, ..., 15. ,\n", " 9.99999962, 7.50000037]),\n", " np.float64(0.005609084456829864),\n", " array([ 6.2475106 , 5.28889147, 8.45238627, ..., 10.13461903,\n", " 8.60321693, 7.9102166 ]),\n", " np.float64(4.092856441820566))" ] }, "execution_count": 120, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier1(KNeighborsRegressor,n_jobs =-1 ,weights = 'distance',n_neighbors = 10)" ] }, { "cell_type": "code", "execution_count": null, "id": "e78bf77a-e2de-4d51-bffb-ca46a1c2a0b1", "metadata": {}, "outputs": [], "source": [ "params_applier1(KNeighborsRegressor,n_jobs=-1,weights = 'distance',n_neighbors = 9)" ] }, { "cell_type": "code", "execution_count": null, "id": "492740c2-cca1-4b8c-8aa0-0760505a84e6", "metadata": {}, "outputs": [], "source": [ "params_applier1(KNeighborsRegressor,n_jobs=-1,weights = 'distance',n_neighbors = 7)" ] }, { "cell_type": "code", "execution_count": null, "id": "a79fdb94-2c26-418d-98c1-15bb2064bcf5", "metadata": {}, "outputs": [], "source": [ "params_applier1(KNeighborsRegressor,n_jobs=-1,weights = 'distance',n_neighbors = 8)" ] }, { "cell_type": "code", "execution_count": null, "id": "407210ca-5234-4b99-9e0f-8ce4eb2506a8", "metadata": {}, "outputs": [], "source": [ "params_applier1(KNeighborsRegressor,n_jobs=-1,weights = 'distance',n_neighbors = 3)" ] }, { "cell_type": "code", "execution_count": 121, "id": "813f4109-9f64-455d-9164-dec3540e56d5", "metadata": {}, "outputs": [], "source": [ "model = KNeighborsRegressor(n_jobs=-1,weights = 'distance',n_neighbors = 10)" ] }, { "cell_type": "code", "execution_count": 122, "id": "aebd5705-c099-4158-8509-d0475d6d9276", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
KNeighborsRegressor(n_jobs=-1, n_neighbors=10, weights='distance')
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "KNeighborsRegressor(n_jobs=-1, n_neighbors=10, weights='distance')" ] }, "execution_count": 122, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs1,train_target)" ] }, { "cell_type": "code", "execution_count": 123, "id": "7f76cc0b-15d7-4787-a659-b18a22e50653", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.00000029.557500
12015-01-27 13:08:24.00000038.713567
22011-10-08 11:53:44.00000025.619444
32012-12-01 21:12:12.00000027.585304
42012-12-01 21:12:12.000000314.228388
.........
99092015-05-10 12:37:51.00000026.925133
99102015-01-12 17:05:51.00000018.208483
99112015-04-19 20:44:15.000000159.604628
99122015-01-31 01:05:19.000000517.131794
99132015-01-18 14:06:23.000000610.806133
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 9.557500\n", "1 2015-01-27 13:08:24.0000003 8.713567\n", "2 2011-10-08 11:53:44.0000002 5.619444\n", "3 2012-12-01 21:12:12.0000002 7.585304\n", "4 2012-12-01 21:12:12.0000003 14.228388\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 6.925133\n", "9910 2015-01-12 17:05:51.0000001 8.208483\n", "9911 2015-04-19 20:44:15.0000001 59.604628\n", "9912 2015-01-31 01:05:19.0000005 17.131794\n", "9913 2015-01-18 14:06:23.0000006 10.806133\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model,test_inputs1,'./submissions/knn_submission.csv')" ] }, { "cell_type": "markdown", "id": "c205cf34-f425-4b85-88dd-a0b379884637", "metadata": {}, "source": [ "#### we scored 3.70245 in test score" ] }, { "cell_type": "markdown", "id": "6774d326-4303-4f78-89da-7b2dc010f780", "metadata": {}, "source": [ "we found that our model is performing pretty well on K-nearest neighbour" ] }, { "cell_type": "markdown", "id": "4d187dc5-eed7-48be-a05e-c4de0a5f9ac0", "metadata": {}, "source": [ "### At the end we can clearly see that the best working model on the test set is XGBoost model.So from now we will be working on the hyperparameter tuning for the xgboost model to gain max accuracy" ] }, { "cell_type": "markdown", "id": "23293e38-7df1-4b22-a293-221d4f774ef2", "metadata": {}, "source": [ "# Step 9 : Hyperparameter Tuning of our Best Model\n", "##### we will go step by step and improve our model by adding hyperparameter step by step according to the importance and impacton the data step and at the end we will get our best model\n", "##### These will be our hyperparameter will be step by step --:\n", "- n_estimators\n", "- learning_rate\n", "- max_depth\n", "- min_child_weight\n", "- gamma\n", "- subsample\n", "- colsample_bytree\n", "- reg_alpha\n", "- reg_lambda" ] }, { "cell_type": "markdown", "id": "4141553c-e3a5-40ca-9ed4-0462544f1f06", "metadata": {}, "source": [ "### Now lets find the best model by fiding the best combination of our model" ] }, { "cell_type": "code", "execution_count": 124, "id": "17422093-463f-41ba-a134-043bc83fc7d2", "metadata": {}, "outputs": [], "source": [ "from xgboost import XGBRegressor" ] }, { "cell_type": "markdown", "id": "633e6dd1-7781-4069-9032-afcb49097b8d", "metadata": {}, "source": [ "#### We will write our best parameter in the model below" ] }, { "cell_type": "code", "execution_count": 126, "id": "e96e5757-3270-4a5d-9c25-85c172a45374", "metadata": {}, "outputs": [], "source": [ "model = XGBRegressor(\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'gbtree',\n", " tree_method = 'hist'\n", " )" ] }, { "cell_type": "markdown", "id": "3df1451c-ba54-4e0a-a119-1ab3eb43de7b", "metadata": {}, "source": [ "#### Parameter 1 : n_estimators\n", "##### we should fix a particlar no. of n estimator as later changes can create a issue with learning rate and may decrese the efficeincy\n", "##### I think 500 estimator would be enough as we have a large dataset" ] }, { "cell_type": "code", "execution_count": 127, "id": "961be157-ff34-4e19-8415-65003dd590d4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.607094 , 4.6113153, 23.883295 , ..., 13.214553 , 10.228402 ,\n", " 7.570654 ], dtype=float32),\n", " np.float64(2.454884378076267),\n", " array([7.4975257, 5.7112494, 8.271085 , ..., 5.6197248, 9.69781 ,\n", " 8.402278 ], dtype=float32),\n", " np.float64(3.840321073619539))" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500\n", " \n", " )" ] }, { "cell_type": "markdown", "id": "0e4afcc1-d453-4fab-a38a-3d0f194b7b11", "metadata": {}, "source": [ "#### Parameter 2 : Learning Rate \n", "##### Defination : Controls how much each tree contributes" ] }, { "cell_type": "code", "execution_count": 128, "id": "c65a6108-5685-4a49-bbac-285a9fed1708", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.278479 , 5.012647 , 23.596752 , ..., 12.810253 , 10.2411995,\n", " 7.6393433], dtype=float32),\n", " np.float64(3.1633162760567783),\n", " array([ 7.0798635, 6.350174 , 8.583187 , ..., 5.153224 , 10.207847 ,\n", " 8.295157 ], dtype=float32),\n", " np.float64(3.6704700135737975))" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "45b78c04-92f6-4446-a520-524a534b6bd7", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.059\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "e23297a2-5a5f-452e-bac0-5066b383a168", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.08\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "30ab8c72-9b4f-4d3e-baf8-b8b420af33e6", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.04\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "741cbbcb-d528-42a2-bbe4-52cd6e4f0dde", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.05\n", " )" ] }, { "cell_type": "markdown", "id": "3930f3de-3f80-4b90-9400-76ad874b86cc", "metadata": {}, "source": [ "##### our best learning rate turn out to be 0.06" ] }, { "cell_type": "markdown", "id": "6561e8f1-f935-407f-960e-89e3a988eefa", "metadata": {}, "source": [ "#### Parameter 3 : Max Depth\n", "##### → Depth of each tree. Controls model complexity." ] }, { "cell_type": "code", "execution_count": null, "id": "6e20973f-ef5e-49ae-afe5-0168b17905f5", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 4\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "49eede79-8c56-4cbf-99bb-60d8df1c00ed", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 5\n", " )" ] }, { "cell_type": "code", "execution_count": 129, "id": "eb59701c-d3e5-45be-b525-274ab6ab85dd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.278479 , 5.012647 , 23.596752 , ..., 12.810253 , 10.2411995,\n", " 7.6393433], dtype=float32),\n", " np.float64(3.1633162760567783),\n", " array([ 7.0798635, 6.350174 , 8.583187 , ..., 5.153224 , 10.207847 ,\n", " 8.295157 ], dtype=float32),\n", " np.float64(3.6704700135737975))" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6\n", " )" ] }, { "cell_type": "markdown", "id": "8742ce32-a8c3-4038-be88-39e7ade9593c", "metadata": {}, "source": [ "##### Our max_depth is perfect as default value which is 6" ] }, { "cell_type": "markdown", "id": "e55b22f5-c143-46fd-b9de-576eab4c293c", "metadata": {}, "source": [ "#### Parameter 4 : Min Child Weight\n", "##### → Minimum sum of instance weight (hessian) needed in a child.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "302f72e9-cea8-4afd-86b3-21151f4fb624", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 25\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "ef688422-82b3-4396-b8ac-f86988d9ef49", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 26\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "db658a1f-f220-4ca9-96d4-d102d603012a", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 27\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "ef0a9ffd-092b-44eb-8cab-c8e521915637", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 28\n", " )" ] }, { "cell_type": "code", "execution_count": 130, "id": "aa6e3f47-09d7-4cae-a38e-727517299776", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([17.036634 , 5.040554 , 23.412882 , ..., 12.67248 , 10.125301 ,\n", " 7.6132674], dtype=float32),\n", " np.float64(3.40904163440582),\n", " array([ 7.261657, 6.528111, 8.74254 , ..., 5.294597, 10.013864,\n", " 8.4293 ], dtype=float32),\n", " np.float64(3.643364657249642))" ] }, "execution_count": 130, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20\n", " )" ] }, { "cell_type": "markdown", "id": "3a9af988-be12-4961-8d89-d5b29e3d4863", "metadata": {}, "source": [ "##### After a lot of tuning best hyperparameter for min_child_weight is 20" ] }, { "cell_type": "markdown", "id": "7232cf35-1e86-4158-bf86-0356d69a13f2", "metadata": {}, "source": [ "#### Parameter 5 : Gamma\n", "##### → Minimum loss reduction required to make a split." ] }, { "cell_type": "code", "execution_count": null, "id": "dfe33612-871a-4ad0-8142-4b9056771f8b", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 14\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "a4ef4300-b674-450e-82b4-2fc71b61874a", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 15\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "16c08d69-8078-4984-8fbf-c48d968e6de9", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 16\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "7cabc0a0-940a-4bed-b568-bdd915114fca", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1\n", " )" ] }, { "cell_type": "markdown", "id": "b8a05fc0-9ec6-4ae7-94d8-02b067165d0a", "metadata": {}, "source": [ "##### Gamma is not able to make a impact on the model as min child weight is too high" ] }, { "cell_type": "markdown", "id": "f72976ff-3a4a-4a6f-a0c4-31ff9da06f3f", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "##### And on the incresing gamma it is negetively impacting the model" ] }, { "cell_type": "markdown", "id": "99514ef1-2abe-4338-9089-c893a5e0c463", "metadata": {}, "source": [ "#### Parameter 6 : Subsample\n", "##### → Control randomness in sampling data and features." ] }, { "cell_type": "code", "execution_count": null, "id": "595b3bee-c740-4c7f-98e7-3643724cdb6e", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "0743caf1-0dcc-4e9a-9ad0-34edbbad276f", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "7807b6e1-75bc-41fb-8f66-deab0c194372", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 0.4\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "8bacd51c-1859-4fed-9c82-8cbef19d0662", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 0.3\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "553c35b5-2a58-4547-aab0-38be6ba614d8", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 0.2\n", " )" ] }, { "cell_type": "markdown", "id": "53cd32c7-177f-4f75-89f7-8b7d791c1350", "metadata": {}, "source": [ "##### Subsample is not creating a impact as the dataset is too large and don't need any randomness" ] }, { "cell_type": "markdown", "id": "93c3f37a-0b6d-4966-a9d6-79e49bd35bed", "metadata": {}, "source": [ "#### Parameter 7 : colsample_bytree" ] }, { "cell_type": "code", "execution_count": 131, "id": "cda43b66-3c21-4910-8e2c-e22bc1f6f0f9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([16.986835 , 4.9570074, 23.526522 , ..., 12.459195 , 10.060337 ,\n", " 7.835018 ], dtype=float32),\n", " np.float64(3.461781005024091),\n", " array([ 7.1247945, 6.6203218, 8.315928 , ..., 5.2654314, 10.024519 ,\n", " 8.4302025], dtype=float32),\n", " np.float64(3.6304159811973618))" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "39fa2386-913c-46d4-82fd-77b7860e8ecb", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.59\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "ecec9487-ffe4-49d5-8b3e-ac002ede2ddd", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.61\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "10e87d8f-2b5d-4ac8-b02a-a70aaafd3512", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.3\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "ea25872d-5e20-496d-a0af-794adac9ce61", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " )" ] }, { "cell_type": "markdown", "id": "e79fe61a-dbde-4e9e-8049-02c836f00005", "metadata": {}, "source": [ "##### There is a good improvement in the model at the value of 0.6" ] }, { "cell_type": "markdown", "id": "4f09c43d-9e44-4c4a-9488-a6c2e4eb4283", "metadata": {}, "source": [ "#### Parameter 8 : Regularization Parameters\n", "##### Help fight overfitting." ] }, { "cell_type": "code", "execution_count": null, "id": "a4ec3cb7-6525-433a-bf0e-254fa592c4b9", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " reg_alpha =0.01\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "cc29567d-085f-4676-ae65-68ce2b1ac385", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " reg_alpha =0.4\n", " )" ] }, { "cell_type": "code", "execution_count": null, "id": "ec733b9d-c4e3-4495-b50f-5ac6e3675d89", "metadata": { "scrolled": true }, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " )" ] }, { "cell_type": "markdown", "id": "875fd7e9-f9b4-4a82-9b42-c1f060168721", "metadata": {}, "source": [ "#### Parameter 9 : Booster and Tree Method" ] }, { "cell_type": "markdown", "id": "b97eebe2-2be0-4aab-a892-861207827380", "metadata": {}, "source": [ "##### not creating a major impact" ] }, { "cell_type": "code", "execution_count": 132, "id": "ede9ca8e-fda7-4287-b4d4-9e7f61ab4c20", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(array([16.986835 , 4.9570074, 23.526522 , ..., 12.459195 , 10.060337 ,\n", " 7.835018 ], dtype=float32),\n", " np.float64(3.461781005024091),\n", " array([ 7.1247945, 6.6203218, 8.315928 , ..., 5.2654314, 10.024519 ,\n", " 8.4302025], dtype=float32),\n", " np.float64(3.6304159811973618))" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'gbtree'\n", " )" ] }, { "cell_type": "markdown", "id": "806d8846-a638-4046-8307-91c3c5910853", "metadata": {}, "source": [ "##### don't use dart as it is very slow in working with large dataset" ] }, { "cell_type": "code", "execution_count": null, "id": "f184e80b-7605-4216-930d-9878e08fac78", "metadata": {}, "outputs": [], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'dart'\n", " )" ] }, { "cell_type": "markdown", "id": "1b866706-660a-4bf8-9fd0-109cf0c005a3", "metadata": {}, "source": [ "##### dart should be used a dataset less then one lakh dataset" ] }, { "cell_type": "markdown", "id": "461b4357-eb95-4684-987e-01c796f1a33b", "metadata": {}, "source": [ "#### Parameter 10 : tree_method\n", "##### for faster training on large data" ] }, { "cell_type": "code", "execution_count": 133, "id": "41426772-1cac-4461-8349-6b030d11900a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([16.986835 , 4.9570074, 23.526522 , ..., 12.459195 , 10.060337 ,\n", " 7.835018 ], dtype=float32),\n", " np.float64(3.461781005024091),\n", " array([ 7.1247945, 6.6203218, 8.315928 , ..., 5.2654314, 10.024519 ,\n", " 8.4302025], dtype=float32),\n", " np.float64(3.6304159811973618))" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'gbtree',\n", " tree_method = 'hist'\n", " )" ] }, { "cell_type": "markdown", "id": "5e19f2b5-8d68-4fd1-89aa-6a4e7189fbad", "metadata": {}, "source": [ "##### Now our model speed is faster by few second without any dataloss" ] }, { "cell_type": "markdown", "id": "cdd22176-a223-44c3-a4f3-29a94c030629", "metadata": {}, "source": [ "#### Now our best model is redy for prediction" ] }, { "cell_type": "code", "execution_count": 134, "id": "4bd375e6-1e35-4782-9212-c4b86beb3049", "metadata": {}, "outputs": [], "source": [ "model = XGBRegressor(\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'gbtree',\n", " tree_method = 'hist'\n", " )" ] }, { "cell_type": "code", "execution_count": 135, "id": "5caf6a24-0210-4a4c-ba60-5372ccb1fd3a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
XGBRegressor(base_score=None, booster='gbtree', callbacks=None,\n",
       "             colsample_bylevel=None, colsample_bynode=None,\n",
       "             colsample_bytree=0.6, device=None, early_stopping_rounds=None,\n",
       "             enable_categorical=False, eval_metric=None, feature_types=None,\n",
       "             feature_weights=None, gamma=0.1, grow_policy=None,\n",
       "             importance_type=None, interaction_constraints=None,\n",
       "             learning_rate=0.06, max_bin=None, max_cat_threshold=None,\n",
       "             max_cat_to_onehot=None, max_delta_step=None, max_depth=6,\n",
       "             max_leaves=None, min_child_weight=20, missing=nan,\n",
       "             monotone_constraints=None, multi_strategy=None, n_estimators=500,\n",
       "             n_jobs=-1, num_parallel_tree=None, ...)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "XGBRegressor(base_score=None, booster='gbtree', callbacks=None,\n", " colsample_bylevel=None, colsample_bynode=None,\n", " colsample_bytree=0.6, device=None, early_stopping_rounds=None,\n", " enable_categorical=False, eval_metric=None, feature_types=None,\n", " feature_weights=None, gamma=0.1, grow_policy=None,\n", " importance_type=None, interaction_constraints=None,\n", " learning_rate=0.06, max_bin=None, max_cat_threshold=None,\n", " max_cat_to_onehot=None, max_delta_step=None, max_depth=6,\n", " max_leaves=None, min_child_weight=20, missing=nan,\n", " monotone_constraints=None, multi_strategy=None, n_estimators=500,\n", " n_jobs=-1, num_parallel_tree=None, ...)" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.fit(train_inputs,train_target)" ] }, { "cell_type": "code", "execution_count": 136, "id": "ff37b5f8-d93a-4501-af1d-15c9becfae37", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.470364
12015-01-27 13:08:24.000000310.812552
22011-10-08 11:53:44.00000024.896918
32012-12-01 21:12:12.00000028.680733
42012-12-01 21:12:12.000000315.681168
.........
99092015-05-10 12:37:51.00000028.640362
99102015-01-12 17:05:51.000000113.162942
99112015-04-19 20:44:15.000000154.945484
99122015-01-31 01:05:19.000000520.186121
99132015-01-18 14:06:23.00000066.909365
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.470364\n", "1 2015-01-27 13:08:24.0000003 10.812552\n", "2 2011-10-08 11:53:44.0000002 4.896918\n", "3 2012-12-01 21:12:12.0000002 8.680733\n", "4 2012-12-01 21:12:12.0000003 15.681168\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 8.640362\n", "9910 2015-01-12 17:05:51.0000001 13.162942\n", "9911 2015-04-19 20:44:15.0000001 54.945484\n", "9912 2015-01-31 01:05:19.0000005 20.186121\n", "9913 2015-01-18 14:06:23.0000006 6.909365\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(model, test_inputs,'./submissions/xgboost2_submission.csv')" ] }, { "cell_type": "markdown", "id": "622b0254-5fb3-4e49-9110-954a513a07a9", "metadata": {}, "source": [ "### finally reached the rank of 476" ] }, { "cell_type": "markdown", "id": "ee5a8fc9-407a-45e6-9e67-1a7188816916", "metadata": {}, "source": [ "# Step 10 : Incresing the Size of Dataset\n", "### We will be taking 3 training dataset with\n", "- 3%\n", "- 10%\n", "- 100% - unable to do it as the my sistemis not capable\n", "##### of total dataset" ] }, { "cell_type": "markdown", "id": "e6b4d8df-509b-446c-8fb9-46480e5748df", "metadata": {}, "source": [ "## Loading of Data" ] }, { "cell_type": "markdown", "id": "2a66ad39-df12-4892-9a9e-edc5f91bff93", "metadata": {}, "source": [ "let's start with 3%" ] }, { "cell_type": "code", "execution_count": 137, "id": "f584dfb5-aa0f-44c0-806b-bc23c128922c", "metadata": {}, "outputs": [], "source": [ "sample3=0.03\n", "cols = 'fare_amount,pickup_datetime,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,passenger_count'.split(',')\n", "d_type = {\n", " 'fare_amount':'float32',\n", " 'pickup_longitude':'float32',\n", " 'pickup_latitude':'float32',\n", " 'dropoff_longitude':'float32',\n", " 'dropoff_latitude':'float32',\n", " 'passenger_count':'uint8'\n", "}\n", "def selected_row3(row_indx):\n", " if row_indx == 0:\n", " return False\n", " return random.random() > sample3 \n", "random.seed(43)#this will initialize by 42" ] }, { "cell_type": "code", "execution_count": 138, "id": "6020b802-7f39-4133-9be4-6e46d9435090", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: total: 1min 22s\n", "Wall time: 1min 25s\n" ] } ], "source": [ "%%time\n", "data3 = pd.read_csv('./train.csv',usecols=cols,dtype=d_type,skiprows=selected_row3,parse_dates=['pickup_datetime'])" ] }, { "cell_type": "markdown", "id": "570e9d4d-4a30-47c2-9216-ad0864f6c74b", "metadata": {}, "source": [ "This is for 10%" ] }, { "cell_type": "code", "execution_count": 139, "id": "bcc58bb7-ef65-4cd8-a758-4e65a572f79d", "metadata": {}, "outputs": [], "source": [ "sample10=0.1\n", "cols = 'fare_amount,pickup_datetime,pickup_longitude,pickup_latitude,dropoff_longitude,dropoff_latitude,passenger_count'.split(',')\n", "d_type = {\n", " 'fare_amount':'float32',\n", " 'pickup_longitude':'float32',\n", " 'pickup_latitude':'float32',\n", " 'dropoff_longitude':'float32',\n", " 'dropoff_latitude':'float32',\n", " 'passenger_count':'uint8'\n", "}\n", "def selected_row10(row_indx):\n", " if row_indx == 0:\n", " return False\n", " return random.random() > sample10 \n", "random.seed(43)#this will initialize by 42" ] }, { "cell_type": "code", "execution_count": 140, "id": "03df6492-4bcc-4be6-95f9-72ebb99a0591", "metadata": {}, "outputs": [], "source": [ "data10 = pd.read_csv('./train.csv',usecols=cols,dtype=d_type,skiprows=selected_row10,parse_dates=['pickup_datetime'])" ] }, { "cell_type": "markdown", "id": "1ba50d56-0920-4cdc-9e7d-4f76fc9d035d", "metadata": {}, "source": [ "This is for 100%" ] }, { "cell_type": "code", "execution_count": null, "id": "60d0cc36-09df-469e-b9a5-721844bf2b80", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "e40eeee0-a9de-4fb8-bf4e-cb82e9bc475b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "27530c21-b607-41d6-a812-aa0437f337e7", "metadata": {}, "outputs": [], "source": [ "data3" ] }, { "cell_type": "code", "execution_count": null, "id": "c03fa3d9-eb2b-4d45-8a91-fdbf40a8688a", "metadata": { "scrolled": true }, "outputs": [], "source": [ "data10" ] }, { "cell_type": "code", "execution_count": null, "id": "4f0d5580-2fba-4de5-a225-370224f6cf3e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "8a3d8c0f-c8da-4b20-91c5-8163d258fbe9", "metadata": {}, "source": [ "## Converting our datasets to parkuet_file for faster processing" ] }, { "cell_type": "code", "execution_count": 141, "id": "b981253f-6089-41d0-9bd8-0ee3a409906b", "metadata": {}, "outputs": [], "source": [ "data3.to_parquet('./parkuet_file/data3.parquet')\n", "data10.to_parquet('./parkuet_file/data10.parquet')\n" ] }, { "cell_type": "code", "execution_count": null, "id": "7074bb6d-e969-4140-af28-b69a1835aed3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 142, "id": "6f452a7c-c932-49c5-b8cd-1504a44d66c8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: total: 281 ms\n", "Wall time: 111 ms\n" ] } ], "source": [ "%%time\n", "data3 = pd.read_parquet('./parkuet_file/data3.parquet')" ] }, { "cell_type": "code", "execution_count": 143, "id": "49fa32bd-8b42-4939-94bf-f4992a9d2957", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: total: 1 s\n", "Wall time: 201 ms\n" ] } ], "source": [ "%%time\n", "data10 = pd.read_parquet('./parkuet_file/data10.parquet')" ] }, { "cell_type": "code", "execution_count": 144, "id": "604a9ff7-93cc-4329-8ecb-56e2bc26feb0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_count
04.52009-06-15 17:26:21+00:00-73.84431540.721317-73.84161440.7122761
19.02012-12-03 13:10:00+00:00-74.00646240.726711-73.99308040.7316281
24.02014-12-06 20:36:22+00:00-73.97981340.751904-73.97944640.7554821
34.52011-06-28 19:47:00+00:00-73.98889240.760159-73.98644340.7578583
49.32012-05-04 06:11:20+00:00-73.98925840.690834-74.00413540.7256891
........................
55404905.52012-10-19 09:25:00+00:00-73.95831340.773880-73.96010640.7661593
55404915.72010-11-18 07:08:58+00:00-73.99758940.735889-73.98455840.7540551
55404928.52011-04-23 19:22:50+00:00-73.99702540.752476-74.00404440.7224581
55404935.02015-05-17 00:27:40+00:00-73.97428940.761883-73.98296440.7561193
55404945.32009-06-03 20:16:35+00:00-73.97618940.748318-73.97968340.7576601
\n", "

5540495 rows × 7 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "0 4.5 2009-06-15 17:26:21+00:00 -73.844315 \n", "1 9.0 2012-12-03 13:10:00+00:00 -74.006462 \n", "2 4.0 2014-12-06 20:36:22+00:00 -73.979813 \n", "3 4.5 2011-06-28 19:47:00+00:00 -73.988892 \n", "4 9.3 2012-05-04 06:11:20+00:00 -73.989258 \n", "... ... ... ... \n", "5540490 5.5 2012-10-19 09:25:00+00:00 -73.958313 \n", "5540491 5.7 2010-11-18 07:08:58+00:00 -73.997589 \n", "5540492 8.5 2011-04-23 19:22:50+00:00 -73.997025 \n", "5540493 5.0 2015-05-17 00:27:40+00:00 -73.974289 \n", "5540494 5.3 2009-06-03 20:16:35+00:00 -73.976189 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude passenger_count \n", "0 40.721317 -73.841614 40.712276 1 \n", "1 40.726711 -73.993080 40.731628 1 \n", "2 40.751904 -73.979446 40.755482 1 \n", "3 40.760159 -73.986443 40.757858 3 \n", "4 40.690834 -74.004135 40.725689 1 \n", "... ... ... ... ... \n", "5540490 40.773880 -73.960106 40.766159 3 \n", "5540491 40.735889 -73.984558 40.754055 1 \n", "5540492 40.752476 -74.004044 40.722458 1 \n", "5540493 40.761883 -73.982964 40.756119 3 \n", "5540494 40.748318 -73.979683 40.757660 1 \n", "\n", "[5540495 rows x 7 columns]" ] }, "execution_count": 144, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data10" ] }, { "cell_type": "code", "execution_count": null, "id": "c9bb8d34-0007-4e8d-a9c2-5535e0b435d8", "metadata": { "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "b8bbeaa4-1857-4c6b-a0ca-e605b6df7819", "metadata": {}, "source": [ "## Doing Preprocessing and Feature Engineering that we did earlier" ] }, { "cell_type": "code", "execution_count": 145, "id": "3de6df9b-0378-4aaf-8a77-a208f15fe7db", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 1662240 entries, 0 to 1662239\n", "Data columns (total 7 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 fare_amount 1662240 non-null float32 \n", " 1 pickup_datetime 1662240 non-null datetime64[ns, UTC]\n", " 2 pickup_longitude 1662240 non-null float32 \n", " 3 pickup_latitude 1662240 non-null float32 \n", " 4 dropoff_longitude 1662227 non-null float32 \n", " 5 dropoff_latitude 1662227 non-null float32 \n", " 6 passenger_count 1662240 non-null uint8 \n", "dtypes: datetime64[ns, UTC](1), float32(5), uint8(1)\n", "memory usage: 46.0 MB\n" ] } ], "source": [ "data3.info()" ] }, { "cell_type": "code", "execution_count": 146, "id": "91078389-04df-4671-a042-db5d0bf24caa", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 5540495 entries, 0 to 5540494\n", "Data columns (total 7 columns):\n", " # Column Dtype \n", "--- ------ ----- \n", " 0 fare_amount float32 \n", " 1 pickup_datetime datetime64[ns, UTC]\n", " 2 pickup_longitude float32 \n", " 3 pickup_latitude float32 \n", " 4 dropoff_longitude float32 \n", " 5 dropoff_latitude float32 \n", " 6 passenger_count uint8 \n", "dtypes: datetime64[ns, UTC](1), float32(5), uint8(1)\n", "memory usage: 153.2 MB\n" ] } ], "source": [ "data10.info()" ] }, { "cell_type": "code", "execution_count": 147, "id": "5a24525a-0f73-4668-98e4-b469907a0eec", "metadata": {}, "outputs": [], "source": [ "data3=data3.dropna()\n", "data10 = data10.dropna()" ] }, { "cell_type": "code", "execution_count": 148, "id": "6a198cb1-98f5-4eab-b241-58e387181468", "metadata": {}, "outputs": [], "source": [ "inputs_cols = ['pickup_datetime','pickup_longitude', 'pickup_latitude','dropoff_longitude', 'dropoff_latitude', 'passenger_count']\n", "target_cols = 'fare_amount'" ] }, { "cell_type": "code", "execution_count": 149, "id": "041d7841-6b90-4e19-bb00-fb807b61e652", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "code", "execution_count": 150, "id": "46c92e12-4779-4e44-a278-e05a678b7954", "metadata": {}, "outputs": [], "source": [ "train_data3 ,val_data3 = train_test_split(data3,test_size=0.2,random_state=42)\n", "train_data10 ,val_data10 = train_test_split(data10,test_size=0.2,random_state=42)" ] }, { "cell_type": "code", "execution_count": 151, "id": "9e0a0d07-463d-43e9-9ce6-6aa3d833530b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "' \\nCalculate the great circle distance between two points\\non the earth (specified in decimal degrees)\\nAll args must be of equal length.\\n\\n'" ] }, "execution_count": 151, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "def haversine_np(lon1, lat1, lon2, lat2):\n", " lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])\n", " dlon = lon2 - lon1\n", " dlat = lat2 - lat1\n", " a= np.sin(dlat/2.0) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2.0) ** 2\n", " c = 2 * np.arcsin(np.sqrt(a))\n", " km = 6367 * c\n", " return km\n", "''' \n", "Calculate the great circle distance between two points\n", "on the earth (specified in decimal degrees)\n", "All args must be of equal length.\n", "\n", "'''\n" ] }, { "cell_type": "code", "execution_count": 152, "id": "e0e176aa-5530-47e6-8870-e5ceb6cdcf70", "metadata": {}, "outputs": [], "source": [ "def distance_evaluator(data):\n", " data['trip_distance'] = haversine_np(data['pickup_longitude'],\n", " data['pickup_latitude'],\n", " data['dropoff_longitude'],\n", " data['dropoff_latitude'])" ] }, { "cell_type": "code", "execution_count": 153, "id": "9e288c59-ec4e-4821-9f48-044934fa8c5a", "metadata": {}, "outputs": [], "source": [ "def extract_info(data,col):\n", " data[col+'_year'] = data[col].dt.year\n", " data[col+'_month'] = data[col].dt.month\n", " data[col+'_day'] = data[col].dt.day\n", " data[col+'_weekday'] = data[col].dt.weekday\n", " data[col+'_hour'] = data[col].dt.hour\n", " " ] }, { "cell_type": "code", "execution_count": 154, "id": "67bcd54a-a006-44f0-80f4-e16b9c192e8a", "metadata": {}, "outputs": [], "source": [ "distance_evaluator(train_data3)\n", "distance_evaluator(val_data3)\n", "distance_evaluator(train_data10)\n", "distance_evaluator(val_data10)\n" ] }, { "cell_type": "code", "execution_count": 155, "id": "76273428-429d-49e8-8a5d-61593c0799b0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_counttrip_distance
39985675.72012-04-28 19:52:52+00:00-73.98300240.741825-73.97838640.73088131.276929
12976474.12009-03-22 11:54:20+00:00-73.99218040.764221-73.98416940.76130710.748180
33248335.32010-06-12 13:40:00+00:00-74.01661740.709328-74.00861440.71522510.940320
50383654.02013-09-04 19:58:02+00:00-73.98438340.737244-73.98974640.74174910.674066
48942305.32010-08-19 13:44:22+00:00-73.99707840.722363-73.98999040.73452011.476838
...........................
157001315.32010-07-23 12:46:00+00:00-73.98965540.756737-73.99829940.71755214.414771
22345025.32009-09-19 00:33:00+00:00-73.96679740.762238-73.98188840.76855511.451031
49265069.32009-08-26 13:04:46+00:00-73.95413240.764042-73.97522740.76118511.803378
43045938.52014-05-09 22:58:00+00:00-73.97145840.758259-73.95317140.77864112.738510
16927525.52014-07-26 15:57:58+00:00-73.98155240.771519-73.98140040.78104811.058888
\n", "

4432375 rows × 8 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "3998567 5.7 2012-04-28 19:52:52+00:00 -73.983002 \n", "1297647 4.1 2009-03-22 11:54:20+00:00 -73.992180 \n", "3324833 5.3 2010-06-12 13:40:00+00:00 -74.016617 \n", "5038365 4.0 2013-09-04 19:58:02+00:00 -73.984383 \n", "4894230 5.3 2010-08-19 13:44:22+00:00 -73.997078 \n", "... ... ... ... \n", "1570013 15.3 2010-07-23 12:46:00+00:00 -73.989655 \n", "2234502 5.3 2009-09-19 00:33:00+00:00 -73.966797 \n", "4926506 9.3 2009-08-26 13:04:46+00:00 -73.954132 \n", "4304593 8.5 2014-05-09 22:58:00+00:00 -73.971458 \n", "1692752 5.5 2014-07-26 15:57:58+00:00 -73.981552 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude \\\n", "3998567 40.741825 -73.978386 40.730881 \n", "1297647 40.764221 -73.984169 40.761307 \n", "3324833 40.709328 -74.008614 40.715225 \n", "5038365 40.737244 -73.989746 40.741749 \n", "4894230 40.722363 -73.989990 40.734520 \n", "... ... ... ... \n", "1570013 40.756737 -73.998299 40.717552 \n", "2234502 40.762238 -73.981888 40.768555 \n", "4926506 40.764042 -73.975227 40.761185 \n", "4304593 40.758259 -73.953171 40.778641 \n", "1692752 40.771519 -73.981400 40.781048 \n", "\n", " passenger_count trip_distance \n", "3998567 3 1.276929 \n", "1297647 1 0.748180 \n", "3324833 1 0.940320 \n", "5038365 1 0.674066 \n", "4894230 1 1.476838 \n", "... ... ... \n", "1570013 1 4.414771 \n", "2234502 1 1.451031 \n", "4926506 1 1.803378 \n", "4304593 1 2.738510 \n", "1692752 1 1.058888 \n", "\n", "[4432375 rows x 8 columns]" ] }, "execution_count": 155, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10" ] }, { "cell_type": "code", "execution_count": 156, "id": "8267be84-8fa4-4070-ae8a-cdec30e87673", "metadata": {}, "outputs": [], "source": [ "extract_info(train_data3,'pickup_datetime')\n", "extract_info(val_data3,'pickup_datetime')\n", "extract_info(train_data10,'pickup_datetime')\n", "extract_info(val_data10,'pickup_datetime') " ] }, { "cell_type": "code", "execution_count": 157, "id": "998e80b6-e8ce-413e-8d94-d9ffbeadfb3f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_counttrip_distancepickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hour
39985675.72012-04-28 19:52:52+00:00-73.98300240.741825-73.97838640.73088131.2769292012428519
12976474.12009-03-22 11:54:20+00:00-73.99218040.764221-73.98416940.76130710.7481802009322611
33248335.32010-06-12 13:40:00+00:00-74.01661740.709328-74.00861440.71522510.9403202010612513
50383654.02013-09-04 19:58:02+00:00-73.98438340.737244-73.98974640.74174910.674066201394219
48942305.32010-08-19 13:44:22+00:00-73.99707840.722363-73.98999040.73452011.4768382010819313
..........................................
157001315.32010-07-23 12:46:00+00:00-73.98965540.756737-73.99829940.71755214.4147712010723412
22345025.32009-09-19 00:33:00+00:00-73.96679740.762238-73.98188840.76855511.451031200991950
49265069.32009-08-26 13:04:46+00:00-73.95413240.764042-73.97522740.76118511.8033782009826213
43045938.52014-05-09 22:58:00+00:00-73.97145840.758259-73.95317140.77864112.738510201459422
16927525.52014-07-26 15:57:58+00:00-73.98155240.771519-73.98140040.78104811.0588882014726515
\n", "

4432375 rows × 13 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "3998567 5.7 2012-04-28 19:52:52+00:00 -73.983002 \n", "1297647 4.1 2009-03-22 11:54:20+00:00 -73.992180 \n", "3324833 5.3 2010-06-12 13:40:00+00:00 -74.016617 \n", "5038365 4.0 2013-09-04 19:58:02+00:00 -73.984383 \n", "4894230 5.3 2010-08-19 13:44:22+00:00 -73.997078 \n", "... ... ... ... \n", "1570013 15.3 2010-07-23 12:46:00+00:00 -73.989655 \n", "2234502 5.3 2009-09-19 00:33:00+00:00 -73.966797 \n", "4926506 9.3 2009-08-26 13:04:46+00:00 -73.954132 \n", "4304593 8.5 2014-05-09 22:58:00+00:00 -73.971458 \n", "1692752 5.5 2014-07-26 15:57:58+00:00 -73.981552 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude \\\n", "3998567 40.741825 -73.978386 40.730881 \n", "1297647 40.764221 -73.984169 40.761307 \n", "3324833 40.709328 -74.008614 40.715225 \n", "5038365 40.737244 -73.989746 40.741749 \n", "4894230 40.722363 -73.989990 40.734520 \n", "... ... ... ... \n", "1570013 40.756737 -73.998299 40.717552 \n", "2234502 40.762238 -73.981888 40.768555 \n", "4926506 40.764042 -73.975227 40.761185 \n", "4304593 40.758259 -73.953171 40.778641 \n", "1692752 40.771519 -73.981400 40.781048 \n", "\n", " passenger_count trip_distance pickup_datetime_year \\\n", "3998567 3 1.276929 2012 \n", "1297647 1 0.748180 2009 \n", "3324833 1 0.940320 2010 \n", "5038365 1 0.674066 2013 \n", "4894230 1 1.476838 2010 \n", "... ... ... ... \n", "1570013 1 4.414771 2010 \n", "2234502 1 1.451031 2009 \n", "4926506 1 1.803378 2009 \n", "4304593 1 2.738510 2014 \n", "1692752 1 1.058888 2014 \n", "\n", " pickup_datetime_month pickup_datetime_day pickup_datetime_weekday \\\n", "3998567 4 28 5 \n", "1297647 3 22 6 \n", "3324833 6 12 5 \n", "5038365 9 4 2 \n", "4894230 8 19 3 \n", "... ... ... ... \n", "1570013 7 23 4 \n", "2234502 9 19 5 \n", "4926506 8 26 2 \n", "4304593 5 9 4 \n", "1692752 7 26 5 \n", "\n", " pickup_datetime_hour \n", "3998567 19 \n", "1297647 11 \n", "3324833 13 \n", "5038365 19 \n", "4894230 13 \n", "... ... \n", "1570013 12 \n", "2234502 0 \n", "4926506 13 \n", "4304593 22 \n", "1692752 15 \n", "\n", "[4432375 rows x 13 columns]" ] }, "execution_count": 157, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10" ] }, { "cell_type": "code", "execution_count": 158, "id": "da323419-b7c1-44f1-ae48-b04f422cfba3", "metadata": {}, "outputs": [], "source": [ "jfk_lonlat = -73.7781, 40.6413\n", "lga_lonlat = -73.8740, 40.7769\n", "ewr_lonlat = -74.1745, 40.6895\n", "met_lonlat = -73.9632, 40.7794\n", "wtc_lonlat = -74.0099, 40.7126" ] }, { "cell_type": "code", "execution_count": 159, "id": "587043e8-60fd-4efb-98dc-845a8d53dea8", "metadata": {}, "outputs": [], "source": [ "def landmark_dropoff_distance(data,landmark_name,landmark_loglat):\n", " log,lat = landmark_loglat\n", " data[landmark_name+'_drop_distance']= haversine_np(log ,lat ,data['dropoff_longitude'],data['dropoff_latitude'])" ] }, { "cell_type": "code", "execution_count": 160, "id": "7f597349-e29e-416f-aaa3-166d5e687f05", "metadata": {}, "outputs": [], "source": [ "def add_landmark(data):\n", " landmarks = [('jfk',jfk_lonlat),\n", " ('lga',lga_lonlat),\n", " ('ewr',ewr_lonlat),\n", " ('met',met_lonlat),\n", " ('wtc',wtc_lonlat)]\n", " for name,loglat in landmarks:\n", " landmark_dropoff_distance(data,name,loglat)" ] }, { "cell_type": "code", "execution_count": 161, "id": "16a9281e-b827-491a-af09-1ee5d196cf86", "metadata": {}, "outputs": [], "source": [ "add_landmark(train_data3)\n", "add_landmark(val_data3)\n", "add_landmark(train_data10)\n", "add_landmark(val_data10)" ] }, { "cell_type": "code", "execution_count": 162, "id": "7011a84d-fe93-4d0a-8b18-34ded99316a6", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_counttrip_distancepickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourjfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
39985675.72012-04-28 19:52:52+00:00-73.98300240.741825-73.97838640.73088131.276929201242851919.59426810.16700117.1476335.5412393.342241
12976474.12009-03-22 11:54:20+00:00-73.99218040.764221-73.98416940.76130710.748180200932261121.8909609.43209417.9054362.6751235.830046
33248335.32010-06-12 13:40:00+00:00-74.01661740.709328-74.00861440.71522510.940320201061251321.09188013.24399514.2647248.0914880.311325
50383654.02013-09-04 19:58:02+00:00-73.98438340.737244-73.98974640.74174910.67406620139421921.03823510.49656816.6093284.7433843.656743
48942305.32010-08-19 13:44:22+00:00-73.99707840.722363-73.98999040.73452011.476838201081931320.64216610.84023616.3270335.4733942.957209
.........................................................
157001315.32010-07-23 12:46:00+00:00-73.98965540.756737-73.99829940.71755214.414771201072341220.39985212.36921315.1677097.4811511.121554
22345025.32009-09-19 00:33:00+00:00-73.96679740.762238-73.98188840.76855511.45103120099195022.2414889.12627118.4466461.9810156.650465
49265069.32009-08-26 13:04:46+00:00-73.95413240.764042-73.97522740.76118511.803378200982621321.2902758.69621418.5768272.2629276.138009
43045938.52014-05-09 22:58:00+00:00-73.97145840.758259-73.95317140.77864112.73851020145942221.2226776.66488621.1059820.8482358.756058
16927525.52014-07-26 15:57:58+00:00-73.98155240.771519-73.98140040.78104811.058888201472651523.1174699.04912919.1800391.5422817.975787
\n", "

4432375 rows × 18 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "3998567 5.7 2012-04-28 19:52:52+00:00 -73.983002 \n", "1297647 4.1 2009-03-22 11:54:20+00:00 -73.992180 \n", "3324833 5.3 2010-06-12 13:40:00+00:00 -74.016617 \n", "5038365 4.0 2013-09-04 19:58:02+00:00 -73.984383 \n", "4894230 5.3 2010-08-19 13:44:22+00:00 -73.997078 \n", "... ... ... ... \n", "1570013 15.3 2010-07-23 12:46:00+00:00 -73.989655 \n", "2234502 5.3 2009-09-19 00:33:00+00:00 -73.966797 \n", "4926506 9.3 2009-08-26 13:04:46+00:00 -73.954132 \n", "4304593 8.5 2014-05-09 22:58:00+00:00 -73.971458 \n", "1692752 5.5 2014-07-26 15:57:58+00:00 -73.981552 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude \\\n", "3998567 40.741825 -73.978386 40.730881 \n", "1297647 40.764221 -73.984169 40.761307 \n", "3324833 40.709328 -74.008614 40.715225 \n", "5038365 40.737244 -73.989746 40.741749 \n", "4894230 40.722363 -73.989990 40.734520 \n", "... ... ... ... \n", "1570013 40.756737 -73.998299 40.717552 \n", "2234502 40.762238 -73.981888 40.768555 \n", "4926506 40.764042 -73.975227 40.761185 \n", "4304593 40.758259 -73.953171 40.778641 \n", "1692752 40.771519 -73.981400 40.781048 \n", "\n", " passenger_count trip_distance pickup_datetime_year \\\n", "3998567 3 1.276929 2012 \n", "1297647 1 0.748180 2009 \n", "3324833 1 0.940320 2010 \n", "5038365 1 0.674066 2013 \n", "4894230 1 1.476838 2010 \n", "... ... ... ... \n", "1570013 1 4.414771 2010 \n", "2234502 1 1.451031 2009 \n", "4926506 1 1.803378 2009 \n", "4304593 1 2.738510 2014 \n", "1692752 1 1.058888 2014 \n", "\n", " pickup_datetime_month pickup_datetime_day pickup_datetime_weekday \\\n", "3998567 4 28 5 \n", "1297647 3 22 6 \n", "3324833 6 12 5 \n", "5038365 9 4 2 \n", "4894230 8 19 3 \n", "... ... ... ... \n", "1570013 7 23 4 \n", "2234502 9 19 5 \n", "4926506 8 26 2 \n", "4304593 5 9 4 \n", "1692752 7 26 5 \n", "\n", " pickup_datetime_hour jfk_drop_distance lga_drop_distance \\\n", "3998567 19 19.594268 10.167001 \n", "1297647 11 21.890960 9.432094 \n", "3324833 13 21.091880 13.243995 \n", "5038365 19 21.038235 10.496568 \n", "4894230 13 20.642166 10.840236 \n", "... ... ... ... \n", "1570013 12 20.399852 12.369213 \n", "2234502 0 22.241488 9.126271 \n", "4926506 13 21.290275 8.696214 \n", "4304593 22 21.222677 6.664886 \n", "1692752 15 23.117469 9.049129 \n", "\n", " ewr_drop_distance met_drop_distance wtc_drop_distance \n", "3998567 17.147633 5.541239 3.342241 \n", "1297647 17.905436 2.675123 5.830046 \n", "3324833 14.264724 8.091488 0.311325 \n", "5038365 16.609328 4.743384 3.656743 \n", "4894230 16.327033 5.473394 2.957209 \n", "... ... ... ... \n", "1570013 15.167709 7.481151 1.121554 \n", "2234502 18.446646 1.981015 6.650465 \n", "4926506 18.576827 2.262927 6.138009 \n", "4304593 21.105982 0.848235 8.756058 \n", "1692752 19.180039 1.542281 7.975787 \n", "\n", "[4432375 rows x 18 columns]" ] }, "execution_count": 162, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10" ] }, { "cell_type": "code", "execution_count": 163, "id": "1ee833e0-9c29-41a7-9243-f0bd16d38369", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_counttrip_distancepickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourjfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
count4.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+064.432375e+06
mean1.133739e+01-7.251658e+013.991970e+01-7.251485e+013.991888e+011.686650e+002.001510e+012.011740e+036.263875e+001.571816e+013.041134e+001.350796e+011.925729e+021.817814e+021.908399e+021.768255e+021.783250e+02
std9.729894e+001.282979e+011.012297e+011.307459e+011.031528e+011.334857e+003.725870e+021.860003e+003.433978e+008.686547e+001.949020e+006.516328e+001.221962e+031.225015e+031.226849e+031.226728e+031.226823e+03
min-1.450000e+02-3.384713e+03-3.488031e+03-3.394483e+03-3.483855e+030.000000e+000.000000e+002.009000e+031.000000e+001.000000e+000.000000e+000.000000e+001.891306e-012.147256e-021.943166e-011.903868e-022.024109e-03
25%6.000000e+00-7.399207e+014.073496e+01-7.399139e+014.073407e+011.000000e+001.211645e+002.010000e+033.000000e+008.000000e+001.000000e+009.000000e+002.053833e+018.344644e+001.650536e+012.164302e+003.643375e+00
50%8.500000e+00-7.398180e+014.075268e+01-7.398015e+014.075316e+011.000000e+002.114515e+002.012000e+036.000000e+001.600000e+013.000000e+001.400000e+012.120464e+019.574266e+001.802145e+013.803042e+005.566407e+00
75%1.250000e+01-7.396709e+014.076713e+01-7.396368e+014.076810e+012.000000e+003.872261e+002.013000e+039.000000e+002.300000e+015.000000e+001.900000e+012.195213e+011.111760e+011.995965e+016.051793e+007.818505e+00
max5.841600e+023.456138e+033.351468e+033.440830e+033.390615e+032.080000e+021.888969e+042.015000e+031.200000e+013.100000e+016.000000e+002.300000e+011.810252e+041.810706e+041.813391e+041.811431e+041.811982e+04
\n", "
" ], "text/plain": [ " fare_amount pickup_longitude pickup_latitude dropoff_longitude \\\n", "count 4.432375e+06 4.432375e+06 4.432375e+06 4.432375e+06 \n", "mean 1.133739e+01 -7.251658e+01 3.991970e+01 -7.251485e+01 \n", "std 9.729894e+00 1.282979e+01 1.012297e+01 1.307459e+01 \n", "min -1.450000e+02 -3.384713e+03 -3.488031e+03 -3.394483e+03 \n", "25% 6.000000e+00 -7.399207e+01 4.073496e+01 -7.399139e+01 \n", "50% 8.500000e+00 -7.398180e+01 4.075268e+01 -7.398015e+01 \n", "75% 1.250000e+01 -7.396709e+01 4.076713e+01 -7.396368e+01 \n", "max 5.841600e+02 3.456138e+03 3.351468e+03 3.440830e+03 \n", "\n", " dropoff_latitude passenger_count trip_distance pickup_datetime_year \\\n", "count 4.432375e+06 4.432375e+06 4.432375e+06 4.432375e+06 \n", "mean 3.991888e+01 1.686650e+00 2.001510e+01 2.011740e+03 \n", "std 1.031528e+01 1.334857e+00 3.725870e+02 1.860003e+00 \n", "min -3.483855e+03 0.000000e+00 0.000000e+00 2.009000e+03 \n", "25% 4.073407e+01 1.000000e+00 1.211645e+00 2.010000e+03 \n", "50% 4.075316e+01 1.000000e+00 2.114515e+00 2.012000e+03 \n", "75% 4.076810e+01 2.000000e+00 3.872261e+00 2.013000e+03 \n", "max 3.390615e+03 2.080000e+02 1.888969e+04 2.015000e+03 \n", "\n", " pickup_datetime_month pickup_datetime_day pickup_datetime_weekday \\\n", "count 4.432375e+06 4.432375e+06 4.432375e+06 \n", "mean 6.263875e+00 1.571816e+01 3.041134e+00 \n", "std 3.433978e+00 8.686547e+00 1.949020e+00 \n", "min 1.000000e+00 1.000000e+00 0.000000e+00 \n", "25% 3.000000e+00 8.000000e+00 1.000000e+00 \n", "50% 6.000000e+00 1.600000e+01 3.000000e+00 \n", "75% 9.000000e+00 2.300000e+01 5.000000e+00 \n", "max 1.200000e+01 3.100000e+01 6.000000e+00 \n", "\n", " pickup_datetime_hour jfk_drop_distance lga_drop_distance \\\n", "count 4.432375e+06 4.432375e+06 4.432375e+06 \n", "mean 1.350796e+01 1.925729e+02 1.817814e+02 \n", "std 6.516328e+00 1.221962e+03 1.225015e+03 \n", "min 0.000000e+00 1.891306e-01 2.147256e-02 \n", "25% 9.000000e+00 2.053833e+01 8.344644e+00 \n", "50% 1.400000e+01 2.120464e+01 9.574266e+00 \n", "75% 1.900000e+01 2.195213e+01 1.111760e+01 \n", "max 2.300000e+01 1.810252e+04 1.810706e+04 \n", "\n", " ewr_drop_distance met_drop_distance wtc_drop_distance \n", "count 4.432375e+06 4.432375e+06 4.432375e+06 \n", "mean 1.908399e+02 1.768255e+02 1.783250e+02 \n", "std 1.226849e+03 1.226728e+03 1.226823e+03 \n", "min 1.943166e-01 1.903868e-02 2.024109e-03 \n", "25% 1.650536e+01 2.164302e+00 3.643375e+00 \n", "50% 1.802145e+01 3.803042e+00 5.566407e+00 \n", "75% 1.995965e+01 6.051793e+00 7.818505e+00 \n", "max 1.813391e+04 1.811431e+04 1.811982e+04 " ] }, "execution_count": 163, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10.describe()" ] }, { "cell_type": "code", "execution_count": 164, "id": "95ff5ee1-2607-448e-8cd5-a0b3a973b9b7", "metadata": {}, "outputs": [], "source": [ "def remove_outliers(df):\n", " return df[(df['fare_amount'] >= 1.) &\n", " (df['fare_amount' ] <= 500.) &\n", " (df['pickup_longitude' ] >= -75) &\n", " (df['pickup_longitude' ] <= -72) &\n", " (df['dropoff_longitude' ] >= -75) &\n", " (df['dropoff_longitude' ] <= -72) &\n", " (df['pickup_latitude' ] >= 40) &\n", " (df['pickup_latitude' ] <= 42) &\n", " (df['dropoff_latitude' ] >=40) &\n", " (df['dropoff_latitude' ] <= 42) &\n", " (df['passenger_count' ] >= 1) &\n", " (df['passenger_count'] <= 6)]" ] }, { "cell_type": "code", "execution_count": 165, "id": "1a077651-c0ad-448e-9e16-0c57adbaac24", "metadata": { "scrolled": true }, "outputs": [], "source": [ "train_data10=remove_outliers(train_data10)\n", "val_data10=remove_outliers(val_data10)\n", "train_data3=remove_outliers(train_data3)\n", "val_data3=remove_outliers(val_data3)\n" ] }, { "cell_type": "code", "execution_count": 166, "id": "89262e70-89a5-48f0-b613-db27bef0d5ce", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_datetimepickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_counttrip_distancepickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourjfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
39985675.72012-04-28 19:52:52+00:00-73.98300240.741825-73.97838640.73088131.276929201242851919.59426810.16700117.1476335.5412393.342241
12976474.12009-03-22 11:54:20+00:00-73.99218040.764221-73.98416940.76130710.748180200932261121.8909609.43209417.9054362.6751235.830046
33248335.32010-06-12 13:40:00+00:00-74.01661740.709328-74.00861440.71522510.940320201061251321.09188013.24399514.2647248.0914880.311325
50383654.02013-09-04 19:58:02+00:00-73.98438340.737244-73.98974640.74174910.67406620139421921.03823510.49656816.6093284.7433843.656743
48942305.32010-08-19 13:44:22+00:00-73.99707840.722363-73.98999040.73452011.476838201081931320.64216610.84023616.3270335.4733942.957209
.........................................................
157001315.32010-07-23 12:46:00+00:00-73.98965540.756737-73.99829940.71755214.414771201072341220.39985212.36921315.1677097.4811511.121554
22345025.32009-09-19 00:33:00+00:00-73.96679740.762238-73.98188840.76855511.45103120099195022.2414889.12627118.4466461.9810156.650465
49265069.32009-08-26 13:04:46+00:00-73.95413240.764042-73.97522740.76118511.803378200982621321.2902758.69621418.5768272.2629276.138009
43045938.52014-05-09 22:58:00+00:00-73.97145840.758259-73.95317140.77864112.73851020145942221.2226776.66488621.1059820.8482358.756058
16927525.52014-07-26 15:57:58+00:00-73.98155240.771519-73.98140040.78104811.058888201472651523.1174699.04912919.1800391.5422817.975787
\n", "

4323806 rows × 18 columns

\n", "
" ], "text/plain": [ " fare_amount pickup_datetime pickup_longitude \\\n", "3998567 5.7 2012-04-28 19:52:52+00:00 -73.983002 \n", "1297647 4.1 2009-03-22 11:54:20+00:00 -73.992180 \n", "3324833 5.3 2010-06-12 13:40:00+00:00 -74.016617 \n", "5038365 4.0 2013-09-04 19:58:02+00:00 -73.984383 \n", "4894230 5.3 2010-08-19 13:44:22+00:00 -73.997078 \n", "... ... ... ... \n", "1570013 15.3 2010-07-23 12:46:00+00:00 -73.989655 \n", "2234502 5.3 2009-09-19 00:33:00+00:00 -73.966797 \n", "4926506 9.3 2009-08-26 13:04:46+00:00 -73.954132 \n", "4304593 8.5 2014-05-09 22:58:00+00:00 -73.971458 \n", "1692752 5.5 2014-07-26 15:57:58+00:00 -73.981552 \n", "\n", " pickup_latitude dropoff_longitude dropoff_latitude \\\n", "3998567 40.741825 -73.978386 40.730881 \n", "1297647 40.764221 -73.984169 40.761307 \n", "3324833 40.709328 -74.008614 40.715225 \n", "5038365 40.737244 -73.989746 40.741749 \n", "4894230 40.722363 -73.989990 40.734520 \n", "... ... ... ... \n", "1570013 40.756737 -73.998299 40.717552 \n", "2234502 40.762238 -73.981888 40.768555 \n", "4926506 40.764042 -73.975227 40.761185 \n", "4304593 40.758259 -73.953171 40.778641 \n", "1692752 40.771519 -73.981400 40.781048 \n", "\n", " passenger_count trip_distance pickup_datetime_year \\\n", "3998567 3 1.276929 2012 \n", "1297647 1 0.748180 2009 \n", "3324833 1 0.940320 2010 \n", "5038365 1 0.674066 2013 \n", "4894230 1 1.476838 2010 \n", "... ... ... ... \n", "1570013 1 4.414771 2010 \n", "2234502 1 1.451031 2009 \n", "4926506 1 1.803378 2009 \n", "4304593 1 2.738510 2014 \n", "1692752 1 1.058888 2014 \n", "\n", " pickup_datetime_month pickup_datetime_day pickup_datetime_weekday \\\n", "3998567 4 28 5 \n", "1297647 3 22 6 \n", "3324833 6 12 5 \n", "5038365 9 4 2 \n", "4894230 8 19 3 \n", "... ... ... ... \n", "1570013 7 23 4 \n", "2234502 9 19 5 \n", "4926506 8 26 2 \n", "4304593 5 9 4 \n", "1692752 7 26 5 \n", "\n", " pickup_datetime_hour jfk_drop_distance lga_drop_distance \\\n", "3998567 19 19.594268 10.167001 \n", "1297647 11 21.890960 9.432094 \n", "3324833 13 21.091880 13.243995 \n", "5038365 19 21.038235 10.496568 \n", "4894230 13 20.642166 10.840236 \n", "... ... ... ... \n", "1570013 12 20.399852 12.369213 \n", "2234502 0 22.241488 9.126271 \n", "4926506 13 21.290275 8.696214 \n", "4304593 22 21.222677 6.664886 \n", "1692752 15 23.117469 9.049129 \n", "\n", " ewr_drop_distance met_drop_distance wtc_drop_distance \n", "3998567 17.147633 5.541239 3.342241 \n", "1297647 17.905436 2.675123 5.830046 \n", "3324833 14.264724 8.091488 0.311325 \n", "5038365 16.609328 4.743384 3.656743 \n", "4894230 16.327033 5.473394 2.957209 \n", "... ... ... ... \n", "1570013 15.167709 7.481151 1.121554 \n", "2234502 18.446646 1.981015 6.650465 \n", "4926506 18.576827 2.262927 6.138009 \n", "4304593 21.105982 0.848235 8.756058 \n", "1692752 19.180039 1.542281 7.975787 \n", "\n", "[4323806 rows x 18 columns]" ] }, "execution_count": 166, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10" ] }, { "cell_type": "code", "execution_count": 167, "id": "d1533590-bcff-4bbc-bdf5-0b8bf43d9500", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
fare_amountpickup_longitudepickup_latitudedropoff_longitudedropoff_latitudepassenger_counttrip_distancepickup_datetime_yearpickup_datetime_monthpickup_datetime_daypickup_datetime_weekdaypickup_datetime_hourjfk_drop_distancelga_drop_distanceewr_drop_distancemet_drop_distancewtc_drop_distance
count4.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+064.323806e+06
mean1.132818e+01-7.397524e+014.075107e+01-7.397424e+014.075150e+011.692323e+003.327645e+002.011738e+036.267246e+001.571637e+013.041318e+001.350854e+012.091300e+019.685275e+001.847929e+014.483593e+005.967841e+00
std9.637309e+008.944825e-021.148816e+008.831584e-021.148234e+001.307648e+003.777090e+001.865451e+003.435055e+008.687748e+001.949329e+006.515759e+003.111578e+003.073387e+003.751457e+003.791980e+003.991338e+00
min1.000000e+00-7.494114e+014.000531e+01-7.498721e+014.000335e+011.000000e+000.000000e+002.009000e+031.000000e+001.000000e+000.000000e+000.000000e+001.891306e-012.147256e-021.943166e-011.903868e-022.024109e-03
25%6.000000e+00-7.399228e+014.073658e+01-7.399158e+014.073563e+011.000000e+001.252340e+002.010000e+033.000000e+008.000000e+001.000000e+009.000000e+002.052205e+018.318288e+001.647943e+012.135096e+003.588189e+00
50%8.500000e+00-7.398209e+014.075340e+01-7.398061e+014.075386e+011.000000e+002.151216e+002.012000e+036.000000e+001.600000e+013.000000e+001.400000e+012.117536e+019.518212e+001.796345e+013.705655e+005.495385e+00
75%1.250000e+01-7.396831e+014.076755e+01-7.396535e+014.076840e+012.000000e+003.908612e+002.013000e+039.000000e+002.300000e+015.000000e+001.900000e+012.190082e+011.098282e+011.979075e+015.888230e+007.647567e+00
max4.500000e+02-7.205000e+014.196522e+01-7.231396e+014.199465e+016.000000e+001.630394e+022.015000e+031.200000e+013.100000e+016.000000e+002.300000e+011.897308e+021.832392e+022.077174e+021.881319e+021.962322e+02
\n", "
" ], "text/plain": [ " fare_amount pickup_longitude pickup_latitude dropoff_longitude \\\n", "count 4.323806e+06 4.323806e+06 4.323806e+06 4.323806e+06 \n", "mean 1.132818e+01 -7.397524e+01 4.075107e+01 -7.397424e+01 \n", "std 9.637309e+00 8.944825e-02 1.148816e+00 8.831584e-02 \n", "min 1.000000e+00 -7.494114e+01 4.000531e+01 -7.498721e+01 \n", "25% 6.000000e+00 -7.399228e+01 4.073658e+01 -7.399158e+01 \n", "50% 8.500000e+00 -7.398209e+01 4.075340e+01 -7.398061e+01 \n", "75% 1.250000e+01 -7.396831e+01 4.076755e+01 -7.396535e+01 \n", "max 4.500000e+02 -7.205000e+01 4.196522e+01 -7.231396e+01 \n", "\n", " dropoff_latitude passenger_count trip_distance pickup_datetime_year \\\n", "count 4.323806e+06 4.323806e+06 4.323806e+06 4.323806e+06 \n", "mean 4.075150e+01 1.692323e+00 3.327645e+00 2.011738e+03 \n", "std 1.148234e+00 1.307648e+00 3.777090e+00 1.865451e+00 \n", "min 4.000335e+01 1.000000e+00 0.000000e+00 2.009000e+03 \n", "25% 4.073563e+01 1.000000e+00 1.252340e+00 2.010000e+03 \n", "50% 4.075386e+01 1.000000e+00 2.151216e+00 2.012000e+03 \n", "75% 4.076840e+01 2.000000e+00 3.908612e+00 2.013000e+03 \n", "max 4.199465e+01 6.000000e+00 1.630394e+02 2.015000e+03 \n", "\n", " pickup_datetime_month pickup_datetime_day pickup_datetime_weekday \\\n", "count 4.323806e+06 4.323806e+06 4.323806e+06 \n", "mean 6.267246e+00 1.571637e+01 3.041318e+00 \n", "std 3.435055e+00 8.687748e+00 1.949329e+00 \n", "min 1.000000e+00 1.000000e+00 0.000000e+00 \n", "25% 3.000000e+00 8.000000e+00 1.000000e+00 \n", "50% 6.000000e+00 1.600000e+01 3.000000e+00 \n", "75% 9.000000e+00 2.300000e+01 5.000000e+00 \n", "max 1.200000e+01 3.100000e+01 6.000000e+00 \n", "\n", " pickup_datetime_hour jfk_drop_distance lga_drop_distance \\\n", "count 4.323806e+06 4.323806e+06 4.323806e+06 \n", "mean 1.350854e+01 2.091300e+01 9.685275e+00 \n", "std 6.515759e+00 3.111578e+00 3.073387e+00 \n", "min 0.000000e+00 1.891306e-01 2.147256e-02 \n", "25% 9.000000e+00 2.052205e+01 8.318288e+00 \n", "50% 1.400000e+01 2.117536e+01 9.518212e+00 \n", "75% 1.900000e+01 2.190082e+01 1.098282e+01 \n", "max 2.300000e+01 1.897308e+02 1.832392e+02 \n", "\n", " ewr_drop_distance met_drop_distance wtc_drop_distance \n", "count 4.323806e+06 4.323806e+06 4.323806e+06 \n", "mean 1.847929e+01 4.483593e+00 5.967841e+00 \n", "std 3.751457e+00 3.791980e+00 3.991338e+00 \n", "min 1.943166e-01 1.903868e-02 2.024109e-03 \n", "25% 1.647943e+01 2.135096e+00 3.588189e+00 \n", "50% 1.796345e+01 3.705655e+00 5.495385e+00 \n", "75% 1.979075e+01 5.888230e+00 7.647567e+00 \n", "max 2.077174e+02 1.881319e+02 1.962322e+02 " ] }, "execution_count": 167, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10.describe()" ] }, { "cell_type": "markdown", "id": "dc07d43c-8ac4-41e0-b1f7-e589050a00d6", "metadata": {}, "source": [ "## Saving our processed data in parkuet file" ] }, { "cell_type": "code", "execution_count": 168, "id": "c893ca91-a09a-4e22-af7b-7e508463c1cc", "metadata": {}, "outputs": [], "source": [ "test_data = pd.read_parquet('./parkuet_file/test.parquet')" ] }, { "cell_type": "code", "execution_count": 169, "id": "8f34b81b-64ee-4752-a4d0-ba00f291b32c", "metadata": {}, "outputs": [], "source": [ "train_data3.to_parquet('./parkuet_file/train3.parquet')\n", "val_data3.to_parquet('./parkuet_file/val3.parquet')" ] }, { "cell_type": "code", "execution_count": 170, "id": "c5508981-94ba-4a62-bfca-917a4bf2a782", "metadata": {}, "outputs": [], "source": [ "train_data10.to_parquet('./parkuet_file/train10.parquet')\n", "val_data10.to_parquet('./parkuet_file/val10.parquet')" ] }, { "cell_type": "code", "execution_count": 171, "id": "61372f6f-51f8-4149-8287-e0cc8b538bae", "metadata": {}, "outputs": [], "source": [ "train_data10 = pd.read_parquet('./parkuet_file/train10.parquet')\n", "val_data10 = pd.read_parquet('./parkuet_file/val10.parquet')\n", "train_data3 = pd.read_parquet('./parkuet_file/train3.parquet')\n", "val_data3 = pd.read_parquet('./parkuet_file/val3.parquet')" ] }, { "cell_type": "code", "execution_count": 172, "id": "11c16a76-1749-4518-adf9-7ac90d119580", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['fare_amount', 'pickup_datetime', 'pickup_longitude', 'pickup_latitude',\n", " 'dropoff_longitude', 'dropoff_latitude', 'passenger_count',\n", " 'trip_distance', 'pickup_datetime_year', 'pickup_datetime_month',\n", " 'pickup_datetime_day', 'pickup_datetime_weekday',\n", " 'pickup_datetime_hour', 'jfk_drop_distance', 'lga_drop_distance',\n", " 'ewr_drop_distance', 'met_drop_distance', 'wtc_drop_distance'],\n", " dtype='object')" ] }, "execution_count": 172, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_data10.columns" ] }, { "cell_type": "code", "execution_count": 173, "id": "8a41f474-f786-4539-81b9-0378b9c77944", "metadata": {}, "outputs": [], "source": [ "inputs_cols = [ 'pickup_longitude', 'pickup_latitude',\n", " 'dropoff_longitude', 'dropoff_latitude', 'passenger_count',\n", " 'trip_distance', 'pickup_datetime_year', 'pickup_datetime_month',\n", " 'pickup_datetime_day', 'pickup_datetime_weekday',\n", " 'pickup_datetime_hour', 'jfk_drop_distance', 'lga_drop_distance',\n", " 'ewr_drop_distance', 'met_drop_distance', 'wtc_drop_distance']\n", "target_cols = 'fare_amount'" ] }, { "cell_type": "code", "execution_count": 174, "id": "bdaf8c98-5344-4d61-ab21-d1c8f5d7faa7", "metadata": {}, "outputs": [], "source": [ "train_inputs3 = train_data3[inputs_cols]\n", "train_target3 = train_data3[target_cols]\n", "val_inputs3 = val_data3[inputs_cols]\n", "val_target3 = val_data3[target_cols]\n", "train_inputs10 = train_data10[inputs_cols]\n", "train_target10 = train_data10[target_cols]\n", "val_inputs10 = val_data10[inputs_cols]\n", "val_target10 = val_data10[target_cols]" ] }, { "cell_type": "markdown", "id": "606e3510-7c27-4c77-a183-f670a6542fe1", "metadata": {}, "source": [ "## Fitting our best model" ] }, { "cell_type": "code", "execution_count": 175, "id": "3b674092-3071-4844-a89d-a8cbebb71a52", "metadata": {}, "outputs": [], "source": [ "from xgboost import XGBRegressor" ] }, { "cell_type": "code", "execution_count": 176, "id": "d43b49df-5bcb-4e49-8777-ba4536850bf3", "metadata": {}, "outputs": [], "source": [ "best_model = XGBRegressor(\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'gbtree',\n", " tree_method = 'hist'\n", " )" ] }, { "cell_type": "code", "execution_count": 177, "id": "a72f77e4-3f1b-4603-94fb-37750d056630", "metadata": {}, "outputs": [], "source": [ "def params_applier3(model,**params):\n", " model = model(**params)\n", " model.fit(train_inputs3,train_target3)\n", " train_pred = model.predict(train_inputs3)\n", " train_rmse = np.sqrt(mean_squared_error(train_target3,train_pred))\n", " val_pred = model.predict(val_inputs3)\n", " val_rmse = np.sqrt(mean_squared_error(val_pred,val_target3))\n", " return train_pred,train_rmse,val_pred,val_rmse" ] }, { "cell_type": "code", "execution_count": 178, "id": "ea5cac70-e358-4519-8cb2-fef3a3519d3e", "metadata": {}, "outputs": [], "source": [ "def params_applier10(model,**params):\n", " model = model(**params)\n", " model.fit(train_inputs10,train_target10)\n", " train_pred = model.predict(train_inputs10)\n", " train_rmse = np.sqrt(mean_squared_error(train_target10,train_pred))\n", " val_pred = model.predict(val_inputs10)\n", " val_rmse = np.sqrt(mean_squared_error(val_pred,val_target10))\n", " return train_pred,train_rmse,val_pred,val_rmse" ] }, { "cell_type": "code", "execution_count": 179, "id": "7f7b4d0a-9d4e-4909-9406-550042efd8e3", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(array([6.220419 , 4.506401 , 5.876684 , ..., 8.590099 , 8.674957 ,\n", " 5.3959455], dtype=float32),\n", " np.float64(3.6078558032450907),\n", " array([ 8.073045 , 7.7713213, 7.0075827, ..., 8.304145 , 12.304397 ,\n", " 8.47827 ], dtype=float32),\n", " np.float64(3.6756120859719363))" ] }, "execution_count": 179, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier10(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators = 500,\n", " learning_rate = 0.06,\n", " max_depth = 6,\n", " min_child_weight = 20,\n", " gamma = 0.1,\n", " subsample = 1,\n", " colsample_bytree = 0.6,\n", " booster = 'gbtree',\n", " tree_method = 'hist'\n", " )" ] }, { "cell_type": "code", "execution_count": 180, "id": "cc694388-8eae-4d67-811e-76551e478449", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(array([5.931263 , 4.54495 , 5.885252 , ..., 8.863615 , 8.452772 ,\n", " 5.1941166], dtype=float32),\n", " np.float64(3.26435089809424),\n", " array([ 8.053118 , 7.4996486, 6.7517905, ..., 8.167994 , 12.546586 ,\n", " 8.645787 ], dtype=float32),\n", " np.float64(3.58193260730965))" ] }, "execution_count": 180, "metadata": {}, "output_type": "execute_result" } ], "source": [ "params_applier10(XGBRegressor,\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators=1200,\n", " learning_rate=0.03,\n", " max_depth=8,\n", " min_child_weight=8,\n", " gamma=0,\n", " subsample=0.8,\n", " colsample_bytree=0.8,\n", " booster='gbtree',\n", " tree_method='hist',\n", " eval_metric='rmse'\n", ")" ] }, { "cell_type": "code", "execution_count": 181, "id": "ccead80d-c6a1-4dbc-b214-0302511c3472", "metadata": {}, "outputs": [], "source": [ "best_model10 = XGBRegressor(\n", " objective='reg:squarederror',\n", " random_state=42,\n", " n_jobs=-1,\n", " n_estimators=1200,\n", " learning_rate=0.03,\n", " max_depth=8,\n", " min_child_weight=8,\n", " gamma=0,\n", " subsample=0.8,\n", " colsample_bytree=0.8,\n", " booster='gbtree',\n", " tree_method='hist',\n", " eval_metric='rmse'\n", ")\n" ] }, { "cell_type": "code", "execution_count": 182, "id": "bc4d973f-5f84-43a4-ba0c-ff8204692bc1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
XGBRegressor(base_score=None, booster='gbtree', callbacks=None,\n",
       "             colsample_bylevel=None, colsample_bynode=None,\n",
       "             colsample_bytree=0.8, device=None, early_stopping_rounds=None,\n",
       "             enable_categorical=False, eval_metric='rmse', feature_types=None,\n",
       "             feature_weights=None, gamma=0, grow_policy=None,\n",
       "             importance_type=None, interaction_constraints=None,\n",
       "             learning_rate=0.03, max_bin=None, max_cat_threshold=None,\n",
       "             max_cat_to_onehot=None, max_delta_step=None, max_depth=8,\n",
       "             max_leaves=None, min_child_weight=8, missing=nan,\n",
       "             monotone_constraints=None, multi_strategy=None, n_estimators=1200,\n",
       "             n_jobs=-1, num_parallel_tree=None, ...)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ], "text/plain": [ "XGBRegressor(base_score=None, booster='gbtree', callbacks=None,\n", " colsample_bylevel=None, colsample_bynode=None,\n", " colsample_bytree=0.8, device=None, early_stopping_rounds=None,\n", " enable_categorical=False, eval_metric='rmse', feature_types=None,\n", " feature_weights=None, gamma=0, grow_policy=None,\n", " importance_type=None, interaction_constraints=None,\n", " learning_rate=0.03, max_bin=None, max_cat_threshold=None,\n", " max_cat_to_onehot=None, max_delta_step=None, max_depth=8,\n", " max_leaves=None, min_child_weight=8, missing=nan,\n", " monotone_constraints=None, multi_strategy=None, n_estimators=1200,\n", " n_jobs=-1, num_parallel_tree=None, ...)" ] }, "execution_count": 182, "metadata": {}, "output_type": "execute_result" } ], "source": [ "best_model10.fit(train_inputs10,train_target10)" ] }, { "cell_type": "code", "execution_count": 183, "id": "6df30976-4b9a-4a1b-8ee2-9d735ec17c24", "metadata": {}, "outputs": [], "source": [ "test_inputs= test_data[inputs_cols]" ] }, { "cell_type": "code", "execution_count": 184, "id": "f2f58316-d778-4e29-a4e0-a9a2d4bc725f", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
keyfare_amount
02015-01-27 13:08:24.000000210.543032
12015-01-27 13:08:24.000000310.523460
22011-10-08 11:53:44.00000024.579972
32012-12-01 21:12:12.00000029.127750
42012-12-01 21:12:12.000000316.448162
.........
99092015-05-10 12:37:51.00000028.875057
99102015-01-12 17:05:51.000000111.832165
99112015-04-19 20:44:15.000000153.834366
99122015-01-31 01:05:19.000000519.425726
99132015-01-18 14:06:23.00000066.852792
\n", "

9914 rows × 2 columns

\n", "
" ], "text/plain": [ " key fare_amount\n", "0 2015-01-27 13:08:24.0000002 10.543032\n", "1 2015-01-27 13:08:24.0000003 10.523460\n", "2 2011-10-08 11:53:44.0000002 4.579972\n", "3 2012-12-01 21:12:12.0000002 9.127750\n", "4 2012-12-01 21:12:12.0000003 16.448162\n", "... ... ...\n", "9909 2015-05-10 12:37:51.0000002 8.875057\n", "9910 2015-01-12 17:05:51.0000001 11.832165\n", "9911 2015-04-19 20:44:15.0000001 53.834366\n", "9912 2015-01-31 01:05:19.0000005 19.425726\n", "9913 2015-01-18 14:06:23.0000006 6.852792\n", "\n", "[9914 rows x 2 columns]" ] }, "execution_count": 184, "metadata": {}, "output_type": "execute_result" } ], "source": [ "predict_and_submit(best_model10,test_inputs,'./submissions/10%xgboost_submission.csv')" ] }, { "cell_type": "markdown", "id": "4cbe52cd-0da8-476a-b80f-2e1dd248e67b", "metadata": {}, "source": [ "## finally we got a rank of 250" ] }, { "cell_type": "markdown", "id": "35101384-0c63-452c-bd58-fcbe5cfeb407", "metadata": {}, "source": [ "# Conclusion : Future improvement method" ] }, { "cell_type": "markdown", "id": "0077fe1a-6a77-4676-ae92-88eded8fea80", "metadata": {}, "source": [ "- We should try some other models to improve our model\n", "- There can be some more hyperparameter tuning for improving our model accoding to there importance accoding to the data set\n", "- We have just used 1 percent of data of the dataset.So we can use the complete data to improve accuracy of our model\n", "- We can also do essembling or stacking to get the best result for root mean squared error\n", "- We can also use Bayesian,Optuna and Hyperopt to give a range of hyperameter to find best hyperparameter\n", "- We can also doo some more feature engineering to improve efficiency\n", "- We are still left with scaling sensitive model to be scaled .This will garentieid make a major impact\n", "- we can also do the One hot encoding in some of feature related to dates " ] }, { "cell_type": "code", "execution_count": null, "id": "35e59197-0c44-4de8-8355-1e7958ccb699", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "3e9e6400-44fc-44a9-a86f-dc526e8b4de8", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:base] *", "language": "python", "name": "conda-base-py" }, "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.13.5" } }, "nbformat": 4, "nbformat_minor": 5 }