Linear time decay

q.label.time_decay creates linear recency factors from cumulative sample importance. Average uniqueness is a common input because elapsed progress then reflects independent information rather than raw row count.

minimum_weight controls the oldest intercept. A value of 1 disables decay without changing alignment.

import pandas as pd

import qrt as q

events = pd.date_range("2026-01-01", periods=6, name="event_time")
uniqueness = pd.Series([0.4, 0.6, 0.5, 0.8, 0.7, 1.0], index=events)
comparison = pd.DataFrame({
    "uniqueness": uniqueness,
    "decay from zero": q.label.time_decay(uniqueness),
    "preserve 25%": q.label.time_decay(uniqueness, minimum_weight=0.25),
    "no decay": q.label.time_decay(uniqueness, minimum_weight=1.0),
})
comparison
uniqueness decay from zero preserve 25% no decay
event_time
2026-01-01 0.4 0.100 0.32500 1.0
2026-01-02 0.6 0.250 0.43750 1.0
2026-01-03 0.5 0.375 0.53125 1.0
2026-01-04 0.8 0.575 0.68125 1.0
2026-01-05 0.7 0.750 0.81250 1.0
2026-01-06 1.0 1.000 1.00000 1.0

The factors are ordered by the input index and reach 1 at the newest event. Multiply them into other aligned components with combine_weights.

Back to top