In [1]:
import pandas as pd
import numpy as np
import seaborn as sns
import src.misc.paths as path

%matplotlib inline

import src.vector_gen.generateTimeInformationVector as gtiv
import src.vector_gen.generate_VectorY as gvy

from keras.layers import Dense, Activation
from keras.models import Sequential
from sklearn import preprocessing
from src.misc.evaluation import mape, mape2


Using TensorFlow backend.

load data


In [2]:
csv_files_folder = "./src/misc/splitting_csv_files/"
train_X = pd.read_csv(csv_files_folder+"train_X.csv", index_col=0).as_matrix()
train_Y = pd.read_csv(csv_files_folder+"train_Y.csv", index_col=0).as_matrix()
test_X = pd.read_csv(csv_files_folder+"test_X.csv", index_col=0).as_matrix()
test_Y = pd.read_csv(csv_files_folder+"test_Y.csv", index_col=0).as_matrix()

In [3]:
print(train_X.shape)


(864, 3)

In [4]:
print(train_Y.shape)


(864, 36)

Features


In [5]:
feature_cols = ['hour', 'minute', 'weekday']
y_cols = [
    ('00:00', 'A2'), ('00:00', 'A3'), ('00:00', 'B1'), ('00:00', 'B3'), ('00:00', 'C1'), ('00:00', 'C3'),
    ('00:20', 'A2'), ('00:20', 'A3'), ('00:20', 'B1'), ('00:20', 'B3'), ('00:20', 'C1'), ('00:20', 'C3'),
    ('00:40', 'A2'), ('00:40', 'A3'), ('00:40', 'B1'), ('00:40', 'B3'), ('00:40', 'C1'), ('00:40', 'C3'),
    ('01:00', 'A2'), ('01:00', 'A3'), ('01:00', 'B1'), ('01:00', 'B3'), ('01:00', 'C1'), ('01:00', 'C3'),
    ('01:20', 'A2'), ('01:20', 'A3'), ('01:20', 'B1'), ('01:20', 'B3'), ('01:20', 'C1'), ('01:20', 'C3'),
    ('01:40', 'A2'), ('01:40', 'A3'), ('01:40', 'B1'), ('01:40', 'B3'), ('01:40', 'C1'), ('01:40', 'C3')]

create model


In [6]:
min_max_scaler = preprocessing.MinMaxScaler()
min_max_scaler.fit(np.concatenate((train_X, test_X)))

train_X_scale = min_max_scaler.transform(train_X)
test_X_scale = min_max_scaler.transform(test_X)


C:\Anaconda3\lib\site-packages\sklearn\utils\validation.py:429: DataConversionWarning: Data with input dtype int64 was converted to float64 by MinMaxScaler.
  warnings.warn(msg, _DataConversionWarning)

In [7]:
model = Sequential()
#0.269477
#model.add(Dense(input_dim=3, output_dim=84, activation='relu'))
#model.add(Dense(input_dim=84, output_dim=300, activation='relu'))
#model.add(Dense(input_dim=300, output_dim=84, activation='relu'))
#model.add(Dense(input_dim=84, output_dim=36, activation='relu'))

#0.270922
#model.add(Dense(input_dim=3, output_dim=100, activation='relu'))
#model.add(Dense(input_dim=100, output_dim=300, activation='relu'))
#model.add(Dense(input_dim=300, output_dim=100, activation='relu'))
#model.add(Dense(input_dim=100, output_dim=36, activation='relu'))

#0.597166
#model.add(Dense(input_dim=3, output_dim=100, activation='relu'))
#model.add(Dense(input_dim=100, output_dim=36, activation='relu'))

#0.570687
#model.add(Dense(input_dim=3, output_dim=1000, activation='relu'))
#model.add(Dense(input_dim=1000, output_dim=36, activation='relu'))

#0.258006676742
model.add(Dense(input_dim=3, output_dim=84, activation='relu'))
model.add(Dense(input_dim=84, output_dim=300, activation='relu'))
model.add(Dense(input_dim=300, output_dim=300, activation='relu'))
model.add(Dense(input_dim=300, output_dim=300, activation='relu'))
model.add(Dense(input_dim=300, output_dim=300, activation='relu'))
model.add(Dense(input_dim=300, output_dim=300, activation='relu'))
model.add(Dense(input_dim=300, output_dim=84, activation='relu'))
model.add(Dense(input_dim=84, output_dim=36, activation='relu'))


# For a multi-class classification problem
# Before training a model, you need to configure the learning process, which is done via the compile method
model.compile(loss='mean_absolute_percentage_error', optimizer='rmsprop')


