An open API service indexing awesome lists of open source software.

https://github.com/tidyverts/feasts

Feature Extraction And Statistics for Time Series
https://github.com/tidyverts/feasts

Last synced: about 1 month ago
JSON representation

Feature Extraction And Statistics for Time Series

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(width = 100)
```

# feasts

[![R build status](https://github.com/tidyverts/feasts/workflows/R-CMD-check/badge.svg)](https://github.com/tidyverts/feasts/actions?workflow=R-CMD-check)
[![Coverage status](https://codecov.io/gh/tidyverts/feasts/branch/master/graph/badge.svg)](https://app.codecov.io/gh/tidyverts/feasts?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/feasts)](https://CRAN.R-project.org/package=feasts)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)

## Overview

feasts provides a collection of tools for the analysis of time series data. The package name is an acronym comprising of its key features: *Feature Extraction And Statistics for Time Series*.

The package works with tidy temporal data provided by the [tsibble](https://github.com/tidyverts/tsibble) package to produce time series features, decompositions, statistical summaries and convenient visualisations. These features are useful in understanding the behaviour of time series data, and closely integrates with the tidy forecasting workflow used in the [fable](https://github.com/tidyverts/fable) package.

## Installation

You could install the **stable** version from [CRAN](https://cran.r-project.org/package=feasts):

```{r, eval = FALSE}
install.packages("feasts")
```

You can install the **development** version from
[GitHub](https://github.com/tidyverts/feasts) with:

```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("tidyverts/feasts")
```

## Usage

```{r pkgs, message = FALSE, warning = FALSE}
library(feasts)
library(tsibble)
library(tsibbledata)
library(dplyr)
library(ggplot2)
library(lubridate)
```

### Graphics

Visualisation is often the first step in understanding the patterns in time series data. The package uses [ggplot2](https://github.com/tidyverse/ggplot2) to produce customisable graphics to visualise time series patterns.

```{r graphics, fig.height=3}
aus_production %>% gg_season(Beer)
aus_production %>% gg_subseries(Beer)
aus_production %>% filter(year(Quarter) > 1991) %>% gg_lag(Beer)
aus_production %>% ACF(Beer) %>% autoplot()
```

### Decompositions

A common task in time series analysis is decomposing a time series into some simpler components. The feasts package supports two common time series decomposition methods:

* Classical decomposition
* STL decomposition

```{r dcmp}
dcmp <- aus_production %>%
model(STL(Beer ~ season(window = Inf)))
components(dcmp)
```
```{r dcmp-plot}
components(dcmp) %>% autoplot()
```

### Feature extraction and statistics

Extract features and statistics across a large collection of time series to identify unusual/extreme time series, or find clusters of similar behaviour.

```{r features}
aus_retail %>%
features(Turnover, feat_stl)
```

This allows you to visualise the behaviour of many time series (where the plotting methods above would show too much information).

```{r features-plot}
aus_retail %>%
features(Turnover, feat_stl) %>%
ggplot(aes(x = trend_strength, y = seasonal_strength_year)) +
geom_point() +
facet_wrap(vars(State))
```

Most of Australian's retail industries are highly trended and seasonal for all states.

It's also easy to extract the most (and least) seasonal time series.

```{r extreme}
extreme_seasonalities <- aus_retail %>%
features(Turnover, feat_stl) %>%
filter(seasonal_strength_year %in% range(seasonal_strength_year))
aus_retail %>%
right_join(extreme_seasonalities, by = c("State", "Industry")) %>%
ggplot(aes(x = Month, y = Turnover)) +
geom_line() +
facet_grid(vars(State, Industry, scales::percent(seasonal_strength_year)),
scales = "free_y")
```