|
548 | 548 | " \n",
|
549 | 549 | " Return value: list of `pandas.DataFrame` objects, each containing the predictions\n",
|
550 | 550 | " \"\"\"\n",
|
551 |
| - " prediction_time = ts.index[-1] + 1\n", |
| 551 | + " prediction_time = ts.index[-1] + ts.index.freq\n", |
552 | 552 | " quantiles = [str(q) for q in quantiles]\n",
|
553 | 553 | " req = self.__encode_request(ts, cat, dynamic_feat, num_samples, return_samples, quantiles)\n",
|
554 | 554 | " res = super(DeepARPredictor, self).predict(req)\n",
|
|
575 | 575 | " # however, if possible one will pass multiple time series as predictions will then be faster\n",
|
576 | 576 | " predictions = json.loads(response.decode('utf-8'))['predictions'][0]\n",
|
577 | 577 | " prediction_length = len(next(iter(predictions['quantiles'].values())))\n",
|
578 |
| - " prediction_index = pd.DatetimeIndex(start=prediction_time, freq=freq, periods=prediction_length) \n", |
| 578 | + " prediction_index = pd.date_range(start=prediction_time, freq=freq, periods=prediction_length)\n", |
579 | 579 | " if return_samples:\n",
|
580 | 580 | " dict_of_samples = {'sample_' + str(i): s for i, s in enumerate(predictions['samples'])}\n",
|
581 | 581 | " else:\n",
|
|
669 | 669 | " plot_history=7 * 12,\n",
|
670 | 670 | " confidence=80\n",
|
671 | 671 | "):\n",
|
| 672 | + " freq = target_ts.index.freq\n", |
672 | 673 | " print(\"calling served model to generate predictions starting from {}\".format(str(forecast_date)))\n",
|
673 | 674 | " assert(confidence > 50 and confidence < 100)\n",
|
674 | 675 | " low_quantile = 0.5 - confidence * 0.005\n",
|
|
706 | 707 | " \n",
|
707 | 708 | " \n",
|
708 | 709 | " # plot the target\n",
|
709 |
| - " target_section = target_ts[forecast_date-plot_history:forecast_date+prediction_length]\n", |
| 710 | + " target_section = target_ts[forecast_date - plot_history * freq:forecast_date + prediction_length * freq]\n", |
710 | 711 | " target_section.plot(color=\"black\", label='target')\n",
|
711 | 712 | " \n",
|
712 | 713 | " # plot the confidence interval and the median predicted\n",
|
|
726 | 727 | " for i, f in enumerate(dynamic_feat, start=1):\n",
|
727 | 728 | " ax = plt.subplot(len(dynamic_feat) * 2, 1, len(dynamic_feat) + i, sharex=ax)\n",
|
728 | 729 | " feat_ts = pd.Series(\n",
|
729 |
| - " index=pd.DatetimeIndex(start=target_ts.index[0], freq=target_ts.index.freq, periods=len(f)),\n", |
| 730 | + " index=pd.date_range(start=target_ts.index[0], freq=target_ts.index.freq, periods=len(f)),\n", |
730 | 731 | " data=f\n",
|
731 | 732 | " )\n",
|
732 |
| - " feat_ts[forecast_date-plot_history:forecast_date+prediction_length].plot(ax=ax, color='g')" |
| 733 | + " feat_ts[forecast_date - plot_history * freq:forecast_date + prediction_length * freq].plot(ax=ax, color='g')" |
733 | 734 | ]
|
734 | 735 | },
|
735 | 736 | {
|
|
908 | 909 | "test_data_new_features = [\n",
|
909 | 910 | " {\n",
|
910 | 911 | " \"start\": str(start_dataset),\n",
|
911 |
| - " \"target\": encode_target(ts[start_dataset:end_training + 2*k*prediction_length]),\n", |
912 |
| - " \"dynamic_feat\": [special_day_features[i][start_dataset:end_training + 2*k*prediction_length].tolist()]\n", |
| 912 | + " \"target\": encode_target(ts[start_dataset:end_training + 2*k*prediction_length * ts.index.freq]),\n", |
| 913 | + " \"dynamic_feat\": [special_day_features[i][start_dataset:end_training + 2*k*prediction_length * ts.index.freq].tolist()]\n", |
913 | 914 | " }\n",
|
914 | 915 | " for k in range(1, num_test_windows + 1) \n",
|
915 | 916 | " for i, ts in enumerate(timeseries_uplift)\n",
|
|
1070 | 1071 | ")\n",
|
1071 | 1072 | "def plot_interact(customer_id, forecast_day, confidence, missing_ratio, show_samples): \n",
|
1072 | 1073 | " forecast_date = end_training + datetime.timedelta(days=forecast_day)\n",
|
1073 |
| - " target = time_series_processed[customer_id][start_dataset:forecast_date + prediction_length]\n", |
| 1074 | + " ts = time_series_processed[customer_id]\n", |
| 1075 | + " freq = ts.index.freq\n", |
| 1076 | + " target = ts[start_dataset:forecast_date + prediction_length * freq]\n", |
1074 | 1077 | " target = drop_at_random(target, missing_ratio)\n",
|
1075 |
| - " dynamic_feat = [special_day_features[customer_id][start_dataset:forecast_date + prediction_length].tolist()]\n", |
| 1078 | + " dynamic_feat = [special_day_features[customer_id][start_dataset:forecast_date + prediction_length * freq].tolist()]\n", |
1076 | 1079 | " plot(\n",
|
1077 | 1080 | " predictor_new_features,\n",
|
1078 | 1081 | " target_ts=target, \n",
|
|
0 commit comments