View source: R/ts-feature-cluster-tbl.R
ts_feature_cluster | R Documentation |
This function returns an output list of data and plots that
come from using the K-Means
clustering algorithm on a time series data.
ts_feature_cluster(
.data,
.date_col,
.value_col,
...,
.features = c("frequency", "entropy", "acf_features"),
.scale = TRUE,
.prefix = "ts_",
.centers = 3
)
.data |
The data passed must be a |
.date_col |
The date column. |
.value_col |
The column that holds the value of the time series where you want the features and clustering performed on. |
... |
This is where you can place grouping variables that are passed off
to |
.features |
This is a quoted string vector using c() of features that you
would like to pass. You can pass any feature you make or those from the |
.scale |
If TRUE, time series are scaled to mean 0 and sd 1 before features are computed |
.prefix |
A prefix to prefix the feature columns. Default: "ts_" |
.centers |
An integer of how many different centers you would like to generate. The default is 3. |
This function will return a list object output. The function itself
requires that a time series tibble/data.frame get passed to it, along with
the .date_col
, the .value_col
and a period of data. It uses the underlying
function timetk::tk_tsfeatures()
and takes the output of that and performs
a clustering analysis using the K-Means
algorithm.
The function has a parameter of .features
which can take any of the features
listed in the tsfeatures
package by Rob Hyndman. You can also create custom
functions in the .GlobalEnviron
and it will take them as quoted arguments.
So you can make a function as follows
my_mean <- function(x){return(mean(x, na.rm = TRUE))}
You can then call this by using .features = c("my_mean")
.
The output of this function includes the following:
Data Section
ts_feature_tbl
user_item_matrix_tbl
mapped_tbl
scree_data_tbl
input_data_tbl (the original data)
Plots
static_plot
plotly_plot
A list output
Steven P. Sanderson II, MPH
https://pkg.robjhyndman.com/tsfeatures/index.html
Other Clustering:
ts_feature_cluster_plot()
library(dplyr)
data_tbl <- ts_to_tbl(AirPassengers) %>%
mutate(group_id = rep(1:12, 12))
ts_feature_cluster(
.data = data_tbl,
.date_col = date_col,
.value_col = value,
group_id,
.features = c("acf_features","entropy"),
.scale = TRUE,
.prefix = "ts_",
.centers = 3
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.