Skip to content

chore: improve and add some missing docstrings #2663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions python/prophet/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ def cross_validation(model, horizon, period=None, initial=None, parallel=None, c
cutoffs: list of pd.Timestamp specifying cutoffs to be used during
cross validation. If not provided, they are generated as described
above.
parallel : {None, 'processes', 'threads', 'dask', object}
parallel: {None, 'processes', 'threads', 'dask', object}
How to parallelize the forecast computation. By default no parallelism
is used.

* None : No parallelism.
* 'processes' : Parallelize with concurrent.futures.ProcessPoolExectuor.
* 'threads' : Parallelize with concurrent.futures.ThreadPoolExecutor.
* None: No parallelism.
* 'processes': Parallelize with concurrent.futures.ProcessPoolExecutor.
* 'threads': Parallelize with concurrent.futures.ThreadPoolExecutor.
Note that some operations currently hold Python's Global Interpreter
Lock, so parallelizing with threads may be slower than training
sequentially.
* 'dask': Parallelize with Dask.
This requires that a dask.distributed Client be created.
* object : Any instance with a `.map` method. This method will
* object: Any instance with a `.map` method. This method will
be called with :func:`single_cutoff_forecast` and a sequence of
iterables where each element is the tuple of arguments to pass to
:func:`single_cutoff_forecast`
Expand Down Expand Up @@ -132,7 +132,7 @@ def map(self, func, *iterables):
extra_output_columns = [extra_output_columns]
predict_columns.extend([c for c in extra_output_columns if c not in predict_columns])

# Identify largest seasonality period
# Identify the largest seasonality period
period_max = 0.
for s in model.seasonalities.values():
period_max = max(period_max, s['period'])
Expand Down Expand Up @@ -214,7 +214,7 @@ def map(self, func, *iterables):

def single_cutoff_forecast(df, model, cutoff, horizon, predict_columns):
"""Forecast for single cutoff. Used in cross validation function
when evaluating for multiple cutoffs either sequentially or in parallel .
when evaluating for multiple cutoffs either sequentially or in parallel.

Parameters
----------
Expand Down Expand Up @@ -274,7 +274,7 @@ def prophet_copy(m, cutoff=None):
----------
m: Prophet model.
cutoff: pd.Timestamp or None, default None.
cuttoff Timestamp for changepoints member variable.
cutoff Timestamp for changepoints member variable.
changepoints are only retained if 'changepoints <= cutoff'

Returns
Expand Down Expand Up @@ -344,7 +344,7 @@ def performance_metrics(df, metrics=None, rolling_window=0.1, monthly=False):
"""Compute performance metrics from cross-validation results.

Computes a suite of performance metrics on the output of cross-validation.
By default the following metrics are included:
By default, the following metrics are included:
'mse': mean squared error
'rmse': root mean squared error
'mae': mean absolute error
Expand Down
18 changes: 17 additions & 1 deletion python/prophet/forecaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class Prophet(object):
uncertainty intervals. Settings this value to 0 or False will disable
uncertainty estimation and speed up the calculation.
stan_backend: str as defined in StanBackendEnum default: None - will try to
iterate over all available backends and find the working one
iterate over all available backends and find the working one.
scaling: 'absmax' (default) or 'minmax'.
holidays_mode: 'additive' or 'multiplicative'. Defaults to seasonality_mode.
"""

Expand Down Expand Up @@ -1541,6 +1542,15 @@ def sample_model_vectorized(
) -> List[Dict[str, np.ndarray]]:
"""Simulate observations from the extrapolated generative model. Vectorized version of sample_model().

Parameters
----------
df: Prediction dataframe.
seasonal_features: pd.DataFrame of seasonal features.
iteration: Int sampling iteration to use parameters from.
s_a: Indicator vector for additive components.
s_m: Indicator vector for multiplicative components.
n_samples: Number of future paths of the trend to simulate.

Returns
-------
List (length n_samples) of dictionaries with arrays for trend and yhat, each ordered like df['t'].
Expand Down Expand Up @@ -1619,6 +1629,12 @@ def sample_predictive_trend(self, df, iteration):
def sample_predictive_trend_vectorized(self, df: pd.DataFrame, n_samples: int, iteration: int = 0) -> np.ndarray:
"""Sample draws of the future trend values. Vectorized version of sample_predictive_trend().

Parameters
----------
df: Prediction dataframe.
iteration: Int sampling iteration to use parameters from.
n_samples: Number of future paths of the trend to simulate.

Returns
-------
Draws of the trend values with shape (n_samples, len(df)). Values are on the scale of the original data.
Expand Down
1 change: 1 addition & 0 deletions python/prophet/make_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def make_holidays_df(year_list, country, province=None, state=None):
----------
year_list: a list of years
country: country name
province: province name

Returns
-------
Expand Down
7 changes: 4 additions & 3 deletions python/prophet/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def plot_cross_validation_metric(
for each prediction, and aggregated over a rolling window with horizon.

This uses prophet.diagnostics.performance_metrics to compute the metrics.
Valid values of metric are 'mse', 'rmse', 'mae', 'mape', and 'coverage'.
Valid values of metric are 'mse', 'rmse', 'mae', 'mape', 'mdape', 'smape', and 'coverage'.

rolling_window is the proportion of data included in the rolling window of
aggregation. The default value of 0.1 means 10% of data are included in the
Expand All @@ -499,7 +499,7 @@ def plot_cross_validation_metric(
Parameters
----------
df_cv: The output from prophet.diagnostics.cross_validation.
metric: Metric name, one of ['mse', 'rmse', 'mae', 'mape', 'coverage'].
metric: Metric name, one of ['mse', 'rmse', 'mae', 'mape', 'mdape', 'smape', 'coverage'].
rolling_window: Proportion of data to use for rolling average of metric.
In [0, 1]. Defaults to 0.1.
ax: Optional matplotlib axis on which to plot. If not given, a new figure
Expand Down Expand Up @@ -579,6 +579,7 @@ def plot_plotly(m, fcst, uncertainty=True, plot_cap=True, trend=False, changepoi
changepoints_threshold: Threshold on trend change magnitude for significance.
xlabel: Optional label name on X-axis
ylabel: Optional label name on Y-axis
figsize: The plot's size (in px).

Returns
-------
Expand Down Expand Up @@ -775,7 +776,7 @@ def plot_components_plotly(


def plot_forecast_component_plotly(m, fcst, name, uncertainty=True, plot_cap=False, figsize=(900, 300)):
"""Plot an particular component of the forecast using Plotly.
"""Plot a particular component of the forecast using Plotly.
See plot_plotly() for Plotly setup instructions

Parameters
Expand Down
2 changes: 1 addition & 1 deletion python/prophet/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def regressor_coefficients(m):
Only different to `coef` if `mcmc_samples > 0`.
- `coef`: Expected value of the coefficient.
- `coef_upper`: Upper bound for the coefficient, estimated from MCMC samples.
Only to different to `coef` if `mcmc_samples > 0`.
Only different to `coef` if `mcmc_samples > 0`.
"""
assert len(m.extra_regressors) > 0, 'No extra regressors found.'
coefs = []
Expand Down