C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:23: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=84, activation="relu", input_dim=3)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:24: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=300, activation="relu", input_dim=84)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:25: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=300, activation="relu", input_dim=300)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:26: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=300, activation="relu", input_dim=300)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:27: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=300, activation="relu", input_dim=300)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:28: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=300, activation="relu", input_dim=300)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:29: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=84, activation="relu", input_dim=300)`
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:30: UserWarning: Update your `Dense` call to the Keras 2 API: `Dense(units=36, activation="relu", input_dim=84)`

train model


In [8]:
model.fit(train_X_scale, train_Y,
          batch_size=1, epochs=40, verbose=0,
          validation_data=(test_X_scale, test_Y))

y_prediction = model.predict(test_X_scale, batch_size=1, verbose=2)

#y_prediction = y_prediction.astype('float64')
mymape = mape2(y_prediction, test_Y)
print(mymape)


196/204 [===========================>..] - ETA: 0s0.258006676742

In [63]:
test_Y


Out[63]:
array([[ 100.75      ,   85.31999969,   15.57999992, ...,   62.77999878,
          12.14000034,    7.78000021],
       [  55.88999939,   76.19999695,    9.90999985, ...,   73.27999878,
         166.07000732,   33.        ],
       [  47.52999878,   77.73000336,  116.04000092, ...,  104.37000275,
         133.55000305,   60.59999847],
       ..., 
       [  64.09999847,  123.62999725,  120.15000153, ...,   78.72000122,
          74.70999908,   57.90000153],
       [  64.01000214,  103.63999939,   35.65000153, ...,   90.29000092,
          35.91999817,   21.77000046],
       [  59.61000061,   89.41000366,   95.70999908, ...,   22.18000031,
          18.97999954,    8.17000008]], dtype=float32)

In [64]:
y_prediction


Out[64]:
array([[  40.21813202,   36.46603394,   16.05171967, ...,    0.        ,
          12.59272861,    8.05186749],
       [  47.5795784 ,   49.30667496,   10.07021809, ...,    0.        ,
          68.48070526,   33.73544312],
       [  52.23166656,   92.90644073,   62.33463669, ...,    0.        ,
         137.5453949 ,   64.19611359],
       ..., 
       [  65.1662674 ,  109.8110199 ,   71.34067535, ...,    0.        ,
          74.45367432,   67.31396484],
       [  55.88864517,   88.38116455,   43.12081146, ...,    0.        ,
          41.98317337,   28.88004494],
       [  47.31322479,   68.4859314 ,   21.01136017, ...,    0.        ,
          17.83046913,    7.75364113]])

evaluate


In [17]:
y_test_predict = regr_multi_svr.predict(x_test)

y_test_predict_df = pd.DataFrame(y_test_predict, columns=y_cols)
y_test_predict_df.head()


Out[17]:
(0, A2) (0, A3) (0, B1) (0, B3) (0, C1) (0, C3) (1, A2) (1, A3) (1, B1) (1, B3) ... (4, B1) (4, B3) (4, C1) (4, C3) (5, A2) (5, A3) (5, B1) (5, B3) (5, C1) (5, C3)
0 46.025391 60.064694 18.624742 50.165473 38.504617 27.914778 41.904651 82.014838 16.135032 52.339146 ... 20.834479 39.415504 21.364780 16.204721 27.074640 57.165415 9.924544 22.184935 18.974734 8.164814
1 37.101425 35.275227 15.584786 28.744548 8.354545 17.125012 42.644986 35.204763 10.374562 25.514648 ... 11.054890 31.364840 13.864653 11.754970 47.235217 52.984261 12.014673 29.134891 12.134626 7.774778
2 48.704799 45.884741 9.915024 23.754957 15.554647 9.834902 51.954573 40.295065 30.234905 35.974643 ... 22.544770 55.532948 30.064732 26.144735 52.045095 85.816422 36.274551 71.509276 68.082869 33.005233
3 48.215322 94.074957 68.922185 77.114709 74.694871 42.834633 56.207525 104.935183 64.274967 86.365208 ... 92.301355 86.172414 92.154937 72.124704 62.645088 129.905189 69.425345 113.054598 145.755387 60.594503
4 81.604858 136.554499 97.055292 109.397514 151.384817 87.912526 76.735156 133.515126 81.164844 107.894640 ... 104.305255 127.415765 162.299043 120.937280 70.104845 132.455018 95.014935 115.304689 134.879393 108.184905

5 rows × 36 columns


In [16]:
from sklearn import metrics

print(metrics.mean_absolute_error(y_test_predict, y_test))
print(metrics.mean_squared_error(y_test_predict, y_test))

import src.misc.evaluation as ev
mymape = ev.mape(y_test_predict, y_test)
print(np.mean(np.array(mymape)))


28.10626237
2815.47733885
0.209518459546

In [21]:
y_test_predict_df


Out[21]:
(0, A2) (0, A3) (0, B1) (0, B3) (0, C1) (0, C3) (1, A2) (1, A3) (1, B1) (1, B3) ... (4, B1) (4, B3) (4, C1) (4, C3) (5, A2) (5, A3) (5, B1) (5, B3) (5, C1) (5, C3)
0 46.025391 60.064694 18.624742 50.165473 38.504617 27.914778 41.904651 82.014838 16.135032 52.339146 ... 20.834479 39.415504 21.364780 16.204721 27.074640 57.165415 9.924544 22.184935 18.974734 8.164814
1 37.101425 35.275227 15.584786 28.744548 8.354545 17.125012 42.644986 35.204763 10.374562 25.514648 ... 11.054890 31.364840 13.864653 11.754970 47.235217 52.984261 12.014673 29.134891 12.134626 7.774778
2 48.704799 45.884741 9.915024 23.754957 15.554647 9.834902 51.954573 40.295065 30.234905 35.974643 ... 22.544770 55.532948 30.064732 26.144735 52.045095 85.816422 36.274551 71.509276 68.082869 33.005233
3 48.215322 94.074957 68.922185 77.114709 74.694871 42.834633 56.207525 104.935183 64.274967 86.365208 ... 92.301355 86.172414 92.154937 72.124704 62.645088 129.905189 69.425345 113.054598 145.755387 60.594503
4 81.604858 136.554499 97.055292 109.397514 151.384817 87.912526 76.735156 133.515126 81.164844 107.894640 ... 104.305255 127.415765 162.299043 120.937280 70.104845 132.455018 95.014935 115.304689 134.879393 108.184905
5 68.993439 122.081918 109.327471 114.807154 142.535469 105.851533 62.504984 113.284961 91.985390 120.555214 ... 84.164574 95.344585 151.727357 102.335383 55.064656 102.595495 86.684865 98.605718 148.320280 88.354910
6 55.655196 101.992542 91.995231 110.554613 162.010270 114.055235 51.095199 97.935420 100.332704 107.985303 ... 91.935764 108.854934 160.261135 165.984759 64.735347 107.054865 88.492043 112.934960 139.445309 140.795178
7 63.334766 109.774921 105.575227 114.413915 148.930540 158.215337 62.964668 111.864695 110.484878 119.564614 ... 118.184549 111.812451 148.833140 169.315326 67.065795 106.848756 79.985546 103.305180 142.607235 125.784836
8 70.746158 107.182945 78.765416 104.145482 144.064874 151.613248 64.884916 107.275413 97.816438 117.144607 ... 91.606676 107.874585 133.402992 115.541559 64.983969 112.414810 97.864816 109.295274 141.045427 137.850112
9 77.004578 112.625191 79.000318 103.114660 117.725286 122.439355 64.734764 115.915125 69.724952 106.597333 ... 62.145180 87.025073 83.934783 79.104497 64.455441 125.554888 53.770227 98.988292 83.934881 90.565054
10 63.614880 102.015266 70.775148 94.535185 112.312762 72.644880 61.804983 108.464743 59.015292 84.805397 ... 61.555227 96.465117 114.645229 65.924986 57.207917 108.165024 61.912438 93.425915 74.715357 57.904818
11 51.225106 86.324892 35.654856 84.704855 83.335388 51.674728 53.800341 83.134981 37.174551 62.195326 ... 32.594541 61.424897 28.594864 34.714613 46.085206 73.290642 23.504744 39.475235 35.925177 21.764510
12 49.584614 81.055274 18.625159 50.164889 38.505351 27.915378 36.992307 76.908283 16.135421 45.355154 ... 20.835234 39.414876 21.365125 16.205312 31.575289 63.233290 9.925451 22.185260 18.985227 8.175474
13 41.355195 35.274918 15.585320 30.787789 8.364990 17.125379 48.796134 48.444677 10.385421 25.515463 ... 11.065291 31.365518 13.875188 11.765294 55.892589 71.914699 12.015331 29.135331 12.145089 7.785468
14 52.970179 65.325386 9.915331 23.755225 15.555098 9.845418 53.045438 40.294837 30.234734 35.975274 ... 22.545403 63.291368 30.075238 26.155439 47.386777 72.394721 36.275322 48.226566 67.514960 33.004484
15 49.534719 97.474518 56.344684 83.668421 74.695357 42.835475 54.835595 114.574240 67.073634 93.754599 ... 85.763817 83.344656 98.556053 74.016930 71.944663 128.134602 74.375057 100.784990 144.464940 60.605062
16 72.617758 136.554904 99.484938 104.165037 136.856553 82.542852 75.794773 138.807675 81.165346 111.235267 ... 95.515022 130.034694 157.695375 104.675011 67.996004 125.045355 106.544937 111.124933 159.994874 127.849263
17 67.385324 111.104999 105.994964 103.825230 148.514437 100.985162 64.795157 112.645226 91.985003 116.374720 ... 81.455069 96.205046 145.205162 106.703818 55.324827 107.664921 92.026552 103.144797 156.812001 101.093687
18 56.974593 104.195002 83.065400 101.635101 158.114999 139.499196 54.754767 104.934540 98.404628 102.264822 ... 89.114869 115.307646 158.185322 158.537415 62.554916 121.760928 88.008576 110.595377 156.076103 157.136539
19 66.645235 111.710031 112.104555 111.134979 147.605403 162.494731 58.935355 112.985259 101.205469 117.825140 ... 106.824804 111.185402 149.834797 171.899244 64.875107 111.114957 71.685023 98.188766 152.785094 141.845178
20 67.115119 109.497847 104.037521 107.244999 145.479019 167.178236 68.425839 110.775073 89.454764 115.155395 ... 90.694507 110.340233 128.333047 117.268930 69.940688 111.871112 92.587263 105.772118 132.854572 139.875426
21 70.994125 110.884505 77.425046 109.185142 117.724687 100.269691 57.675597 116.931996 69.725416 109.154861 ... 62.144880 92.822543 84.971006 80.391325 64.327087 123.445196 52.305063 96.254937 83.935265 90.564640
22 59.284715 106.864612 62.675521 100.318451 106.440094 72.645380 60.814167 113.435140 59.014985 101.665005 ... 69.719909 97.695542 114.644638 65.924708 54.564609 108.165326 50.814643 79.320990 75.589786 57.905292
23 55.444763 81.725219 35.655237 87.725062 83.334776 51.675442 54.729272 84.614628 37.175226 62.194761 ... 32.595235 63.761270 28.595428 34.715442 44.862038 71.805369 23.505204 39.474772 37.215361 21.775418
24 46.648841 77.504886 18.624723 60.421678 38.504791 27.904955 36.435454 71.080652 16.134768 48.607499 ... 20.834766 39.415434 21.354775 16.194886 29.064741 45.094698 9.924829 22.174634 18.974665 8.164526
25 45.185066 35.275218 15.584673 28.745364 8.354652 17.114634 43.726452 36.717018 10.384953 25.514681 ... 11.064970 31.364879 13.864677 11.764672 56.324845 61.594460 12.014611 29.134650 12.134787 7.774679
26 51.535358 77.283107 9.914728 23.754860 15.544654 9.834649 49.865008 40.295340 35.220229 35.974798 ... 22.544853 69.541150 30.074919 26.144973 48.445314 76.284725 36.274887 48.224661 67.515389 33.005273
27 47.635354 97.135466 56.344610 75.800649 74.694603 42.834913 52.034843 105.464922 82.011465 92.035385 ... 83.905368 96.374734 93.050446 72.125168 74.362352 134.464741 87.334568 105.936959 159.908733 60.604499
28 68.534961 136.721263 114.695801 102.223900 128.055340 64.315173 78.575355 145.434186 104.574878 111.234575 ... 89.266186 127.779991 155.772324 104.675362 71.414890 113.884766 118.056829 110.234645 165.050611 126.385215
29 67.474508 102.135249 109.805268 103.824862 163.284855 100.985072 69.408111 111.284925 118.215337 112.665346 ... 88.404827 99.744804 152.662904 93.075009 55.264846 105.487531 89.665462 105.485378 151.585032 104.835962
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
53 73.032505 107.665043 106.594851 109.725506 163.211901 138.255109 70.935393 117.975378 105.189091 108.944627 ... 94.387241 96.204805 159.385023 133.506646 64.135029 105.094771 106.025399 100.545129 155.953277 98.882930
54 59.554562 103.126635 98.935309 90.104433 153.294743 91.154642 57.485018 102.585003 105.617535 106.215013 ... 112.804675 112.491368 182.785362 159.366191 61.825069 98.075002 103.487501 111.625261 170.784937 162.846374
55 66.269198 109.145429 128.349289 122.074684 165.626622 160.716551 64.224927 113.055182 133.404558 108.015223 ... 97.235388 118.755701 174.003541 127.149821 65.054777 105.644720 109.484727 117.233157 171.125017 158.728937
56 70.393641 108.926722 89.341654 124.289497 141.907311 173.135367 62.285127 125.343577 108.324710 109.584919 ... 66.654609 107.684448 139.195682 128.754968 65.445053 120.155532 93.324642 106.681421 160.084888 131.485298
57 60.645342 105.424755 110.571680 110.384710 168.805121 114.380712 64.174947 115.924718 79.236132 105.535167 ... 62.144764 109.474846 84.827335 79.105254 67.064900 106.514962 52.304836 105.145425 83.934722 112.588119
58 55.556121 107.445303 62.675359 106.865088 90.825303 90.789404 57.085045 104.835265 85.994812 94.064162 ... 84.335401 93.384779 114.645204 84.545570 52.045324 108.175015 46.815227 93.614818 74.714681 57.904886
59 54.785383 89.635143 35.654809 84.361907 92.652082 51.674908 50.555442 82.624705 37.175133 83.794792 ... 32.594844 81.134668 28.584719 34.714553 42.987497 62.065241 23.494662 39.474690 35.924746 21.774950
60 50.614687 75.485041 18.624704 55.677646 38.505330 27.914880 44.323843 73.404906 16.134993 45.354795 ... 20.835390 39.415009 21.365299 16.205237 41.034936 57.767224 9.925383 22.184696 18.985465 8.175352
61 37.534726 35.275203 15.585126 28.745363 8.364690 17.125338 38.660836 35.204597 10.384849 25.515236 ... 11.065226 31.364997 13.875243 11.764490 47.245257 59.839814 12.015332 29.134665 12.145083 7.785375
62 51.524920 45.884862 9.915299 23.754955 15.554841 9.844960 49.874950 52.977101 30.234884 37.296780 ... 22.544629 48.195340 30.075086 26.154707 50.834684 93.074961 36.274569 48.224762 67.514862 33.004837
63 39.044760 86.804848 56.345426 79.914840 120.289586 42.834681 54.504722 107.265339 64.275477 83.665016 ... 90.614957 86.075032 159.725197 72.125059 63.058138 102.962373 72.725212 105.925104 133.554964 105.398942
64 64.335179 111.924812 105.005254 104.175058 155.644863 104.664897 62.268121 110.625146 110.814981 103.514453 ... 116.855125 113.514661 162.274896 143.387552 71.035229 124.824870 87.745051 99.595293 166.085152 150.864836
65 66.644772 111.347177 89.804972 103.824748 141.945024 150.309832 69.154986 115.144917 100.864789 107.045245 ... 74.904652 96.204799 155.635380 136.907155 60.175168 101.395019 93.394985 99.744928 149.965057 88.355201
66 50.855001 114.695272 96.954677 95.715021 148.265072 111.044639 62.802585 105.701067 98.404919 97.610986 ... 110.614652 106.214843 172.784934 145.835351 59.344863 107.044753 85.155044 110.835747 163.144807 182.144705
67 65.395145 110.175155 111.296905 122.214670 149.774760 160.814933 60.695597 102.814950 101.205284 107.595471 ... 90.475042 103.254891 157.983222 137.874525 60.414776 106.014720 96.839506 102.655030 158.304921 147.667969
68 66.485014 110.715048 78.764526 107.244528 129.255446 152.836551 64.514997 112.644913 97.091447 106.495049 ... 66.655450 100.495393 128.545170 125.517941 61.274922 117.145022 82.135065 107.975148 174.415294 123.934849
69 59.974717 110.605082 106.224954 102.735052 150.645246 95.014845 62.195225 111.855992 89.034654 119.644985 ... 62.145292 88.254581 83.934847 79.104948 66.215371 102.145371 52.304683 96.834839 83.934611 96.445045
70 54.894737 102.005396 62.675122 94.534771 97.684344 114.113797 55.449772 112.214650 70.691577 94.664702 ... 67.760254 86.434777 114.644783 65.924976 54.064772 108.164702 65.659562 79.155029 74.714939 57.905063
71 53.745157 86.294591 35.655010 68.855382 118.882101 51.675237 53.804992 83.635983 37.174622 73.365314 ... 32.595212 89.672200 28.594671 34.715083 41.334913 72.714854 23.504659 51.564165 35.925155 21.775120
72 46.015113 60.065164 18.625188 76.124626 38.505032 27.914674 47.840922 86.145141 16.135024 45.354981 ... 20.835015 39.414921 21.365231 16.204966 27.075138 45.094928 9.924949 22.185209 18.984933 8.175031
73 37.095429 54.117722 15.584808 28.745154 8.365033 17.125034 40.319679 35.204708 10.384559 25.514644 ... 11.065210 31.364924 13.874806 11.765251 47.504932 46.124933 12.015407 29.135299 12.144986 7.785287
74 51.525115 56.730948 9.915137 34.541980 15.554885 9.845044 50.990002 56.830737 41.318366 35.974936 ... 22.545307 67.144830 30.075085 26.155105 63.205232 115.214623 36.274990 67.794843 87.233600 33.004865
75 44.394920 94.284847 82.344714 62.565303 74.695437 42.834630 55.594971 102.494648 64.274584 83.664868 ... 95.494670 103.894997 92.154808 76.436185 69.624817 144.174416 86.025044 117.455064 145.799208 60.605094
76 92.823365 146.384773 97.064847 109.754664 157.488364 64.314579 84.154736 125.954923 89.375127 106.855252 ... 104.945847 132.592230 149.254877 154.094643 74.712049 130.355339 106.845268 118.984924 132.774966 108.184630
77 76.724647 138.489339 109.235110 121.304800 145.644770 100.984980 68.764906 115.725405 121.705096 118.164630 ... 99.831104 110.955385 142.964856 93.074945 59.387698 103.475045 80.955218 103.724942 128.405173 137.045391
78 60.214728 103.295394 90.506080 96.244852 155.714878 96.015422 61.004914 109.635000 106.064677 112.164699 ... 89.115208 106.644820 153.954620 123.634960 61.705111 107.044927 91.495201 109.545266 139.444645 140.794600
79 55.134878 101.255281 109.356330 100.915506 147.604864 137.164627 66.474923 115.555159 101.205155 95.725061 ... 100.059361 107.584778 145.364910 171.154907 64.755409 106.171717 76.218193 110.664661 137.865085 125.785347
80 65.474796 102.924898 89.674694 106.855186 154.495339 146.464684 60.814823 105.444977 80.495167 103.225000 ... 66.654759 100.495331 128.894661 103.154815 62.214965 118.194789 82.134654 106.505071 135.485175 107.454883
81 61.955219 110.884853 77.424737 107.495292 117.724926 143.267696 68.984999 109.865925 69.725257 107.094692 ... 78.105965 86.275298 83.934611 79.105254 63.534928 118.534889 52.304910 104.665270 83.935387 90.564895
82 62.315414 106.174799 62.675070 94.534711 90.825337 72.645120 57.474683 106.685298 59.014808 84.754844 ... 61.554743 90.110303 115.895968 65.924942 53.055015 108.165369 46.814974 81.245272 74.714989 57.905387

83 rows × 36 columns


In [40]:
y_test


Out[40]:
(0, A2) (0, A3) (0, B1) (0, B3) (0, C1) (0, C3) (1, A2) (1, A3) (1, B1) (1, B3) ... (4, B1) (4, B3) (4, C1) (4, C3) (5, A2) (5, A3) (5, B1) (5, B3) (5, C1) (5, C3)
2016-10-11 00:00:00 52.28 60.06 18.62 50.16 38.50 27.91 37.07 107.80 16.13 103.27 ... 20.83 39.41 21.36 16.20 27.07 45.09 69.89 94.61 18.98 8.17
2016-10-11 02:00:00 37.09 35.27 15.58 28.74 8.36 17.12 52.36 35.20 10.38 75.56 ... 11.06 31.36 13.87 11.76 53.40 46.12 99.88 29.13 12.14 7.78
2016-10-11 04:00:00 38.38 45.88 9.91 23.75 15.55 9.84 53.69 40.29 30.23 35.97 ... 22.54 48.19 164.07 156.45 41.32 77.45 90.51 48.22 206.02 33.00
2016-10-11 06:00:00 44.41 97.47 125.78 62.56 74.69 42.83 32.56 127.90 96.05 71.58 ... 127.86 143.01 158.56 72.12 50.97 137.73 134.92 110.76 173.09 190.27
2016-10-11 08:00:00 68.09 146.16 86.56 142.52 158.31 64.31 75.02 168.43 127.10 93.00 ... 120.29 104.09 129.01 202.18 70.26 121.44 93.94 133.37 166.25 117.08
2016-10-11 10:00:00 58.42 134.14 128.12 133.50 241.20 100.98 59.50 122.61 96.85 231.31 ... 97.47 93.11 202.58 93.07 72.78 96.14 102.81 102.93 145.38 132.98
2016-10-11 12:00:00 62.17 168.92 140.94 81.62 159.03 206.08 67.42 105.85 134.51 129.76 ... 101.64 106.02 188.35 123.63 61.31 122.76 106.54 103.98 198.28 132.72
2016-10-11 14:00:00 63.76 84.14 131.75 160.78 198.61 159.13 70.16 104.73 106.43 110.78 ... 120.09 113.49 177.20 124.07 80.86 112.35 107.40 124.56 186.99 151.44
2016-10-11 16:00:00 66.96 102.97 85.30 97.92 151.63 143.58 85.57 100.22 93.09 130.13 ... 111.53 103.08 193.29 183.23 67.00 146.57 254.55 76.11 230.08 218.23
2016-10-11 18:00:00 48.92 112.86 204.27 113.66 250.10 95.01 121.45 280.83 126.37 64.97 ... 128.57 129.44 160.61 79.10 77.23 115.81 128.59 102.91 170.00 207.18
2016-10-11 20:00:00 88.02 98.23 108.57 95.91 153.19 72.64 53.83 104.47 93.71 84.75 ... 61.55 268.29 161.02 122.44 74.66 91.72 350.79 120.55 201.53 218.45
2016-10-11 22:00:00 54.76 95.40 148.41 86.69 162.99 51.67 48.85 97.33 37.17 86.00 ... 32.59 136.46 137.63 34.71 50.05 62.06 23.50 39.47 35.92 111.98
2016-10-12 00:00:00 53.89 55.96 18.62 83.32 38.50 27.91 69.38 64.30 16.13 45.35 ... 20.83 39.41 21.36 16.20 27.07 67.30 9.92 22.18 18.98 8.17
2016-10-12 02:00:00 35.75 35.27 15.58 28.74 8.36 17.12 57.34 89.27 10.38 105.41 ... 11.06 83.37 13.87 11.76 60.73 46.12 12.01 29.13 12.14 7.78
2016-10-12 04:00:00 41.58 82.20 9.91 23.75 15.55 9.84 42.86 40.29 30.23 35.97 ... 97.33 87.31 188.20 26.15 58.03 99.03 36.27 48.22 67.51 33.00
2016-10-12 06:00:00 49.68 93.64 100.25 84.28 74.69 42.83 45.53 135.08 64.27 98.94 ... 73.54 73.71 92.15 110.15 63.15 138.92 69.42 153.30 143.44 60.60
2016-10-12 08:00:00 86.16 171.63 117.33 84.05 146.38 175.34 83.28 189.11 184.11 156.47 ... 132.43 168.48 116.31 104.67 65.32 143.11 87.74 156.67 194.99 215.89
2016-10-12 10:00:00 94.91 131.99 107.56 104.83 121.63 209.00 58.60 99.85 106.44 117.59 ... 64.19 76.81 242.19 140.85 57.23 111.28 104.02 110.46 176.85 88.35
2016-10-12 12:00:00 55.71 81.89 120.83 92.75 180.54 174.42 61.98 100.87 82.99 26.74 ... 132.50 103.32 142.53 176.53 64.27 112.77 85.15 103.29 139.48 160.53
2016-10-12 14:00:00 71.25 105.32 113.41 92.04 172.53 115.48 62.77 109.13 142.55 87.21 ... 96.16 81.32 221.58 218.83 50.12 99.73 143.76 95.90 151.01 141.39
2016-10-12 16:00:00 60.51 97.40 126.86 86.15 153.51 170.92 57.58 83.99 111.50 111.87 ... 66.65 93.10 172.73 148.58 78.55 114.99 110.97 103.29 171.72 196.05
2016-10-12 18:00:00 81.69 113.32 127.47 160.28 186.11 146.06 52.32 112.96 132.60 87.50 ... 62.14 102.74 169.59 203.03 67.94 101.71 52.30 51.49 196.28 90.56
2016-10-12 20:00:00 76.01 100.00 89.78 82.10 183.10 72.64 57.85 110.36 130.23 113.44 ... 96.42 97.17 162.05 65.92 66.46 89.55 46.81 98.05 74.71 57.90
2016-10-12 22:00:00 58.35 112.08 35.65 68.51 156.96 51.67 35.44 46.24 96.12 71.62 ... 99.06 80.30 112.53 34.71 42.57 56.12 23.50 121.04 35.92 21.77
2016-10-13 00:00:00 74.92 60.06 18.62 50.16 38.50 27.91 46.58 91.02 16.13 45.35 ... 20.83 39.41 21.36 16.20 50.53 45.09 94.23 22.18 18.98 97.82
2016-10-13 02:00:00 129.60 93.48 15.58 28.74 145.63 17.12 52.09 95.52 10.38 25.51 ... 68.08 31.36 13.87 11.76 73.72 46.12 12.01 29.13 12.14 7.78
2016-10-13 04:00:00 54.43 73.95 9.91 23.75 142.71 9.84 57.76 106.28 100.69 35.97 ... 22.54 107.66 30.07 26.15 37.66 87.00 36.27 95.92 67.51 33.00
2016-10-13 06:00:00 54.31 121.44 119.71 62.56 127.55 42.83 77.89 92.64 138.09 83.66 ... 140.66 16.85 92.15 119.28 87.81 114.64 102.54 106.15 214.35 212.35
2016-10-13 08:00:00 82.59 176.52 117.33 113.20 169.92 194.72 85.20 105.61 119.43 82.62 ... 109.39 67.84 176.34 104.67 67.78 96.76 146.40 107.55 152.02 187.55
2016-10-13 10:00:00 65.09 105.11 137.43 82.42 182.90 159.94 61.71 119.30 121.10 117.33 ... 178.25 110.95 149.97 93.07 53.17 144.99 107.04 104.34 134.46 137.87
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2016-10-15 10:00:00 141.55 479.41 193.03 82.13 130.52 195.73 142.34 225.43 215.81 80.56 ... 102.47 99.52 183.99 243.18 51.78 110.14 126.93 125.04 193.78 178.96
2016-10-15 12:00:00 55.49 108.68 148.88 90.00 175.20 91.15 75.10 102.03 194.71 111.61 ... 131.88 123.81 311.30 211.62 76.85 107.19 322.43 94.48 345.66 210.76
2016-10-15 14:00:00 70.85 101.44 369.30 147.15 480.54 131.23 68.73 129.67 132.41 112.88 ... 99.66 72.51 226.76 200.01 64.57 105.97 166.30 131.37 220.01 195.49
2016-10-15 16:00:00 62.82 186.11 131.17 120.68 183.74 173.84 55.51 136.59 187.96 156.38 ... 118.43 143.56 288.68 201.31 56.20 131.52 208.65 116.47 156.18 176.67
2016-10-15 18:00:00 69.84 140.16 117.03 92.53 208.13 95.01 61.47 107.73 113.36 39.24 ... 62.14 104.38 174.08 79.10 54.73 116.60 121.98 76.71 83.93 187.67
2016-10-15 20:00:00 49.56 113.54 131.56 81.32 90.82 557.39 71.34 85.96 92.39 73.55 ... 61.55 75.68 160.54 127.78 61.11 85.04 152.00 81.70 181.06 57.90
2016-10-15 22:00:00 56.07 98.05 150.00 81.24 208.41 51.67 32.25 82.48 134.46 100.07 ... 164.11 137.85 28.59 127.32 59.24 91.96 88.84 94.80 142.51 21.77
2016-10-16 00:00:00 59.43 60.06 18.62 71.69 38.50 176.72 45.70 300.65 93.32 45.35 ... 20.83 53.37 21.36 16.20 27.07 45.09 9.92 22.18 18.98 8.17
2016-10-16 02:00:00 91.74 35.27 15.58 12.09 8.36 17.12 36.26 35.20 10.38 25.51 ... 11.06 206.38 13.87 11.76 54.07 126.42 12.01 29.13 12.14 7.78
2016-10-16 04:00:00 45.65 28.72 9.91 23.75 15.55 9.84 42.17 40.29 30.23 35.97 ... 22.54 86.44 114.24 26.15 44.47 94.31 36.27 48.22 285.05 33.00
2016-10-16 06:00:00 44.35 107.90 56.34 62.56 74.69 42.83 43.37 97.01 64.27 90.34 ... 112.56 94.86 137.52 72.12 49.07 101.45 116.25 105.92 186.40 189.78
2016-10-16 08:00:00 65.10 114.11 112.75 93.91 166.49 64.31 78.61 135.07 102.82 98.29 ... 121.36 80.88 177.79 141.18 66.83 227.94 97.21 94.94 165.23 181.15
2016-10-16 10:00:00 72.15 171.94 103.33 54.65 210.89 124.70 70.30 132.77 124.10 79.78 ... 149.32 59.31 144.38 103.01 55.31 95.59 80.95 126.53 440.99 227.12
2016-10-16 12:00:00 64.06 93.59 134.29 100.55 266.24 152.97 54.81 95.45 143.35 102.87 ... 112.56 99.43 195.02 230.93 79.16 183.45 132.12 111.54 201.60 201.56
2016-10-16 14:00:00 52.68 175.09 149.55 103.92 253.72 190.71 60.43 118.46 91.03 128.19 ... 128.09 135.54 234.90 209.33 66.86 85.67 120.06 106.91 210.66 286.61
2016-10-16 16:00:00 72.75 168.21 133.51 103.95 264.98 235.16 71.52 164.68 172.85 97.74 ... 153.68 117.52 226.31 215.28 93.63 93.54 183.33 110.75 180.95 224.67
2016-10-16 18:00:00 63.15 135.56 117.24 110.04 241.96 141.09 70.38 128.98 69.72 104.61 ... 160.60 68.83 269.18 156.06 68.37 94.52 52.30 104.63 202.09 190.96
2016-10-16 20:00:00 64.10 123.63 120.15 87.52 164.39 153.81 54.89 104.32 112.66 90.29 ... 106.95 81.92 224.93 65.92 357.05 105.93 110.85 78.72 74.71 57.90
2016-10-16 22:00:00 64.01 103.64 35.65 106.78 183.47 51.67 58.27 105.03 37.17 62.19 ... 80.86 61.42 28.59 34.71 52.26 84.51 23.50 90.29 35.92 21.77
2016-10-17 00:00:00 59.61 89.41 95.71 70.85 38.50 27.91 40.03 77.48 16.13 125.27 ... 106.77 88.43 21.36 16.20 27.07 45.09 9.92 22.18 18.98 8.17
2016-10-17 02:00:00 37.09 35.27 15.58 28.74 8.36 17.12 51.25 35.20 10.38 25.51 ... 11.06 93.78 13.87 11.76 47.24 46.12 12.01 29.13 12.14 7.78
2016-10-17 04:00:00 56.49 91.66 9.91 73.25 15.55 9.84 69.42 126.47 30.23 35.97 ... 22.54 48.19 30.07 26.15 45.24 72.77 135.14 113.93 67.51 33.00
2016-10-17 06:00:00 43.74 68.25 56.34 83.62 196.30 42.83 48.09 140.63 75.72 43.62 ... 73.54 69.52 224.46 72.12 72.16 171.10 136.97 110.83 168.88 60.60
2016-10-17 08:00:00 133.58 306.58 108.63 147.11 165.10 64.31 108.33 296.26 115.41 118.52 ... 108.23 149.29 151.34 104.67 53.21 128.11 122.42 120.32 265.43 218.18
2016-10-17 10:00:00 64.87 118.49 161.91 129.52 142.21 220.20 76.01 132.14 88.98 50.23 ... 102.55 102.44 153.59 93.07 44.09 98.61 100.05 109.67 172.90 88.35
2016-10-17 12:00:00 65.24 99.45 131.03 94.10 167.98 104.38 45.44 104.89 104.69 77.63 ... 111.03 84.63 218.76 169.18 64.32 93.51 134.56 81.00 165.84 149.21
2016-10-17 14:00:00 52.28 84.48 99.41 98.19 191.14 131.23 70.19 100.53 147.23 104.86 ... 138.69 82.67 134.58 124.07 71.70 131.03 76.92 126.84 483.07 125.78
2016-10-17 16:00:00 53.86 109.92 134.99 115.47 180.28 171.02 69.77 111.73 136.45 100.27 ... 130.78 118.25 170.14 122.02 53.69 125.55 177.36 102.55 132.85 107.45
2016-10-17 18:00:00 65.40 158.01 77.42 102.74 267.11 173.74 48.66 115.05 98.47 83.02 ... 62.14 91.64 83.93 79.10 65.93 86.11 99.04 96.84 188.23 187.43
2016-10-17 20:00:00 52.66 101.30 62.67 99.77 90.82 209.32 72.69 137.58 172.53 84.75 ... 61.55 61.96 121.61 159.44 39.55 100.03 46.81 73.88 74.71 57.90

83 rows × 36 columns


In [46]:
#plot
import matplotlib.pyplot as plt
alpha=0.8
lw=0.7

fig, ax = plt.subplots(figsize = (26,8))

x_a = [pd.to_datetime(d) for d in y_test.index.values]

ax.scatter(np.array(x_a), y_test['0','A2'], color='green', label='y_test', s=0.8)

#ax.plot(x_a, y_test_predict_df['0','A2'], color='red', label='y_pred_rbf', alpha=alpha, lw=lw)
#plt.plot(x_a, y_test_predict_df['1','A2'], color='blue', label='y_pred_sigmoid', alpha=alpha, lw=lw)
#ax.plot(res.index.values, res['y_pred_lin'], color='orange', label='y_pred_lin', alpha=alpha, lw=lw)
#plt.plot(res.index.values, res['y_pred'], color='darkorange', label='y_pred_rbf')
ax.set_title('SVN on TimeInformation with rbf and linear kernel')
ax.set_xlabel('index(route,dayofweek,hour,minute)')
ax.set_ylabel('avg_travel_time')
ax.set_ylim(0,200)
ax.set_xlim(0)

ax.legend(shadow=True, fancybox=True)

#fig.legend()

'''
I also want to share my recent results. Maybe it helps or inspire someone.

SVN on TimeInformation with rbf and linear kernel.
Trained on the first 8 weeks and tested with the remaining data. (not shuffled)

'''


Out[46]:
'\nI also want to share my recent results. Maybe it helps or inspire someone.\n\nSVN on TimeInformation with rbf and linear kernel.\nTrained on the first 8 weeks and tested with the remaining data. (not shuffled)\n\n'
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    305                 pass
    306             else:
--> 307                 return printer(obj)
    308             # Finally look for special method names
    309             method = get_real_method(obj, self.print_method)

C:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
    225 
    226     if 'png' in formats:
--> 227         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    228     if 'retina' in formats or 'png2x' in formats:
    229         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

C:\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    117 
    118     bytes_io = BytesIO()
--> 119     fig.canvas.print_figure(bytes_io, **kw)
    120     data = bytes_io.getvalue()
    121     if fmt == 'svg':

C:\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2178                     orientation=orientation,
   2179                     dryrun=True,
-> 2180                     **kwargs)
   2181                 renderer = self.figure._cachedRenderer
   2182                 bbox_inches = self.figure.get_tightbbox(renderer)

C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    525 
    526     def print_png(self, filename_or_obj, *args, **kwargs):
--> 527         FigureCanvasAgg.draw(self)
    528         renderer = self.get_renderer()
    529         original_dpi = renderer.dpi

C:\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

C:\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1157         dsu.sort(key=itemgetter(0))
   1158         for zorder, a, func, args in dsu:
-> 1159             func(*args)
   1160 
   1161         renderer.close_group('figure')

C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

C:\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2317 
   2318         for zorder, a in dsu:
-> 2319             a.draw(renderer)
   2320 
   2321         renderer.close_group('axes')

C:\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     60     def draw_wrapper(artist, renderer, *args, **kwargs):
     61         before(artist, renderer)
---> 62         draw(artist, renderer, *args, **kwargs)
     63         after(artist, renderer)
     64 

C:\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
   1106         renderer.open_group(__name__)
   1107 
-> 1108         ticks_to_draw = self._update_ticks(renderer)
   1109         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
   1110                                                                 renderer)

C:\Anaconda3\lib\site-packages\matplotlib\axis.py in _update_ticks(self, renderer)
    949 
    950         interval = self.get_view_interval()
--> 951         tick_tups = [t for t in self.iter_ticks()]
    952         if self._smart_bounds:
    953             # handle inverted limits

C:\Anaconda3\lib\site-packages\matplotlib\axis.py in <listcomp>(.0)
    949 
    950         interval = self.get_view_interval()
--> 951         tick_tups = [t for t in self.iter_ticks()]
    952         if self._smart_bounds:
    953             # handle inverted limits

C:\Anaconda3\lib\site-packages\matplotlib\axis.py in iter_ticks(self)
    892         Iterate through all of the major and minor ticks.
    893         """
--> 894         majorLocs = self.major.locator()
    895         majorTicks = self.get_major_ticks(len(majorLocs))
    896         self.major.formatter.set_locs(majorLocs)

C:\Anaconda3\lib\site-packages\matplotlib\dates.py in __call__(self)
   1005     def __call__(self):
   1006         'Return the locations of the ticks'
-> 1007         self.refresh()
   1008         return self._locator()
   1009 

C:\Anaconda3\lib\site-packages\matplotlib\dates.py in refresh(self)
   1025     def refresh(self):
   1026         'Refresh internal information based on current limits.'
-> 1027         dmin, dmax = self.viewlim_to_dt()
   1028         self._locator = self.get_locator(dmin, dmax)
   1029 

C:\Anaconda3\lib\site-packages\matplotlib\dates.py in viewlim_to_dt(self)
    769             vmin, vmax = vmax, vmin
    770 
--> 771         return num2date(vmin, self.tz), num2date(vmax, self.tz)
    772 
    773     def _get_unit(self):

C:\Anaconda3\lib\site-packages\matplotlib\dates.py in num2date(x, tz)
    417         tz = _get_rc_timezone()
    418     if not cbook.iterable(x):
--> 419         return _from_ordinalf(x, tz)
    420     else:
    421         x = np.asarray(x)

C:\Anaconda3\lib\site-packages\matplotlib\dates.py in _from_ordinalf(x, tz)
    269 
    270     ix = int(x)
--> 271     dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
    272 
    273     remainder = float(x) - ix

ValueError: ordinal must be >= 1
<matplotlib.figure.Figure at 0x2d28f1806a0>