vp.features.velocity
Trailing-window counts, sum and distinct count (catalog/velocity.viv).
Part of the distribution vipyr; it runs from a checkout of the
repository. Planned on PyPI as pip install vipyr.
Signature
vp.features.velocity(df=None, n=500) Parameters
- df : pandas.DataFrame, default
None - The event table, rows in any order; None makes a synthetic one of n rows.
- n : int, default
500 - Rows of the synthetic table when df is None. Range: >= 1.
Returns
A frozen VelocityResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- frame : pandas.DataFrame
- The features, one row per input row, in the input's order and index: sum_24h, distinct_24h.
| column of frame | definition |
|---|---|
sum_24h | amount summed over the 24-hour window, left to right in canonical order |
distinct_24h | distinct merchants in the 24-hour window |
Raises
- TypeError
- An argument of the wrong type, or an unknown keyword.
- vipyr.VivBuildError
- An ImportError: no C compiler, or the program's C does not build.
Examples
import vipyr as vp
r = vp.features.velocity() # a synthetic table; pass df= for yours
print(r.frame.head())
assert r.check() n_1h n_24h sum_24h distinct_24h
0 0 0 0.00 0
1 0 1 99.35 1
2 0 1 5.70 1
3 0 2 42.11 2
4 0 0 0.00 0Each example ran as written when these pages were generated, and the output shown is what it printed.
Checked against
- Reference
- catalog.velocity_reference: a pandas groupby().apply() with a Python loop per row, equal bit for bit; vipyr.check_point_in_time: no feature reads a row after its own time
Source
- Viv: catalog/velocity.viv
- Viv: catalog/catalog.py
- The defs it reaches and the calls between them: map of the code