labels.projection¶
Block-to-window label projection following time_spec.md Section 6.
Projection rules¶
- A window is labeled only when its entire
[bucket_start_ts, bucket_end_ts)falls within a single labeled block. - Windows covered by multiple blocks with conflicting labels are dropped.
- Windows that only partially overlap a block are dropped.
- Unlabeled windows are dropped (not used in supervised training).
- When a span carries a
user_id, it only matches features with the sameuser_id.
Usage¶
from taskclf.labels.projection import project_blocks_to_windows
projected_df = project_blocks_to_windows(features_df, label_spans)
The returned DataFrame contains only the cleanly-labeled windows, with an added label column.
taskclf.labels.projection
¶
Block-to-window label projection following time_spec.md Section 6.
Manual labeling is done in time blocks (LabelSpan instances). This module projects those blocks onto fixed-width feature windows using strict containment rules so only cleanly-labeled windows enter the training set.
project_blocks_to_windows(features_df, label_spans, bucket_seconds=DEFAULT_BUCKET_SECONDS)
¶
Assign labels from label_spans to feature windows using strict containment.
Projection rules (per time_spec.md Section 6):
- A window is labeled only when its entire
[bucket_start_ts, bucket_end_ts)interval falls within a single labeled block. - Windows overlapping multiple labeled blocks are dropped.
- Windows that only partially overlap a block are dropped.
- Unlabeled windows are dropped (not used in supervised training).
- When a span carries a
user_id, it only matches feature rows with the sameuser_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features_df
|
DataFrame
|
Feature DataFrame. Must contain |
required |
label_spans
|
Sequence[LabelSpan]
|
Label spans (blocks) to project. |
required |
bucket_seconds
|
int
|
Window width in seconds (used to derive
|
DEFAULT_BUCKET_SECONDS
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of features_df containing only the windows that satisfy |
DataFrame
|
the strict containment rule, with an added |