|
47 | 47 | "outputs": [], |
48 | 48 | "source": [ |
49 | 49 | "%%capture\n", |
50 | | - "!pip install neuralforecast datasetsforecast" |
| 50 | + "!pip install neuralforecast datasetsforecast utilsforecast" |
51 | 51 | ] |
52 | 52 | }, |
53 | 53 | { |
|
433 | 433 | "nf.models[0].results.get_best_result().config" |
434 | 434 | ] |
435 | 435 | }, |
436 | | - { |
437 | | - "cell_type": "code", |
438 | | - "execution_count": null, |
439 | | - "metadata": {}, |
440 | | - "outputs": [ |
441 | | - { |
442 | | - "name": "stdout", |
443 | | - "output_type": "stream", |
444 | | - "text": [ |
445 | | - "Parsed results\n", |
446 | | - "2. y_true.shape (n_series, n_windows, n_time_out):\t (7, 11425, 96)\n", |
447 | | - "2. y_hat.shape (n_series, n_windows, n_time_out):\t (7, 11425, 96)\n" |
448 | | - ] |
449 | | - } |
450 | | - ], |
451 | | - "source": [ |
452 | | - "y_true = Y_hat_df.y.values\n", |
453 | | - "y_hat = Y_hat_df['AutoNHITS'].values\n", |
454 | | - "\n", |
455 | | - "n_series = len(Y_df.unique_id.unique())\n", |
456 | | - "\n", |
457 | | - "y_true = y_true.reshape(n_series, -1, horizon)\n", |
458 | | - "y_hat = y_hat.reshape(n_series, -1, horizon)\n", |
459 | | - "\n", |
460 | | - "print('Parsed results')\n", |
461 | | - "print('2. y_true.shape (n_series, n_windows, n_time_out):\\t', y_true.shape)\n", |
462 | | - "print('2. y_hat.shape (n_series, n_windows, n_time_out):\\t', y_hat.shape)" |
463 | | - ] |
464 | | - }, |
465 | 436 | { |
466 | 437 | "cell_type": "code", |
467 | 438 | "execution_count": null, |
|
479 | 450 | } |
480 | 451 | ], |
481 | 452 | "source": [ |
482 | | - "fig, axs = plt.subplots(nrows=3, ncols=1, figsize=(10, 11))\n", |
483 | | - "fig.tight_layout()\n", |
484 | | - "\n", |
| 453 | + "from utilsforecast.plotting import plot_series \n", |
| 454 | + " \n", |
485 | 455 | "series = ['HUFL','HULL','LUFL','LULL','MUFL','MULL','OT']\n", |
486 | | - "series_idx = 3\n", |
487 | | - "\n", |
488 | | - "for idx, w_idx in enumerate([200, 300, 400]):\n", |
489 | | - " axs[idx].plot(y_true[series_idx, w_idx,:],label='True')\n", |
490 | | - " axs[idx].plot(y_hat[series_idx, w_idx,:],label='Forecast')\n", |
491 | | - " axs[idx].grid()\n", |
492 | | - " axs[idx].set_ylabel(series[series_idx]+f' window {w_idx}', \n", |
493 | | - " fontsize=17)\n", |
494 | | - " if idx==2:\n", |
495 | | - " axs[idx].set_xlabel('Forecast Horizon', fontsize=17)\n", |
496 | | - "plt.legend()\n", |
497 | | - "plt.show()\n", |
498 | | - "plt.close()" |
| 456 | + "series_id = series[3] # 'LULL'\n", |
| 457 | + "\n", |
| 458 | + "series_cutoffs = Y_hat_df.loc[Y_hat_df['unique_id'] == \"LULL\", 'cutoff'].unique() \n", |
| 459 | + " \n", |
| 460 | + "for w_idx in [200, 300, 400]:\n", |
| 461 | + " cutoff = series_cutoffs[w_idx]\n", |
| 462 | + " plot_df = Y_hat_df.loc[Y_hat_df['cutoff'] == cutoff, ['unique_id', 'ds', 'y', 'AutoNHITS']]\n", |
| 463 | + "\n", |
| 464 | + " fig = plot_series(\n", |
| 465 | + " df=plot_df[['unique_id', 'ds', 'y']],\n", |
| 466 | + " forecasts_df=plot_df[['unique_id', 'ds', 'AutoNHITS']],\n", |
| 467 | + " ids=[series_id],\n", |
| 468 | + " models=['AutoNHITS'],\n", |
| 469 | + " max_insample_length=96\n", |
| 470 | + " )\n", |
| 471 | + " display(fig)" |
499 | 472 | ] |
500 | 473 | }, |
501 | 474 | { |
|
523 | 496 | } |
524 | 497 | ], |
525 | 498 | "source": [ |
526 | | - "from neuralforecast.losses.numpy import mae, mse\n", |
| 499 | + "from utilsforecast.evaluation import evaluate\n", |
| 500 | + "from utilsforecast.losses import mae, mse\n", |
| 501 | + "\n", |
| 502 | + "eval_df = evaluate(\n", |
| 503 | + " df=Y_hat_df.drop(columns=[\"cutoff\"]),\n", |
| 504 | + " metrics=[mae, mse],\n", |
| 505 | + " agg_fn=\"mean\"\n", |
| 506 | + ")\n", |
527 | 507 | "\n", |
528 | | - "print('MAE: ', mae(y_hat, y_true))\n", |
529 | | - "print('MSE: ', mse(y_hat, y_true))" |
| 508 | + "print('MAE: ', eval_df.iloc[0][\"AutoNHITS\"])\n", |
| 509 | + "print('MSE: ', eval_df.iloc[1][\"AutoNHITS\"])" |
530 | 510 | ] |
531 | 511 | }, |
532 | 512 | { |
|
0 commit comments