Time Series functions
Analyze and manipulate time-based data.
Time series functions analyze and manipulate time-based data, enabling:
- Outlier detection
- Trend analysis
- Data aggregation over time intervals
These functions extract insights from temporal datasets like financial data, IoT sensor readings, and other time-stamped information.
Time Series API
Explore our Time Series API for easily fetching ready-to-chart time series data.
ClickHouse function reference
seriesOutliersDetectTukey
Detects outliers in series data using Tukey’s fences method.
Syntax:
Arguments:
series
(Array
of numeric values): The input series data.min_percentile
(Float64
, optional): The minimum percentile for calculating the interquartile range (IQR). Default: 0.25. Must be in range [0.02, 0.98].max_percentile
(Float64
, optional): The maximum percentile for calculating the IQR. Default: 0.75. Must be in range [0.02, 0.98].K
(Float64
, optional): Non-negative constant to detect mild or stronger outliers. Default: 1.5.
Returns:
An array of the same length as the input, where each value represents the anomaly score of the corresponding element. A non-zero score indicates a possible anomaly. [Array(Float64)
]
- At least four data points are required in the series to detect outliers.
- The function uses the interquartile range (IQR) method to identify outliers.
Example:
Result:
In this example, we analyze taco sales data to detect any unusual spikes. The value 100 is identified as an outlier with a score of 67.5, while all other values have a score of 0, indicating they are within the expected range.
seriesPeriodDetectFFT
Finds the period of the given series data using Fast Fourier Transform (FFT).
Syntax:
Arguments:
series
(Array(numeric)
): An array of numeric values representing the time series data.
Returns:
A real value equal to the period of the series data. Returns NaN
when the number of data points is less than four. [Float64
]
Example:
Result:
In this example, we analyze the periodicity of taco sales data. The function detects a period of 5, indicating that the sales pattern repeats every 5 data points.
- The function requires at least four data points to detect a period.
- FFT is particularly useful for detecting regular patterns or cycles in time series data, which can be valuable for forecasting or identifying seasonal trends in taco sales or production.
seriesDecomposeSTL
Decomposes a time series into seasonal, trend, and residual components using the STL (Seasonal-Trend Decomposition Procedure Based on Loess) algorithm.
Syntax:
Arguments:
series
(Array(numeric)
): An array of numeric values representing the time series data.period
(UInt32
): A positive integer representing the expected periodicity of the seasonal component.
Returns:
An array containing four arrays, each representing a component of the decomposition:
- Seasonal component
- Trend component
- Residual component
- Baseline component (seasonal + trend)
The number of data points in the input series should be at least twice the value of the period
argument.
Example:
Result:
In this example, we decompose a series of taco sales data with a period of 3. The result shows:
- The seasonal pattern of sales fluctuations
- The overall trend of increasing sales
- The residual (unexplained) variations
- The baseline sales (seasonal + trend)
This decomposition can help identify patterns, trends, and anomalies in your taco sales data.