Commit 76aebb17 authored by Alahakoon K.M.R.A.B's avatar Alahakoon K.M.R.A.B

Merge branch 'IT19049014' into 'master'

It19049014 to merge master branch

See merge request !11
parents 7ca78e9b 4f79a414
This diff is collapsed.
import pandas as pd
import numpy as np
from statsmodels.tsa.stattools import adfuller
from pmdarima import auto_arima
from statsmodels.tsa.arima.model import ARIMA
from sklearn.metrics import mean_squared_error
from math import sqrt
import warnings
warnings.filterwarnings("ignore")
df = pd.read_csv('data.csv', index_col='Date', parse_dates=True)
df = df.dropna()
print('Shape of data', df.shape)
print(df.head())
def adf_test(dataset):
dftest = adfuller(dataset, autolag='AIC')
print("1. ADF : ", dftest[0])
print("2. P-Value : ", dftest[1])
print("3. Num Of Lags : ", dftest[2])
print("4. Num Of Observations Used For ADF Regression and Critical Values Calculation :", dftest[3])
print("5. Critical Values :")
for key, val in dftest[4].items():
print("\t", key, ": ", val)
adf_test(df['no_of_vehicles'])
stepwise_fit = auto_arima(df['no_of_vehicles'], suppress_warnings=True)
print(stepwise_fit.summary())
print(df.shape)
train = df.iloc[:-30]
test = df.iloc[-30:]
print(train.shape, test.shape)
print(test.iloc[0], test.iloc[-1])
model = ARIMA(train['no_of_vehicles'], order=(1, 0, 0))
model = model.fit()
model.summary()
start = len(train)
end = len(train) + len(test) - 1
pred = model.predict(start=start, end=end, typ='levels').rename('ARIMA predictions')
# pred.index=index_future_dates
pred.plot(legend=True)
test['no_of_vehicles'].plot(legend=True)
rmse = sqrt(mean_squared_error(pred, test['no_of_vehicles']))
print(rmse)
model2 = ARIMA(df['no_of_vehicles'], order=(1, 0, 0))
model2 = model2.fit()
df.tail()
model2.save('no_of_vehicles.pkl')
Date,no_of_vehicles
2020.06.01,620
2020.06.02,586
2020.06.03,1061
2020.06.04,434
2020.06.05,597
2020.06.06,683
2020.06.07,447
2020.06.08,408
2020.06.09,788
2020.06.10,1019
2020.06.11,149
2020.06.12,813
2020.06.13,448
2020.06.14,119
2020.06.15,74
2020.06.16,565
2020.06.17,64
2020.06.18,928
2020.06.19,985
2020.06.20,271
2020.06.21,998
2020.06.22,294
2020.06.23,930
2020.06.24,71
2020.06.25,650
2020.06.26,440
2020.06.27,103
2020.06.28,196
2020.06.29,890
2020.06.30,170
2020.07.01,637
2020.07.02,134
2020.07.03,995
2020.07.04,104
2020.07.05,757
2020.07.06,334
2020.07.07,724
2020.07.08,1076
2020.07.09,16
2020.07.10,1076
2020.07.11,516
2020.07.12,792
2020.07.13,617
2020.07.14,221
2020.07.15,624
2020.07.16,457
2020.07.17,762
2020.07.18,736
2020.07.19,374
2020.07.20,404
2020.07.21,671
2020.07.22,867
2020.07.23,394
2020.07.24,716
2020.07.25,11
2020.07.26,904
2020.07.27,76
2020.07.28,755
2020.07.29,98
2020.07.30,481
2020.07.31,696
2020.08.01,446
2020.08.02,947
2020.08.03,1126
2020.08.04,1149
2020.08.05,939
2020.08.06,582
2020.08.07,841
2020.08.08,1011
2020.08.09,156
2020.08.10,1070
2020.08.11,167
2020.08.12,904
2020.08.13,165
2020.08.14,769
2020.08.15,609
2020.08.16,216
2020.08.17,948
2020.08.18,568
2020.08.19,1012
2020.08.20,826
2020.08.21,741
2020.08.22,694
2020.08.23,766
2020.08.24,961
2020.08.25,680
2020.08.26,21
2020.08.27,489
2020.08.28,21
2020.08.29,1061
2020.08.30,341
2020.08.31,1071
2020.09.01,510
2020.09.02,983
2020.09.03,1168
2020.09.04,65
2020.09.05,515
2020.09.06,233
2020.09.07,186
2020.09.08,1052
2020.09.09,366
2020.09.10,423
2020.09.11,55
2020.09.12,536
2020.09.13,589
2020.09.14,412
2020.09.15,545
2020.09.16,177
2020.09.17,968
2020.09.18,1063
2020.09.19,1156
2020.09.20,435
2020.09.21,703
2020.09.22,1104
2020.09.23,209
2020.09.24,454
2020.09.25,598
2020.09.26,615
2020.09.27,1155
2020.09.28,237
2020.09.29,261
2020.09.30,859
2020.10.01,1156
2020.10.02,1091
2020.10.03,901
2020.10.04,8
2020.10.05,249
2020.10.06,266
2020.10.07,739
2020.10.08,563
2020.10.09,858
2020.10.10,770
2020.10.11,1067
2020.10.12,1172
2020.10.13,559
2020.10.14,1067
2020.10.15,413
2020.10.16,569
2020.10.17,1031
2020.10.18,687
2020.10.19,415
2020.10.20,790
2020.10.21,899
2020.10.22,571
2020.10.23,707
2020.10.24,553
2020.10.25,900
2020.10.26,429
2020.10.27,1106
2020.10.28,1046
2020.10.29,139
2020.10.30,1125
2020.10.31,1061
2020.11.01,1003
2020.11.02,303
2020.11.03,747
2020.11.04,538
2020.11.05,433
2020.11.06,1160
2020.11.07,326
2020.11.08,254
2020.11.09,198
2020.11.10,92
2020.11.11,279
2020.11.12,417
2020.11.13,528
2020.11.14,549
2020.11.15,460
2020.11.16,542
2020.11.17,483
2020.11.18,187
2020.11.19,766
2020.11.20,68
2020.11.21,863
2020.11.22,1116
2020.11.23,93
2020.11.24,1147
2020.11.25,1026
2020.11.26,1144
2020.11.27,239
2020.11.28,961
2020.11.29,347
2020.11.30,190
2020.12.01,1034
2020.12.02,514
2020.12.03,234
2020.12.04,855
2020.12.05,465
2020.12.06,189
2020.12.07,344
2020.12.08,333
2020.12.09,850
2020.12.10,1170
2020.12.11,975
2020.12.12,1109
2020.12.13,1160
2020.12.14,1002
2020.12.15,419
2020.12.16,59
2020.12.17,779
2020.12.18,610
2020.12.19,738
2020.12.20,324
2020.12.21,613
2020.12.22,475
2020.12.23,494
2020.12.24,304
2020.12.25,236
2020.12.26,577
2020.12.27,328
2020.12.28,265
2020.12.29,1190
2020.12.30,532
2020.12.31,221
2021.01.01,64
2021.01.02,606
2021.01.03,187
2021.01.04,460
2021.01.05,274
2021.01.06,503
2021.01.07,983
2021.01.08,698
2021.01.09,1000
2021.01.10,1124
2021.01.11,923
2021.01.12,725
2021.01.13,137
2021.01.14,1032
2021.01.15,1118
2021.01.16,1141
2021.01.17,637
2021.01.18,716
2021.01.19,710
2021.01.20,803
2021.01.21,262
2021.01.22,384
2021.01.23,1194
2021.01.24,525
2021.01.25,404
2021.01.26,1048
2021.01.27,1019
2021.01.28,770
2021.01.29,634
2021.01.30,221
2021.01.31,815
2021.02.01,296
2021.02.02,345
2021.02.03,265
2021.02.04,875
2021.02.05,77
2021.02.06,583
2021.02.07,677
2021.02.08,148
2021.02.09,197
2021.02.10,974
2021.02.11,456
2021.02.12,717
2021.02.13,209
2021.02.14,363
2021.02.15,227
2021.02.16,909
2021.02.17,485
2021.02.18,662
2021.02.19,342
2021.02.20,1131
2021.02.21,410
2021.02.22,145
2021.02.23,488
2021.02.24,1041
2021.02.25,1117
2021.02.26,43
2021.02.27,180
2021.02.28,660
2021.03.01,546
2021.03.02,380
2021.03.03,895
2021.03.04,199
2021.03.05,535
2021.03.06,694
2021.03.07,812
2021.03.08,152
2021.03.09,877
2021.03.10,691
2021.03.11,430
2021.03.12,35
2021.03.13,147
2021.03.14,76
2021.03.15,803
2021.03.16,144
2021.03.17,923
2021.03.18,587
2021.03.19,337
2021.03.20,1162
2021.03.21,572
2021.03.22,1073
2021.03.23,248
2021.03.24,612
2021.03.25,238
2021.03.26,509
2021.03.27,502
2021.03.28,856
2021.03.29,607
2021.03.30,438
2021.03.31,525
2021.04.01,711
2021.04.02,257
2021.04.03,1190
2021.04.04,332
2021.04.05,721
2021.04.06,647
2021.04.07,788
2021.04.08,1165
2021.04.09,803
2021.04.10,442
2021.04.11,623
2021.04.12,780
2021.04.13,824
2021.04.14,631
2021.04.15,563
2021.04.16,739
2021.04.17,679
2021.04.18,988
2021.04.19,721
2021.04.20,871
2021.04.21,361
2021.04.22,674
2021.04.23,1043
2021.04.24,701
2021.04.25,982
2021.04.26,603
2021.04.27,95
2021.04.28,947
2021.04.29,617
2021.04.30,430
2021.05.01,1188
2021.05.02,1115
2021.05.03,720
2021.05.04,396
2021.05.05,54
2021.05.06,1033
2021.05.07,263
2021.05.08,729
2021.05.09,159
2021.05.10,272
2021.05.11,627
2021.05.12,187
2021.05.13,1018
2021.05.14,220
2021.05.15,721
2021.05.16,545
2021.05.17,220
2021.05.18,531
2021.05.19,738
2021.05.20,578
2021.05.21,604
2021.05.22,49
2021.05.23,299
2021.05.24,556
2021.05.25,534
2021.05.26,203
2021.05.27,741
2021.05.28,938
2021.05.29,1013
2021.05.30,1079
2021.05.31,218
2021.06.01,1198
2021.06.02,782
2021.06.03,60
2021.06.04,59
2021.06.05,528
2021.06.06,561
2021.06.07,33
2021.06.08,390
2021.06.09,375
2021.06.10,666
2021.06.11,58
2021.06.12,60
2021.06.13,113
2021.06.14,610
2021.06.15,742
2021.06.16,605
2021.06.17,674
2021.06.18,318
2021.06.19,666
2021.06.20,346
2021.06.21,849
2021.06.22,1024
2021.06.23,362
2021.06.24,608
2021.06.25,132
2021.06.26,898
2021.06.27,785
2021.06.28,590
2021.06.29,348
2021.06.30,375
\ No newline at end of file
from statsmodels.tsa.arima.model import ARIMAResults
import pandas as pd
from datetime import datetime, timedelta
model = ARIMAResults.load('component_3/no_of_vehicles.pkl')
def get_traffic_next_week():
no_of_days = 7
df = pd.read_csv('component_3/data.csv', index_col='Date', parse_dates=True)
df = df.dropna()
today = datetime.now()
n_days = today + timedelta(days=no_of_days)
index_future_dates = pd.date_range(start=today.strftime("%Y.%m.%d"), end=n_days.strftime("%Y.%m.%d"))
# print(index_future_dates)
pred = model.predict(start=len(df), end=len(df) + no_of_days,
typ='levels').rename('ARIMA Predictions')
# print(comp_pred)
pred.index = index_future_dates
output_value = []
for x in range(len(pred)):
output_value.append(round(pred[x], 2))
return output_value
# print(get_waiting_time())
import cv2
import torch
import time
import easyocr
import json
import random
import os
model = torch.hub.load('ultralytics/yolov5', 'custom', path='component_3/best_t.pt')
def get_number_plate():
# cap = cv2.VideoCapture(0) # from webcam
# print('start reading video')
# cap = cv2.VideoCapture('test_data/test.mp4') # from mp4 file
# ret, frame = cap.read()
sample_imgs = os.listdir('component_3/sample_data')
frame = cv2.imread('component_3/sample_data/' + str(random.choice(sample_imgs)))
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
result = model(image)
json_string = result.pandas().xyxy[0].to_json(orient='records')
json_obj = json.loads(json_string)
print(type(json_obj))
cropped_imgs = []
number_plate_text = 'None'
for i in json_obj:
print(i)
x = int(i["xmin"])
y = int(i["ymin"])
w = int(i["xmax"])
h = int(i["ymax"])
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
crop_img = image[y:y + h, x:x + w]
cropped_imgs.append(crop_img)
for cropped_img in cropped_imgs:
cv2.imwrite('save.png', cropped_img)
try:
reader = easyocr.Reader(['en'])
result = reader.readtext('save.png')
for i in result:
print(i[1])
if result[0][1] is not None:
number_plate_text = result[0][1]
else:
print('not readable by ocr')
number_plate_text = 'None'
except:
print('not readable by ocr')
number_plate_text = 'None'
print(number_plate_text)
return number_plate_text
# get_number_plate()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment