TimeBinAggregate
Bins time series and aggregates by bin.
In transform, applies groupby with aggfunc on the temporal coordinate.
More precisely: bins encodes bins \(B_1, \dots, B_k\) where \(B_i\) are intervals, in the reals or in a temporal (time stamp) range.
In transform, the estimator TimeBinAggregate collects values at time stamps of X falling into \(B_i\) as a sample \(S_i\), and then applies aggfunc to \(S_i\) to obtain an aggregate value \(v_i\). The transformed series are values \(v_i\) at time stamps \(t_i\), determined from \(B_i\) per the rule in return_index.
Quickstart
from sktime.transformations.binning import TimeBinAggregate
estimator = TimeBinAggregate(bins, aggfunc=None, return_index='bin_start')Parameters(3)
- bins1D array-like or pd.IntervalIndex
- if 1D array-like, is interpreted as breaks of bins breaks of bins defining intervals considered by aggfunc
- aggfunccallable * 1D array-like -> float), optional, default=np.mean
- Function used to aggregate the values in intervals. Should have signature 1D -> float and defaults to mean if None
- return_indexstr, one of the below; optional, default=”range”
"range"=RangeIndexwith bins indexed in same order as inbins"bin_start"= transformed pd.DataFrame will be indexed by bin starts"bin_end"= transformed pd.DataFrame will be indexed by bin ends"bin_mid"= transformed pd.DataFrame will be indexed by bin midpoints"bin"= transformed pd.DataFrame will havebinsasIntervalIndex
Examples
Basic usage:
>>> import pandas as pd
>>> from sktime.transformations.binning import TimeBinAggregate
>>> X = pd. DataFrame (
... { "a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]}, index = list (range (10))
... )
>>> t = TimeBinAggregate (bins = [- 1, 2, 5, 10 ])
>>> t. fit_transform (X) 0 -1 2.0 2 5.0 5 8.5 Using return_index="range" to get a plain sequential index instead of bin starts:
>>> t2 = TimeBinAggregate (bins = [- 1, 2, 5, 10 ], return_index = "range")
>>> t2. fit_transform (X) 0 0 2.0 1 5.0 2 8.5 Using return_index="bin_end" to index by the end of each bin instead:
>>> t3 = TimeBinAggregate (bins = [- 1, 2, 5, 10 ], return_index = "bin_end")
>>> t3. fit_transform (X) 0 2 2.0 5 5.0 10 8.5