Combine sample weights

q.label.combine_weights multiplies non-negative weight components with identical indexes and optionally normalizes the result to unit mean.

Keeping components separate makes the training policy auditable: return attribution, recency, uniqueness, and class balancing can be inspected before they are combined.

import pandas as pd

import qrt as q

events = pd.date_range("2026-01-01", periods=5, name="event_time")
return_weight = pd.Series([0.4, 0.8, 1.2, 0.9, 1.4], index=events)
uniqueness = pd.Series([0.5, 0.7, 0.9, 0.8, 1.0], index=events)
decay = q.label.time_decay(uniqueness, minimum_weight=0.25)
combined = q.label.combine_weights(return_weight, uniqueness, decay)
pd.DataFrame({
    "return_weight": return_weight,
    "uniqueness": uniqueness,
    "time_decay": decay,
    "combined": combined,
})
return_weight uniqueness time_decay combined
event_time
2026-01-01 0.4 0.5 0.346154 0.114387
2026-01-02 0.8 0.7 0.480769 0.444840
2026-01-03 1.2 0.9 0.653846 1.166751
2026-01-04 0.9 0.8 0.807692 0.960854
2026-01-05 1.4 1.0 1.000000 2.313167

A zero component removes that event multiplicatively. When normalization is enabled, an all-zero result is rejected because it cannot define usable training weights.

Back to top