Spaces:
Sleeping
Sleeping
File size: 17,598 Bytes
b489e00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
{
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>address</th>\n",
" <th>car_num</th>\n",
" <th>lat</th>\n",
" <th>long</th>\n",
" <th>time</th>\n",
" <th>date</th>\n",
" <th>hour</th>\n",
" <th>weekday</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372527</td>\n",
" <td>22.580441</td>\n",
" <td>18:48:39</td>\n",
" <td>2023-05-02</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372527</td>\n",
" <td>22.580441</td>\n",
" <td>18:48:39</td>\n",
" <td>2023-05-02</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372527</td>\n",
" <td>22.580441</td>\n",
" <td>18:50:15</td>\n",
" <td>2023-05-02</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372526</td>\n",
" <td>22.580458</td>\n",
" <td>19:16:08</td>\n",
" <td>2023-05-02</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>15, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372552</td>\n",
" <td>22.580432</td>\n",
" <td>19:17:15</td>\n",
" <td>2023-05-02</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>address</th>\n",
" <th>car_num</th>\n",
" <th>lat</th>\n",
" <th>long</th>\n",
" <th>time</th>\n",
" <th>date</th>\n",
" <th>hour</th>\n",
" <th>weekday</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372527</td>\n",
" <td>22.580441</td>\n",
" <td>18:48:39</td>\n",
" <td>2023-05-02</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372527</td>\n",
" <td>22.580441</td>\n",
" <td>18:48:39</td>\n",
" <td>2023-05-02</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372527</td>\n",
" <td>22.580441</td>\n",
" <td>18:50:15</td>\n",
" <td>2023-05-02</td>\n",
" <td>18</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>40, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372526</td>\n",
" <td>22.580458</td>\n",
" <td>19:16:08</td>\n",
" <td>2023-05-02</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>15, Vidyasagar St, Machuabazar, Kolkata, West ...</td>\n",
" <td>jj</td>\n",
" <td>88.372552</td>\n",
" <td>22.580432</td>\n",
" <td>19:17:15</td>\n",
" <td>2023-05-02</td>\n",
" <td>19</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": [
"<style>#sk-container-id-2 {color: black;background-color: white;}#sk-container-id-2 pre{padding: 0;}#sk-container-id-2 div.sk-toggleable {background-color: white;}#sk-container-id-2 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-2 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-2 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-2 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-2 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-2 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-2 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-2 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-2 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-2 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-2 div.sk-item {position: relative;z-index: 1;}#sk-container-id-2 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-2 div.sk-item::before, #sk-container-id-2 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-2 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-2 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-2 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-2 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-2 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-2 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-2 div.sk-label-container {text-align: center;}#sk-container-id-2 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-2 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestRegressor(random_state=0)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestRegressor</label><div class=\"sk-toggleable__content\"><pre>RandomForestRegressor(random_state=0)</pre></div></div></div></div></div>"
],
"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<len(adress):\n",
" if adress[i] == '40, Vidyasagar St, Machuabazar, Kolkata, West Bengal 700009, India':\n",
" a1.append(adress[i])\n",
" lat1.append(lat[i])\n",
" long1.append(long[i])\n",
" weekday1.append(weekday[i])\n",
" break\n",
" i=i+1\n",
"\n",
"df2= pd.DataFrame({'lat':lat1,'long':long1,'weekday':weekday1})\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[18.08]\n"
]
}
],
"source": [
"print(regressor.predict(df2))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|