Why Multivariate and how can it help to make better predictions?
We can consider multivariate timeseries as regression problem with independent variables being the features of the previous lag (till t-1)along with the independent values of time t. With this approach there is lot more control on the forecast than just the previous timestamps.
From the above figure we can see that, along with the lag features, lead=2 (t+2) timesteps is also considered to make the forecast. This gives us more control on the factors effecting the forecast. In many cases we know that some of the future factors also effects our current time predictions. With these approaches, the decision making team can really simulate the forecast based on various input values of independent features.
Now let us see how to implement the multivariate timeseries with both lead and lag feature.
The major difference between using a LSTM for a regression task to timeseries is, that in timeseries lead and lag timestamp data needs to be considered. Lets define a function which can just do this based on the lead and lag as a parameter
Unnamed: 0 | Date_excel | Rainfall_Terni | Flow_Rate_Lupa | doy | Month | Year | ET01 | Infilt_ | Infiltsum | ... | Infilt_M6 | Infilt_M6_diff | Rainfall_Terni_scale_12_calculated_index | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2010-01-01 | 2010-01-01 | 40.8 | 82.24 | 1.0 | 1.0 | 2010.0 | 1.338352 | 1.934648 | 1.934648 | ... | 20.984370 | 12.824615 | 1.074801 | 0.105768 | 4.548065 | 0.607917 | 1.000000 | 0.0 | 2.094607 | 0.88 |
1 | 2010-01-02 | 2010-01-02 | 6.8 | 88.90 | 2.0 | 1.0 | 2010.0 | 1.701540 | 1.571460 | 3.506108 | ... | 5.949230 | 1.517793 | 1.074801 | 0.105766 | 4.546129 | 0.622538 | 0.999998 | 0.0 | 2.996092 | 0.84 |
2 | 2010-01-03 | 2010-01-03 | 0.0 | 93.56 | 3.0 | 1.0 | 2010.0 | 0.938761 | 2.334239 | 5.840347 | ... | 0.000000 | 0.000000 | 1.074801 | 0.105764 | 4.544194 | 0.637159 | 0.999996 | 0.0 | 1.934498 | 0.84 |
3 | 2010-01-04 | 2010-01-04 | 4.2 | 96.63 | 4.0 | 1.0 | 2010.0 | 0.996871 | 2.276129 | 8.116476 | ... | 3.701564 | 0.792433 | 1.074801 | 0.105761 | 4.542258 | 0.651780 | 0.999994 | 0.0 | 1.625804 | 0.84 |
4 | 2010-01-05 | 2010-01-05 | 26.0 | 98.65 | 5.0 | 1.0 | 2010.0 | 1.278242 | 1.994758 | 10.111234 | ... | 13.467998 | 1.974067 | 1.074801 | 0.105759 | 4.540323 | 0.666401 | 0.999992 | 0.0 | 1.993541 | 0.89 |
5 rows × 41 columns
Unnamed: 0 | Date_excel | Rainfall_Terni | Flow_Rate_Lupa | doy | Month | Year | ET01 | Infilt_ | Infiltsum | ... | Infilt_M6 | Infilt_M6_diff | Rainfall_Terni_scale_12_calculated_index | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3828 | 2020-06-25 | 2020-06-25 | 0.0 | 74.29 | 177.0 | 6.0 | 2020.0 | 4.030210 | -4.030210 | -541.652567 | ... | 0.0 | 0.0 | 0.122602 | 0.127096 | 4.345 | 1.160797 | 1.040964 | 15.897778 | 5.772770 | 0.52 |
3829 | 2020-06-26 | 2020-06-26 | 0.0 | 73.93 | 178.0 | 6.0 | 2020.0 | 4.171681 | -4.171681 | -545.824247 | ... | 0.0 | 0.0 | 0.122602 | 0.127512 | 4.272 | 1.149976 | 1.036377 | 16.560185 | 6.107339 | 0.51 |
3830 | 2020-06-27 | 2020-06-27 | 0.0 | 73.60 | 179.0 | 6.0 | 2020.0 | 4.449783 | -4.449783 | -550.274031 | ... | 0.0 | 0.0 | 0.122602 | 0.127928 | 4.199 | 1.139156 | 1.030895 | 17.222592 | 6.540321 | 0.50 |
3831 | 2020-06-28 | 2020-06-28 | 0.0 | 73.14 | 180.0 | 6.0 | 2020.0 | 4.513588 | -4.513588 | -554.787618 | ... | 0.0 | 0.0 | 0.122602 | 0.128345 | 4.126 | 1.128336 | 1.024516 | 17.885000 | 6.593228 | 0.49 |
3832 | 2020-06-29 | 2020-06-29 | 0.0 | 72.88 | 181.0 | 6.0 | 2020.0 | 4.510906 | -4.510906 | -559.298525 | ... | 0.0 | 0.0 | 0.122602 | 0.128761 | 4.053 | 1.117516 | 1.017240 | 18.547407 | 6.479413 | 0.48 |
5 rows × 41 columns
0 -0.077870 1 -0.077870 2 -0.051091 3 -0.032286 4 -0.020689 Name: α1, dtype: float64
Unnamed: 0 | Date_excel | Rainfall_Terni | Flow_Rate_Lupa | doy | Month | Year | ET01 | Infilt_ | Infiltsum | ... | Rainfall_Terni_scale_12_calculated_index | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | α1_OK | α4 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2010-01-01 | 2010-01-01 | 40.8 | 82.24 | 1.0 | 1.0 | 2010.0 | 1.338352 | 1.934648 | 1.934648 | ... | 1.074801 | 0.105768 | 4.548065 | 0.607917 | 1.000000 | 0.0 | 2.094607 | 0.88 | -0.005 | 0.004800 |
1 | 2010-01-02 | 2010-01-02 | 6.8 | 88.90 | 2.0 | 1.0 | 2010.0 | 1.701540 | 1.571460 | 3.506108 | ... | 1.074801 | 0.105766 | 4.546129 | 0.622538 | 0.999998 | 0.0 | 2.996092 | 0.84 | -0.015 | -0.010000 |
2 | 2010-01-03 | 2010-01-03 | 0.0 | 93.56 | 3.0 | 1.0 | 2010.0 | 0.938761 | 2.334239 | 5.840347 | ... | 1.074801 | 0.105764 | 4.544194 | 0.637159 | 0.999996 | 0.0 | 1.934498 | 0.84 | -0.015 | -0.011667 |
3 | 2010-01-04 | 2010-01-04 | 4.2 | 96.63 | 4.0 | 1.0 | 2010.0 | 0.996871 | 2.276129 | 8.116476 | ... | 1.074801 | 0.105761 | 4.542258 | 0.651780 | 0.999994 | 0.0 | 1.625804 | 0.84 | -0.015 | -0.012500 |
4 | 2010-01-05 | 2010-01-05 | 26.0 | 98.65 | 5.0 | 1.0 | 2010.0 | 1.278242 | 1.994758 | 10.111234 | ... | 1.074801 | 0.105759 | 4.540323 | 0.666401 | 0.999992 | 0.0 | 1.993541 | 0.89 | -0.015 | -0.015000 |
5 rows × 43 columns
Unnamed: 0 | Date_excel | Rainfall_Terni | Flow_Rate_Lupa | doy | Month | Year | ET01 | Infilt_ | Infiltsum | ... | Rainfall_Terni_scale_12_calculated_index | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | α1_OK | α4 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3822 | 2020-06-19 | 2020-06-19 | 0.2 | 76.39 | 171.0 | 6.0 | 2020.0 | 3.463793 | -3.263793 | -518.987061 | ... | 0.122602 | 0.124598 | 4.783 | 1.206395 | 1.049658 | 11.923333 | 5.152927 | 0.58 | 0.004987 | 0.003689 |
3823 | 2020-06-20 | 2020-06-20 | 0.0 | 76.01 | 172.0 | 6.0 | 2020.0 | 3.333015 | -3.333015 | -522.320075 | ... | 0.122602 | 0.125014 | 4.710 | 1.205237 | 1.050450 | 12.585741 | 5.203840 | 0.56 | 0.004880 | 0.004098 |
3824 | 2020-06-21 | 2020-06-21 | 0.0 | 75.64 | 173.0 | 6.0 | 2020.0 | 3.412032 | -3.412032 | -525.732107 | ... | 0.122602 | 0.125430 | 4.637 | 1.204077 | 1.050345 | 13.248148 | 5.040534 | 0.56 | 0.004372 | 0.003658 |
3825 | 2020-06-22 | 2020-06-22 | 0.0 | 75.31 | 174.0 | 6.0 | 2020.0 | 3.742202 | -3.742202 | -529.474309 | ... | 0.122602 | 0.125847 | 4.564 | 1.193257 | 1.049344 | 13.910555 | 5.448369 | 0.56 | 0.005726 | 0.004991 |
3826 | 2020-06-23 | 2020-06-23 | 0.0 | 74.88 | 175.0 | 6.0 | 2020.0 | 3.917863 | -3.917863 | -533.392172 | ... | 0.122602 | 0.126263 | 4.491 | 1.182437 | 1.047447 | 14.572963 | 5.861305 | 0.54 | 0.004014 | 0.004748 |
3827 | 2020-06-24 | 2020-06-24 | 0.0 | 74.58 | 176.0 | 6.0 | 2020.0 | 4.230186 | -4.230186 | -537.622357 | ... | 0.122602 | 0.126679 | 4.418 | 1.171617 | 1.044654 | 15.235370 | 6.209193 | 0.52 | 0.003896 | 0.004502 |
3828 | 2020-06-25 | 2020-06-25 | 0.0 | 74.29 | 177.0 | 6.0 | 2020.0 | 4.030210 | -4.030210 | -541.652567 | ... | 0.122602 | 0.127096 | 4.345 | 1.160797 | 1.040964 | 15.897778 | 5.772770 | 0.52 | 0.004858 | 0.004624 |
3829 | 2020-06-26 | 2020-06-26 | 0.0 | 73.93 | 178.0 | 6.0 | 2020.0 | 4.171681 | -4.171681 | -545.824247 | ... | 0.122602 | 0.127512 | 4.272 | 1.149976 | 1.036377 | 16.560185 | 6.107339 | 0.51 | 0.004474 | 0.004310 |
3830 | 2020-06-27 | 2020-06-27 | 0.0 | 73.60 | 179.0 | 6.0 | 2020.0 | 4.449783 | -4.449783 | -550.274031 | ... | 0.122602 | 0.127928 | 4.199 | 1.139156 | 1.030895 | 17.222592 | 6.540321 | 0.50 | 0.006270 | 0.004874 |
3831 | 2020-06-28 | 2020-06-28 | 0.0 | 73.14 | 180.0 | 6.0 | 2020.0 | 4.513588 | -4.513588 | -554.787618 | ... | 0.122602 | 0.128345 | 4.126 | 1.128336 | 1.024516 | 17.885000 | 6.593228 | 0.49 | 0.004800 | 0.005100 |
10 rows × 43 columns
82.24
4.409641801706855
4.409641801706855
9.068627239003707
-0.0031319072300002304
0.0031319072300002304
Lupa['α1']= Lupa.log_Flow.shift(-1) -Lupa.log_Flow
Unnamed: 0 | Date_excel | Rainfall_Terni | Flow_Rate_Lupa | doy | Month | Year | ET01 | Infilt_ | Infiltsum | ... | Rainfall_Terni_scale_12_calculated_index | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | α1_OK | α4 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2378 | 2016-07-06 | 2016-07-06 | 0.2 | 145.36 | 188.0 | 7.0 | 2016.0 | 4.27521 | -4.07521 | -422.631172 | ... | 0.068649 | 0.129659 | 4.941290 | -0.614314 | 0.919147 | 39.429314 | 5.688181 | 0.46 | 0.015 | 0.006657 |
2908 | 2017-12-18 | 2017-12-18 | 0.0 | 55.51 | 352.0 | 12.0 | 2017.0 | 0.85813 | -0.85813 | -790.968845 | ... | 0.645122 | 0.104350 | 4.419677 | -0.177246 | 0.991808 | 0.000000 | 2.144621 | 0.64 | 0.015 | 0.003307 |
2 rows × 43 columns
Lupa['α4']= Lupa['α1'].rolling(4, center=True).mean().fillna( Lupa['α1'].median() )
Lupa['α10']= Lupa['α1'].rolling(10, center=True).mean().fillna( Lupa['α1'].median() )
Index(['Unnamed: 0', 'Date_excel', 'Rainfall_Terni', 'Flow_Rate_Lupa', 'doy', 'Month', 'Year', 'ET01', 'Infilt_', 'Infiltsum', 'Rainfall_Ter', 'P5', 'Flow_Rate_Lup', 'Infilt_m3', 'Week', 'log_Flow', 'Lupa_Mean99_2011', 'Rainfall_Terni_minET', 'Infiltrate', 'log_Flow_10d', 'log_Flow_20d', 'α10', 'α20', 'log_Flow_10d_dif', 'log_Flow_20d_dif', 'α10_30', 'Infilt_7YR', 'Infilt_2YR', 'α1', 'α1_negatives', 'ro', 'Infilt_M6', 'Infilt_M6_diff', 'Rainfall_Terni_scale_12_calculated_index', 'SMroot', 'Neradebit', 'smian', 'DroughtIndex', 'Deficit', 'PET_hg', 'GWETTOP', 'α1_OK', 'α4'], dtype='object')
Rainfall_Terni_minET | log_Flow | Lupa_Mean99_2011 | Infilt_M6 | α1_OK | α10 | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 39.461648 | 4.409642 | 117.814892 | 20.984370 | -0.005 | 0.004800 | 0.105768 | 4.548065 | 0.607917 | 1.000000 | 0.0 | 2.094607 | 0.88 |
1 | 5.098460 | 4.487512 | 120.382310 | 5.949230 | -0.015 | 0.004800 | 0.105766 | 4.546129 | 0.622538 | 0.999998 | 0.0 | 2.996092 | 0.84 |
2 | 0.000000 | 4.538603 | 118.858733 | 0.000000 | -0.015 | -0.029459 | 0.105764 | 4.544194 | 0.637159 | 0.999996 | 0.0 | 1.934498 | 0.84 |
3 | 3.203129 | 4.570889 | 121.065519 | 3.701564 | -0.015 | -0.027267 | 0.105761 | 4.542258 | 0.651780 | 0.999994 | 0.0 | 1.625804 | 0.84 |
4 | 24.721758 | 4.591578 | 119.763396 | 13.467998 | -0.015 | -0.028786 | 0.105759 | 4.540323 | 0.666401 | 0.999992 | 0.0 | 1.993541 | 0.89 |
Rainfall_Terni_minET | log_Flow | Lupa_Mean99_2011 | Infilt_M6 | α1_OK | α10 | SMroot | Neradebit | smian | DroughtIndex | Deficit | PET_hg | GWETTOP | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3814 | 4.009934 | 4.370966 | 163.535143 | 5.104967 | 0.006212 | 0.003989 | 0.121267 | 5.367 | 1.215667 | 1.024150 | 6.624074 | 3.286200 | 0.67 |
3815 | 0.000000 | 4.364753 | 163.327754 | 0.000000 | 0.004333 | 0.004190 | 0.121683 | 5.294 | 1.214508 | 1.027398 | 7.286481 | 5.497035 | 0.58 |
3816 | 0.000000 | 4.360420 | 162.317328 | 0.000000 | 0.004994 | 0.004186 | 0.122100 | 5.221 | 1.213350 | 1.030798 | 7.948889 | 5.540033 | 0.57 |
3817 | 0.000000 | 4.355426 | 161.169102 | 0.219185 | 0.006052 | 0.005135 | 0.122516 | 5.148 | 1.212190 | 1.034348 | 8.611296 | 4.030759 | 0.57 |
3818 | 1.800428 | 4.349374 | 160.612387 | 3.300214 | 0.003752 | 0.005080 | 0.122932 | 5.075 | 1.211032 | 1.038050 | 9.273704 | 4.253079 | 0.64 |
3819 | 0.000000 | 4.345622 | 160.055672 | 0.000000 | 0.003246 | 0.004972 | 0.123349 | 5.002 | 1.209872 | 1.041904 | 9.936111 | 4.243349 | 0.67 |
3820 | 6.933015 | 4.342376 | 158.942241 | 8.466507 | 0.006131 | 0.004915 | 0.123765 | 4.929 | 1.208713 | 1.045385 | 10.598518 | 4.371786 | 0.62 |
3821 | 0.000000 | 4.336244 | 158.457154 | 1.142865 | 0.000393 | 0.004279 | 0.124181 | 4.856 | 1.207555 | 1.047970 | 11.260926 | 4.987571 | 0.61 |
3822 | 0.000000 | 4.335852 | 157.759221 | 0.000000 | 0.004987 | 0.004237 | 0.124598 | 4.783 | 1.206395 | 1.049658 | 11.923333 | 5.152927 | 0.58 |
3823 | 0.000000 | 4.330865 | 156.506611 | 0.000000 | 0.004880 | 0.004498 | 0.125014 | 4.710 | 1.205237 | 1.050450 | 12.585741 | 5.203840 | 0.56 |
3824 | 0.000000 | 4.325985 | 155.880306 | 0.000000 | 0.004372 | 0.004314 | 0.125430 | 4.637 | 1.204077 | 1.050345 | 13.248148 | 5.040534 | 0.56 |
3825 | 0.000000 | 4.321613 | 155.254001 | 0.000000 | 0.005726 | 0.004453 | 0.125847 | 4.564 | 1.193257 | 1.049344 | 13.910555 | 5.448369 | 0.56 |
3826 | 0.000000 | 4.315887 | 154.398320 | 0.000000 | 0.004014 | 0.004355 | 0.126263 | 4.491 | 1.182437 | 1.047447 | 14.572963 | 5.861305 | 0.54 |
3827 | 0.000000 | 4.311872 | 154.001392 | 0.000000 | 0.003896 | 0.004140 | 0.126679 | 4.418 | 1.171617 | 1.044654 | 15.235370 | 6.209193 | 0.52 |
3828 | 0.000000 | 4.307976 | 152.713987 | 0.000000 | 0.004858 | 0.004250 | 0.127096 | 4.345 | 1.160797 | 1.040964 | 15.897778 | 5.772770 | 0.52 |
3829 | 0.000000 | 4.303119 | 151.252610 | 0.000000 | 0.004474 | 0.004373 | 0.127512 | 4.272 | 1.149976 | 1.036377 | 16.560185 | 6.107339 | 0.51 |
3830 | 0.000000 | 4.298645 | 151.111899 | 0.000000 | 0.006270 | 0.004387 | 0.127928 | 4.199 | 1.139156 | 1.030895 | 17.222592 | 6.540321 | 0.50 |
3831 | 0.000000 | 4.292375 | 150.104384 | 0.000000 | 0.004800 | 0.004831 | 0.128345 | 4.126 | 1.128336 | 1.024516 | 17.885000 | 6.593228 | 0.49 |
The above functions converts the data into timeseries series with customized n_lag and n_lead steps. The output of this function contains data of lag and lead steps as columns with (t-n) or (t+n) timestamps
(3832, 13)
var13(t-1) | var1(t) | var2(t) | var3(t) | var4(t) | var5(t) | var6(t) | var7(t) | var8(t) | var9(t) | var10(t) | var11(t) | var12(t) | var13(t) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3433 | 0.77 | 11.140963 | 4.604770 | 175.539318 | 12.370481 | -0.015000 | -0.015471 | 0.114055 | 7.306774 | 1.553723 | 0.994103 | 0.000000 | 3.531847 | 0.79 |
3434 | 0.79 | 7.092983 | 4.646600 | 173.173278 | 8.446492 | -0.015000 | -0.018052 | 0.114097 | 7.402581 | 1.564240 | 0.995003 | 0.000000 | 3.790510 | 0.76 |
3435 | 0.76 | 7.480072 | 4.676653 | 172.372999 | 8.540036 | -0.015000 | -0.018758 | 0.114138 | 7.498387 | 1.574756 | 0.996043 | 0.000000 | 3.149089 | 0.78 |
3436 | 0.78 | 6.950440 | 4.701843 | 171.920668 | 7.975220 | -0.015000 | -0.018959 | 0.114179 | 7.594194 | 1.585272 | 0.997222 | 0.000000 | 3.038312 | 0.76 |
3437 | 0.76 | 0.000000 | 4.724019 | 171.468337 | 0.000000 | -0.015000 | -0.019481 | 0.114221 | 7.690000 | 1.595789 | 0.998541 | 0.000000 | 4.016658 | 0.73 |
3438 | 0.73 | 0.000000 | 4.742669 | 170.789783 | 0.000000 | -0.015000 | -0.020379 | 0.114262 | 7.573000 | 1.606305 | 1.000000 | 0.000000 | 4.710386 | 0.73 |
3439 | 0.73 | 0.000000 | 4.758406 | 170.424495 | 0.000000 | -0.014733 | -0.021182 | 0.114303 | 7.456000 | 1.571215 | 1.001598 | 2.042404 | 5.001716 | 0.72 |
3440 | 0.72 | 0.000000 | 4.773139 | 169.241475 | 0.000000 | -0.013018 | -0.021962 | 0.114345 | 7.339000 | 1.536125 | 1.003336 | 4.084807 | 4.935763 | 0.71 |
3441 | 0.71 | 0.000000 | 4.786158 | 168.649965 | 0.000000 | -0.012439 | -0.022481 | 0.114386 | 7.222000 | 1.501035 | 1.005213 | 6.127211 | 5.270744 | 0.70 |
3442 | 0.70 | 0.000000 | 4.798597 | 168.058455 | 0.000000 | -0.011227 | -0.020505 | 0.114427 | 7.105000 | 1.465945 | 1.007230 | 8.169615 | 5.364919 | 0.67 |
3443 | 0.67 | 0.000000 | 4.809824 | 166.979819 | 0.000000 | -0.010377 | -0.017360 | 0.114469 | 6.988000 | 1.430855 | 1.009387 | 10.212018 | 5.166235 | 0.65 |
3444 | 0.65 | 0.000000 | 4.820201 | 167.386588 | 0.000000 | -0.002658 | -0.014621 | 0.114510 | 6.871000 | 1.395765 | 1.011683 | 12.254422 | 5.975295 | 0.63 |
3445 | 0.63 | 0.000000 | 4.822859 | 165.901183 | 0.000000 | -0.015000 | -0.014077 | 0.114551 | 6.754000 | 1.360675 | 1.014119 | 14.296826 | 6.325639 | 0.62 |
3446 | 0.62 | 0.000000 | 4.842611 | 165.763054 | 0.000000 | -0.005270 | -0.012386 | 0.114593 | 6.637000 | 1.325585 | 1.016694 | 16.339230 | 6.388215 | 0.59 |
3447 | 0.59 | 0.000000 | 4.847881 | 164.752958 | 0.000000 | -0.010147 | -0.011536 | 0.114634 | 6.520000 | 1.290495 | 1.019409 | 18.381633 | 5.553434 | 0.59 |
3448 | 0.59 | 0.000000 | 4.858028 | 163.535143 | 0.000000 | -0.007505 | -0.010713 | 0.114675 | 6.403000 | 1.255405 | 1.022264 | 20.424037 | 5.656065 | 0.57 |
3449 | 0.57 | 0.000000 | 4.865532 | 163.327754 | 0.000000 | -0.005381 | -0.009777 | 0.114717 | 6.286000 | 1.202354 | 1.025258 | 22.466441 | 5.889984 | 0.56 |
3450 | 0.56 | 0.000000 | 4.870913 | 162.317328 | 0.000000 | -0.004589 | -0.008935 | 0.114758 | 6.169000 | 1.149304 | 1.028391 | 24.508844 | 6.349167 | 0.55 |
3451 | 0.55 | 0.000000 | 4.875503 | 161.169102 | 0.000000 | -0.004188 | -0.008109 | 0.114799 | 6.052000 | 1.096253 | 1.031665 | 26.551248 | 7.182276 | 0.54 |
3452 | 0.54 | 0.000000 | 4.879691 | 160.612387 | 0.000000 | -0.002656 | -0.007252 | 0.114841 | 5.935000 | 1.043203 | 1.035077 | 28.593652 | 5.982390 | 0.53 |
3453 | 0.53 | 0.000000 | 4.882347 | 160.055672 | 0.000000 | -0.002271 | -0.006442 | 0.114882 | 5.818000 | 0.990152 | 1.038630 | 30.636055 | 6.189987 | 0.52 |
3454 | 0.52 | 1.306480 | 4.884618 | 158.942241 | 3.453240 | -0.002794 | -0.006455 | 0.114923 | 5.701000 | 0.937102 | 1.041517 | 32.678459 | 6.074026 | 0.52 |
3455 | 0.52 | 0.000000 | 4.887412 | 158.457154 | 0.000000 | -0.001582 | -0.004638 | 0.114965 | 5.584000 | 0.884051 | 1.042935 | 34.720863 | 5.854209 | 0.52 |
3456 | 0.52 | 0.000000 | 4.888995 | 157.759221 | 0.000000 | -0.000075 | -0.004119 | 0.115006 | 5.467000 | 0.831001 | 1.042882 | 36.763266 | 5.998155 | 0.51 |
3457 | 0.51 | 0.000000 | 4.889070 | 156.506611 | 0.000000 | 0.007405 | -0.002364 | 0.115047 | 5.350000 | 0.777950 | 1.041361 | 38.805670 | 6.350226 | 0.50 |
3458 | 0.50 | 0.000000 | 4.881665 | 155.880306 | 0.000000 | -0.008308 | -0.002444 | 0.115089 | 5.233000 | 0.724900 | 1.038369 | 40.848074 | 6.589590 | 0.49 |
3459 | 0.49 | 0.000000 | 4.889973 | 155.254001 | 0.000000 | -0.000301 | -0.001936 | 0.115130 | 5.116000 | 0.685513 | 1.033907 | 42.890477 | 5.823888 | 0.49 |
3460 | 0.49 | 0.000000 | 4.890274 | 154.398320 | 0.000000 | 0.001430 | -0.001334 | 0.115171 | 4.999000 | 0.646126 | 1.027976 | 44.932881 | 6.191218 | 0.48 |
3461 | 0.48 | 0.000000 | 4.888844 | 154.001392 | 0.000000 | 0.001356 | -0.000780 | 0.115213 | 4.882000 | 0.606738 | 1.020575 | 46.975285 | 5.938021 | 0.48 |
3462 | 0.48 | 0.000000 | 4.887488 | 152.713987 | 0.000000 | 0.001358 | -0.000378 | 0.115254 | 4.765000 | 0.567351 | 1.011705 | 49.017689 | 6.331419 | 0.47 |
3463 | 0.47 | 0.000000 | 4.886130 | 151.252610 | 0.000000 | 0.001511 | 0.000000 | 0.115295 | 4.648000 | 0.527964 | 1.001364 | 51.060092 | 6.652679 | 0.46 |
3464 | 0.46 | 0.000000 | 4.884618 | 151.111899 | 0.000000 | 0.001741 | 0.000453 | 0.115337 | 4.531000 | 0.488577 | 0.989554 | 53.102496 | 7.210034 | 0.45 |
3465 | 0.45 | 0.000000 | 4.882878 | 150.104384 | 0.000000 | 0.002655 | 0.000877 | 0.115378 | 4.414000 | 0.449189 | 0.976274 | 55.144900 | 7.138806 | 0.45 |
3466 | 0.45 | 0.000000 | 4.880223 | 149.409657 | 0.000000 | 0.001748 | 0.001060 | 0.115419 | 4.297000 | 0.409802 | 0.961524 | 57.187303 | 6.510536 | 0.45 |
3467 | 0.45 | 0.000000 | 4.878474 | 148.712596 | 0.000000 | 0.000761 | 0.000395 | 0.115461 | 4.180000 | 0.370415 | 0.945305 | 59.229707 | 7.678308 | 0.44 |
3468 | 0.44 | 0.000000 | 4.877713 | 147.320807 | 0.000000 | 0.001448 | 0.001371 | 0.115502 | 4.186129 | 0.331027 | 0.927616 | 61.272111 | 7.203015 | 0.45 |
3469 | 0.45 | 0.000000 | 4.876265 | 146.856294 | 0.000000 | 0.001908 | 0.001592 | 0.115543 | 4.192258 | 0.323979 | 0.908457 | 63.486426 | 7.461562 | 0.44 |
3470 | 0.44 | 0.000000 | 4.874357 | 145.998608 | 0.000000 | 0.002754 | 0.001724 | 0.115585 | 4.198387 | 0.316930 | 0.887828 | 65.700742 | 7.091059 | 0.44 |
3471 | 0.44 | 0.000000 | 4.871603 | 144.676409 | 0.000000 | 0.002224 | 0.001811 | 0.115626 | 4.204516 | 0.309881 | 0.865730 | 67.915057 | 6.737927 | 0.45 |
3472 | 0.45 | 0.000000 | 4.869379 | 144.302931 | 0.000000 | 0.002229 | 0.001898 | 0.115667 | 4.210645 | 0.302833 | 0.842162 | 70.129372 | 6.867434 | 0.44 |
3473 | 0.44 | 0.000000 | 4.867150 | 143.423800 | 0.000000 | 0.003160 | 0.002063 | 0.115709 | 4.216774 | 0.295784 | 0.817124 | 72.343688 | 7.176614 | 0.42 |
from tensorflow.keras.layers import Normalization
Normalization by StandardScaler
This code helps in dropping the future Y (at t+n) while training the models. Once we drop the future Y and we have the reframed data, its as simple as training the LSTM for a regression problem.
(3802, 402) (3802, 1)
(3665, 1, 402) (137, 1, 402)
The first LSTM layer contains estimators for 3 years. The length of the test targets is 300, thus 10 months.
3660
3665 1 402
Once the model is ready we can train the model on the train data and test it on the test. We add some training checkpoints which can be used to efficiently train and earlystop a model.
3665 1 402
Once model is trained , we can get the predictions for our test data
5/5 [==============================] - 1s 19ms/step
array([[0.09541333], [0.09553236], [0.09676951]], dtype=float32)
(137, 1, 402) (137, 1)
array([0.14965787, 0.14949162, 0.15430685, 0.15563299, 0.16076282])
(137, 1) (137, 1)
tf.math.exp( test_X[:,0,1] )
history.history# .loss
array([[1.1001134], [1.1002445]], dtype=float32)
array([[107.73059], [107.73747]], dtype=float32)
(137, 402)
var2_t is the 10 last feature col
array([4.45560468, 4.94125655, 4.45560468, 4.45560468, 4.45560468, 4.45560468, 4.68121901, 4.45560468, 4.45560468, 4.45560468, 4.45560468, 4.45560468, 4.45560468, 4.69108166, 4.69663514, 4.80012583, 4.45560468, 5.59022869, 5.79308962, 5.02732022])
batchsize=366, predictions = 137
4.9648447
batchsize=183, predictions = 300
the predictions over 300 days vs. the observed outflows.
9.235593
973.3673
values = Lupa[["Rainfall_Terni" ,"log_Flow", "Infilt_M6", 'α10','Neradebit', 'smian', 'DroughtIndex', 'Deficit', 'PET_hg']] MeanAbsolutePercentageError 4.4716454
array([-0.32206752, 0.17360827, -0.26424101, ..., 0.04898375, 1.4423285 , -0.84989194])