{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd \n", "import numpy as np\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\user\\AppData\\Local\\Temp\\ipykernel_20744\\3250454216.py:2: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n", " df['hour'] = pd.to_datetime(df['time']).dt.hour\n" ] } ], "source": [ "df= pd.read_csv('data.csv')\n", "df['hour'] = pd.to_datetime(df['time']).dt.hour\n", "df['weekday'] = pd.to_datetime(df['date']).dt.weekday\n", "\n" ] }, { "cell_type": "code", "execution_count": 31, "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", "
addresscar_numlatlongtimedatehourweekday
040, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252722.58044118:48:392023-05-02181
140, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252722.58044118:48:392023-05-02181
240, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252722.58044118:50:152023-05-02181
340, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252622.58045819:16:082023-05-02191
415, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37255222.58043219:17:152023-05-02191
\n", "
" ], "text/plain": [ " address car_num lat \n", "0 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372527 \\\n", "1 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372527 \n", "2 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372527 \n", "3 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372526 \n", "4 15, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372552 \n", "\n", " long time date hour weekday \n", "0 22.580441 18:48:39 2023-05-02 18 1 \n", "1 22.580441 18:48:39 2023-05-02 18 1 \n", "2 22.580441 18:50:15 2023-05-02 18 1 \n", "3 22.580458 19:16:08 2023-05-02 19 1 \n", "4 22.580432 19:17:15 2023-05-02 19 1 " ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "# df.drop(['time','date','address','car_num'],axis=1,inplace=True)" ] }, { "cell_type": "code", "execution_count": 32, "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", "
addresscar_numlatlongtimedatehourweekday
040, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252722.58044118:48:392023-05-02181
140, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252722.58044118:48:392023-05-02181
240, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252722.58044118:50:152023-05-02181
340, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37252622.58045819:16:082023-05-02191
415, Vidyasagar St, Machuabazar, Kolkata, West ...jj88.37255222.58043219:17:152023-05-02191
\n", "
" ], "text/plain": [ " address car_num lat \n", "0 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372527 \\\n", "1 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372527 \n", "2 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372527 \n", "3 40, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372526 \n", "4 15, Vidyasagar St, Machuabazar, Kolkata, West ... jj 88.372552 \n", "\n", " long time date hour weekday \n", "0 22.580441 18:48:39 2023-05-02 18 1 \n", "1 22.580441 18:48:39 2023-05-02 18 1 \n", "2 22.580441 18:50:15 2023-05-02 18 1 \n", "3 22.580458 19:16:08 2023-05-02 19 1 \n", "4 22.580432 19:17:15 2023-05-02 19 1 " ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "x=df[['lat','long','weekday']]\n", "y= df['hour']" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "# adress_map={}\n", "# temp=[]\n", "# count=0;\n", "# for i in x['address']:\n", "\n" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
RandomForestRegressor(random_state=0)
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": [ "RandomForestRegressor(random_state=0)" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from sklearn.ensemble import RandomForestRegressor\n", " \n", "# create regressor object\n", "regressor = RandomForestRegressor(n_estimators=100, random_state=0)\n", "\n", "\n", " \n", "# fit the regressor with x and y data\n", "regressor.fit(x, y)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[18.08 18.08 18.08 18.64 18.97 18.97 18.97 19. 19. 19. 19. 19.\n", " 19. 19. 19. 19. 19. 19. 19. 19.89 19.89 16.99]\n", "0 18\n", "1 18\n", "2 18\n", "3 19\n", "4 19\n", "5 19\n", "6 19\n", "7 19\n", "8 19\n", "9 19\n", "10 19\n", "11 19\n", "12 19\n", "13 19\n", "14 19\n", "15 19\n", "16 19\n", "17 19\n", "18 19\n", "19 20\n", "20 20\n", "21 16\n", "Name: hour, dtype: int32\n" ] } ], "source": [ "print(regressor.predict(x))\n", "print(y)\n" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "adress= df['address']\n", "lat= df['lat']\n", "long= df['long']\n", "weekday= df['weekday']\n", "\n", "a1=[]\n", "lat1=[]\n", "long1=[]\n", "weekday1=[]\n", "\n", "\n", "\n", "i =0\n", "\n", "while i