Point-in-Time Correctness
Correctitud temporal en la recuperación de features históricos
Point-in-time correctness significa que, al construir un dataset de entrenamiento, cada fila de features corresponde al valor que esa feature tenía justo antes del evento que se quiere predecir. Si entrenas un modelo de churn con el evento ocurrido el 15 de enero, las features deben ser las del 14 de enero —o el momento más reciente anterior a esa fecha—, nunca valores calculados con datos posteriores.
La violación de point-in-time correctness introduce data leakage: el modelo aprende de información que no estaría disponible en el momento de la predicción real. Esto produce métricas de evaluación artificialmente altas durante el entrenamiento y un desempeño significativamente peor en producción. Es uno de los errores más comunes y difíciles de detectar en pipelines de ML.
Feast implementa point-in-time correctness a través de un join temporal: dado un dataframe de entidades con timestamps de referencia, recupera del offline store el valor de cada feature en el momento más reciente anterior al timestamp de referencia de cada fila. Este proceso se denomina 'as-of join' y es el mecanismo central para evitar leakage en el dataset de entrenamiento.
# Point-in-time correct feature retrieval with Feast
import pandas as pd
from feast import FeatureStore
from datetime import datetime
store = FeatureStore(repo_path='.')
# Entity dataframe: each row has the reference timestamp (label event date)
entity_df = pd.DataFrame({
'user_id': [101, 102, 103],
'event_timestamp': ['2025-01-14', '2025-02-03', '2025-03-20'],
'label': [1, 0, 1], # churn target
})
# Feast performs an as-of join: for each row, retrieves features
# as they existed at event_timestamp, not at query time
training_df = store.get_historical_features(
entity_df=entity_df,
features=[
'user_profile:age',
'user_profile:lifetime_value',
'user_activity:last_login_days',
],
).to_df()
# training_df has features as of each user's event_timestamp
print(training_df.head())Debugging lab
Detecta y corrige el error en el código.
- 01
# Training with current timestamp - data leakage! entity_df = pd.DataFrame({ 'user_id': [1, 2, 3], 'event_timestamp': datetime.now(), # Uses TODAY's date for historical events 'label': [1, 0, 1], })
- 02
# Fetching features without timestamps - no point-in-time guarantee training_df = store.get_historical_features( entity_df=pd.DataFrame({'user_id': [1, 2, 3]}), # No timestamps! features=['user_profile:age'], ).to_df()
- 03
# Using the same timestamp as the label event itself # Label: user churned on 2025-01-15 entity_df['event_timestamp'] = '2025-01-15' # Same date as churn event # Problem: features computed on 2025-01-15 may include same-day data