Skip to content

Commit

Permalink
pkgdown: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdancho84 committed May 29, 2020
1 parent 17f4f41 commit 6ae410b
Show file tree
Hide file tree
Showing 81 changed files with 26,526 additions and 234 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
^README\.Rmd$
^doc$
^Meta$
^_pkgdown\.yml$
^docs$
^pkgdown$
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# modeltime 0.0.0.9000

* Working on essential package functionality
4 changes: 2 additions & 2 deletions R/dials-ts_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#' period()
#'
#'
#' @name arima_params
#' @name time_series_params


#' @export
#' @rdname arima_params
#' @rdname time_series_params
period <- function(range = c(1L, 12L), trans = NULL) {
dials::new_quant_param(
type = "integer",
Expand Down
100 changes: 8 additions & 92 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ knitr::opts_chunk$set(
<!-- badges: start -->
<!-- badges: end -->

A scalable time series forecasting framework and workflow for use with the `tidymodels` ecosystem.
A scalable time series forecasting toolset that __combines classical algorithms and machine learning into 1 framework.__

```{r, echo=F, out.width='70%', fig.align='center'}
knitr::include_graphics("vignettes/forecast_plot.jpg")
```


## Features & Benefits

Expand All @@ -30,100 +35,11 @@ Modeltime has a few key features and benefits:
1. __Interactive Plotting by default__ - Modeling algorithms have strengths and weaknesses that come to light when visualized interactively.
2. __Use Classical Algorithms and Machine Learning Algorithms together__ - No need to switch back and forth between various frameworks. `modeltime` unlocks machine learning & classical time series analysis.

## ARIMA Example

Load libraries.

```{r}
library(modeltime)
library(tidyverse)
library(lubridate)
library(timetk)
library(parsnip)
library(rsample)
```

### Step 1 - Collect data and split into training and test sets.

```{r}
# Data
m750 <- m4_monthly %>% filter(id == "M750")
# Split Data 80/20
splits <- initial_time_split(m750, prop = 0.9)
```


### Step 2 - Fit Models

Fit ARIMA models to a training set. We have included some classic time series models and some new boosted versions:

- __Auto ARIMA__ (see `arima_reg()`)
- __Auto ARIMA + XGBoost__ - XGBoosted ARIMA Errors! (see `arima_boost()`)

```{r, message = F}
# Model 1: auto_arima ----
model_fit_no_boost <- arima_reg() %>%
set_engine(engine = "auto_arima") %>%
fit(value ~ date, data = training(splits))
# Model 2: arima_boost ----
model_fit_boosted <- arima_boost(
min_n = 2,
learn_rate = 0.015
) %>%
set_engine(engine = "auto_arima_xgboost") %>%
fit(value ~ date + as.numeric(date) + month(date, label = TRUE),
data = training(splits))
```

### Step 3 - Add fitted models to a Model Table.
## Tutorials

Add as many models as you'd like. The analysis scales with multiple models.
- Getting Started - A walkthrough of the 6-Step Process for using `modeltime` to forecast

```{r, paged.print = FALSE}
models_tbl <- modeltime_table(
model_fit_no_boost,
model_fit_boosted
)
models_tbl
```

### Step 4 - Calibrate the model to a training set.

Calibrating adds a new column, `.calibration_data`, with the test predictions and residuals inside. This is how confidence intervals and accuracy metrics are determined from out-of-sample predictions.

```{r, paged.print = FALSE}
calibration_tbl <- models_tbl %>%
modeltime_calibrate(new_data = testing(splits))
calibration_tbl
```

### Step 5 - Forecast vs Testing Set

Visualizing the Test Error is easy to do. And you get an out-of-sample confidence interval.

```{r}
calibration_tbl %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = m750
) %>%
plot_modeltime_forecast(.interactive = FALSE)
```

### Step 6 - Refit to Full Dataset & Forecast Forward

```{r, message=F, paged.print = FALSE}
refit_tbl <- calibration_tbl %>%
modeltime_refit(data = m750)
refit_tbl %>%
modeltime_forecast(h = "3 years", actual_data = m750) %>%
plot_modeltime_forecast(.interactive = FALSE)
```



Expand Down
125 changes: 7 additions & 118 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

<!-- badges: end -->

A scalable time series forecasting framework and workflow for use with
the `tidymodels` ecosystem.
A scalable time series forecasting toolset that **combines classical
algorithms and machine learning into 1 framework.**

<img src="vignettes/forecast_plot.jpg" width="70%" style="display: block; margin: auto;" />

## Features & Benefits

Expand All @@ -22,123 +24,10 @@ Modeltime has a few key features and benefits:
frameworks. `modeltime` unlocks machine learning & classical time
series analysis.

## ARIMA Example

Load libraries.

``` r
library(modeltime)
library(tidyverse)
library(lubridate)
library(timetk)
library(parsnip)
library(rsample)
```

### Step 1 - Collect data and split into training and test sets.

``` r
# Data
m750 <- m4_monthly %>% filter(id == "M750")

# Split Data 80/20
splits <- initial_time_split(m750, prop = 0.9)
```

### Step 2 - Fit Models

Fit ARIMA models to a training set. We have included some classic time
series models and some new boosted versions:

- **Auto ARIMA** (see `arima_reg()`)
- **Auto ARIMA + XGBoost** - XGBoosted ARIMA Errors\! (see
`arima_boost()`)

<!-- end list -->

``` r
# Model 1: auto_arima ----
model_fit_no_boost <- arima_reg() %>%
set_engine(engine = "auto_arima") %>%
fit(value ~ date, data = training(splits))

# Model 2: arima_boost ----
model_fit_boosted <- arima_boost(
min_n = 2,
learn_rate = 0.015
) %>%
set_engine(engine = "auto_arima_xgboost") %>%
fit(value ~ date + as.numeric(date) + month(date, label = TRUE),
data = training(splits))
```

### Step 3 - Add fitted models to a Model Table.

Add as many models as you’d like. The analysis scales with multiple
models.

``` r
models_tbl <- modeltime_table(
model_fit_no_boost,
model_fit_boosted
)

models_tbl
#> # Modeltime Table
#> # A tibble: 2 x 3
#> .model_id .model .model_desc
#> <int> <list> <chr>
#> 1 1 <fit[+]> ARIMA(0,1,1)(0,1,1)[12]
#> 2 2 <fit[+]> ARIMA(0,1,1)(0,1,1)[12] W/ XGBOOST ERRORS
```

### Step 4 - Calibrate the model to a training set.

Calibrating adds a new column, `.calibration_data`, with the test
predictions and residuals inside. This is how confidence intervals and
accuracy metrics are determined from out-of-sample predictions.

``` r
calibration_tbl <- models_tbl %>%
modeltime_calibrate(new_data = testing(splits))

calibration_tbl
#> # Modeltime Table
#> # A tibble: 2 x 5
#> .model_id .model .model_desc .type .calibration_da…
#> <int> <list> <chr> <chr> <list>
#> 1 1 <fit[+]> ARIMA(0,1,1)(0,1,1)[12] Test <tibble [31 × 4…
#> 2 2 <fit[+]> ARIMA(0,1,1)(0,1,1)[12] W/ XGBOOST … Test <tibble [31 × 4…
```

### Step 5 - Forecast vs Testing Set

Visualizing the Test Error is easy to do. And you get an out-of-sample
confidence interval.

``` r
calibration_tbl %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = m750
) %>%
plot_modeltime_forecast(.interactive = FALSE)
```

<img src="man/figures/README-unnamed-chunk-7-1.png" width="100%" />

### Step 6 - Refit to Full Dataset & Forecast Forward

``` r
refit_tbl <- calibration_tbl %>%
modeltime_refit(data = m750)

refit_tbl %>%
modeltime_forecast(h = "3 years", actual_data = m750) %>%
plot_modeltime_forecast(.interactive = FALSE)
```
## Tutorials

<img src="man/figures/README-unnamed-chunk-8-1.png" width="100%" />
- Getting Started - A walkthrough of the 6-Step Process for using
`modeltime` to forecast

## Installation

Expand Down
65 changes: 65 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
destination: docs

template:
params:
bootswatch: flatly
ganalytics: UA-76139189-2

navbar:
title: "modeltime"
left:
- icon: fa-home
href: index.html
- text: "Getting Started"
href: articles/getting-started-with-modeltime.html
- text: "Key Functions"
href: reference/index.html
- text: "Articles"
href: articles/index.html
menu:
- text: 'Getting Started with Modeltime'
href: articles/getting-started-with-modeltime.html
- text: "News"
href: news/index.html

right:
- icon: fa-github
href: https://github.com/business-science/modeltime

reference:
- title: Modeltime Workflow
desc: The main workflow functions for scalable time series modeling.
contents:
- modeltime_table
- modeltime_calibrate
- modeltime_forecast
- starts_with("modeltime_")
- starts_with("plot_modeltime")
- default_forecast_accuracy_metric_set
- title: Algorithms
desc: The `parsnip`-adjacent algorithms that implement time series models.
contents:
- arima_reg
- arima_boost
- exp_smoothing
- title: Parameters
desc: The `dials` parameter functions that support hyperparameter tuning with `tune`.
contents:
- period
- starts_with("non_seasonal")
- error
- title: Developer Tools
desc: Tools for extending `modeltime`.
contents:
- new_modeltime_bridge
- create_xreg_recipe
- juice_xreg_recipe
- parse_index_from_data
- get_model_description
- get_arima_description

repo:
url:
home: https://github.com/business-science/modeltime
source: https://github.com/business-science/modeltime/blob/master/
issue: https://github.com/business-science/modeltime/issues/
Loading

0 comments on commit 6ae410b

Please sign in to comment.