Add a seasonal component with specified period, number of Fourier components, and prior scale. Increasing the number of Fourier components allows the seasonality to change more quickly (at risk of overfitting). Default values for yearly and weekly seasonalities are 1
(self, name, period, fourier_order, prior_scale=None,
mode=None, condition_name=None)
| 680 | return self |
| 681 | |
| 682 | def add_seasonality(self, name, period, fourier_order, prior_scale=None, |
| 683 | mode=None, condition_name=None): |
| 684 | """Add a seasonal component with specified period, number of Fourier |
| 685 | components, and prior scale. |
| 686 | |
| 687 | Increasing the number of Fourier components allows the seasonality to |
| 688 | change more quickly (at risk of overfitting). Default values for yearly |
| 689 | and weekly seasonalities are 10 and 3 respectively. |
| 690 | |
| 691 | Increasing prior scale will allow this seasonality component more |
| 692 | flexibility, decreasing will dampen it. If not provided, will use the |
| 693 | seasonality_prior_scale provided on Prophet initialization (defaults |
| 694 | to 10). |
| 695 | |
| 696 | Mode can be specified as either 'additive' or 'multiplicative'. If not |
| 697 | specified, self.seasonality_mode will be used (defaults to additive). |
| 698 | Additive means the seasonality will be added to the trend, |
| 699 | multiplicative means it will multiply the trend. |
| 700 | |
| 701 | If condition_name is provided, the dataframe passed to `fit` and |
| 702 | `predict` should have a column with the specified condition_name |
| 703 | containing booleans which decides when to apply seasonality. |
| 704 | |
| 705 | Parameters |
| 706 | ---------- |
| 707 | name: string name of the seasonality component. |
| 708 | period: float number of days in one period. |
| 709 | fourier_order: int number of Fourier components to use. |
| 710 | prior_scale: optional float prior scale for this component. |
| 711 | mode: optional 'additive' or 'multiplicative' |
| 712 | condition_name: string name of the seasonality condition. |
| 713 | |
| 714 | Returns |
| 715 | ------- |
| 716 | The prophet object. |
| 717 | """ |
| 718 | if self.history is not None: |
| 719 | raise Exception( |
| 720 | 'Seasonality must be added prior to model fitting.') |
| 721 | if name not in ['daily', 'weekly', 'yearly']: |
| 722 | # Allow overwriting built-in seasonalities |
| 723 | self.validate_column_name(name, check_seasonalities=False) |
| 724 | if prior_scale is None: |
| 725 | ps = self.seasonality_prior_scale |
| 726 | else: |
| 727 | ps = float(prior_scale) |
| 728 | if ps <= 0: |
| 729 | raise ValueError('Prior scale must be > 0') |
| 730 | if fourier_order <= 0: |
| 731 | raise ValueError('Fourier Order must be > 0') |
| 732 | if mode is None: |
| 733 | mode = self.seasonality_mode |
| 734 | if mode not in ['additive', 'multiplicative']: |
| 735 | raise ValueError('mode must be "additive" or "multiplicative"') |
| 736 | if condition_name is not None: |
| 737 | self.validate_column_name(condition_name) |
| 738 | self.seasonalities[name] = { |
| 739 | 'period': period, |