outliers.md (prophet-1.1) | : | outliers.md (prophet-1.1.1) | ||
---|---|---|---|---|

skipping to change at line 12 | skipping to change at line 12 | |||

layout: docs | layout: docs | |||

docid: "outliers" | docid: "outliers" | |||

title: "Outliers" | title: "Outliers" | |||

permalink: /docs/outliers.html | permalink: /docs/outliers.html | |||

subsections: | subsections: | |||

--- | --- | |||

There are two main ways that outliers can affect Prophet forecasts. Here we make a forecast on the logged Wikipedia visits to the R page from before, but with a block of bad data: | There are two main ways that outliers can affect Prophet forecasts. Here we make a forecast on the logged Wikipedia visits to the R page from before, but with a block of bad data: | |||

```R | ```R | |||

# R | # R | |||

df <- read.csv('../examples/example_wp_log_R_outliers1.csv') | df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples /example_wp_log_R_outliers1.csv') | |||

m <- prophet(df) | m <- prophet(df) | |||

future <- make_future_dataframe(m, periods = 1096) | future <- make_future_dataframe(m, periods = 1096) | |||

forecast <- predict(m, future) | forecast <- predict(m, future) | |||

plot(m, forecast) | plot(m, forecast) | |||

``` | ``` | |||

```python | ```python | |||

# Python | # Python | |||

df = pd.read_csv('../examples/example_wp_log_R_outliers1.csv') | df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/exampl es/example_wp_log_R_outliers1.csv') | |||

m = Prophet() | m = Prophet() | |||

m.fit(df) | m.fit(df) | |||

future = m.make_future_dataframe(periods=1096) | future = m.make_future_dataframe(periods=1096) | |||

forecast = m.predict(future) | forecast = m.predict(future) | |||

fig = m.plot(forecast) | fig = m.plot(forecast) | |||

``` | ``` | |||

![png](/prophet/static/outliers_files/outliers_4_0.png) | ![png](/prophet/static/outliers_files/outliers_4_0.png) | |||

The trend forecast seems reasonable, but the uncertainty intervals seem way too wide. Prophet is able to handle the outliers in the history, but only by fitting them with trend changes. The uncertainty model then expects future trend change s of similar magnitude. | The trend forecast seems reasonable, but the uncertainty intervals seem way too wide. Prophet is able to handle the outliers in the history, but only by fitting them with trend changes. The uncertainty model then expects future trend change s of similar magnitude. | |||

skipping to change at line 56 | skipping to change at line 56 | |||

model = Prophet().fit(df) | model = Prophet().fit(df) | |||

fig = model.plot(model.predict(future)) | fig = model.plot(model.predict(future)) | |||

``` | ``` | |||

![png](/prophet/static/outliers_files/outliers_7_0.png) | ![png](/prophet/static/outliers_files/outliers_7_0.png) | |||

In the above example the outliers messed up the uncertainty estimation but did n ot impact the main forecast `yhat`. This isn't always the case, as in this examp le with added outliers: | In the above example the outliers messed up the uncertainty estimation but did n ot impact the main forecast `yhat`. This isn't always the case, as in this examp le with added outliers: | |||

```R | ```R | |||

# R | # R | |||

df <- read.csv('../examples/example_wp_log_R_outliers2.csv') | df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples /example_wp_log_R_outliers2.csv') | |||

m <- prophet(df) | m <- prophet(df) | |||

future <- make_future_dataframe(m, periods = 1096) | future <- make_future_dataframe(m, periods = 1096) | |||

forecast <- predict(m, future) | forecast <- predict(m, future) | |||

plot(m, forecast) | plot(m, forecast) | |||

``` | ``` | |||

```python | ```python | |||

# Python | # Python | |||

df = pd.read_csv('../examples/example_wp_log_R_outliers2.csv') | df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/exampl es/example_wp_log_R_outliers2.csv') | |||

m = Prophet() | m = Prophet() | |||

m.fit(df) | m.fit(df) | |||

future = m.make_future_dataframe(periods=1096) | future = m.make_future_dataframe(periods=1096) | |||

forecast = m.predict(future) | forecast = m.predict(future) | |||

fig = m.plot(forecast) | fig = m.plot(forecast) | |||

``` | ``` | |||

![png](/prophet/static/outliers_files/outliers_10_0.png) | ![png](/prophet/static/outliers_files/outliers_10_0.png) | |||

Here a group of extreme outliers in June 2015 mess up the seasonality estimate, so their effect reverberates into the future forever. Again the right approach i s to remove them: | Here a group of extreme outliers in June 2015 mess up the seasonality estimate, so their effect reverberates into the future forever. Again the right approach i s to remove them: | |||

End of changes. 4 change blocks. | ||||

4 lines changed or deleted | | 4 lines changed or added |