onlinerake.Targets¶
- class onlinerake.Targets(**kwargs: float)[source]¶
Bases:
objectTarget population proportions for binary features.
A flexible container for specifying target proportions for any set of binary features. Each feature should have a proportion between 0 and 1 representing the fraction of the population where that feature is True/1.
- Parameters:
**kwargs – Named feature proportions. Each key is a feature name and each value is the target proportion (between 0 and 1) for that feature being 1/True.
Examples
>>> # Product preferences >>> targets = Targets(owns_car=0.4, is_subscriber=0.2, likes_coffee=0.7) >>> print(targets.feature_names) ['is_subscriber', 'likes_coffee', 'owns_car']
>>> # Medical indicators >>> targets = Targets(has_diabetes=0.08, exercises=0.35, smoker=0.15)
>>> # Access target values >>> print(targets['owns_car']) 0.4
>>> # Check if feature exists >>> print('owns_car' in targets) True
- Raises:
ValueError – If any target proportion is not between 0 and 1.
Note
Feature names are stored in sorted order for consistent behavior across different Python versions and hash randomization settings.
Methods
Attributes
Get ordered list of feature names.
Get number of features.
- as_dict() dict[str, float][source]¶
Convert targets to a dictionary.
Examples
>>> targets = Targets(owns_car=0.4, is_subscriber=0.2) >>> targets.as_dict() {'owns_car': 0.4, 'is_subscriber': 0.2}