A label is the outcome value assigned to an example that a predictive model is trained to estimate. In market-direction prediction, labels encode whether the next-day move is bullish, bearish, or neutral; in fraud detection, they distinguish fraudulent from legitimate transactions. section 10.4.1 section 8.2.1
Label design determines which outcomes the model learns to distinguish:
- For SPY, next-day returns above +1% are bullish, below −1% are bearish, and returns between those thresholds are neutral. The threshold can be tuned to a trading strategy’s goals and tolerance for noise. section 10.4.1
- For credit-card transactions, Class 1 means fraud and Class 0 means legitimate. Fraud accounts for only about 0.17% of the dataset, creating severe class imbalance that affects modeling and metric choices. section 8.2.1
Listing 10.3 Creating realistic target labels
import numpy as np
def create_target_labels(data, threshold=0.01):
"""Create next-day directional labels with realistic thresholds"""
returns = data['SPY_close'].pct_change().shift(-1) #1
conditions = [
(returns > threshold), # Bullish moves
(returns < -threshold) # Bearish moves
]
choices = [1, -1] # 1: Up, -1: Down
data['target'] = np.select(conditions, choices, default=0) #2
return data.dropna()
etf_data_labeled = create_target_labels(etf_data)
print(f"Target distribution:\n{etf_data_labeled['target'].value_counts()}")
See Python code that derives next-day returns, assigns labels using a configurable threshold, and checks their distribution. section 10.4.1



















