onlinerake.Targets¶

class onlinerake.Targets(**kwargs: float)[source]¶

Bases: object

Target 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.

_targets¶

Internal storage of target proportions.

Type:

dict[str, float]

_feature_names¶

Sorted list of feature names for consistent ordering.

Type:

list[str]

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.

__init__(**kwargs: float) None[source]¶

Methods

__init__(**kwargs)

as_dict()

Convert targets to a dictionary.

Attributes

feature_names

Get ordered list of feature names.

n_features

Get number of features.

as_dict() dict[str, float][source]¶

Convert targets to a dictionary.

Returns:

Dictionary mapping feature names to target proportions.

Return type:

dict[str, float]

Examples

>>> targets = Targets(owns_car=0.4, is_subscriber=0.2)
>>> targets.as_dict()
{'owns_car': 0.4, 'is_subscriber': 0.2}
property feature_names: list[str]¶

Get ordered list of feature names.

Returns:

Sorted list of feature names.

Return type:

list[str]

Examples

>>> targets = Targets(b=0.5, a=0.3, c=0.7)
>>> targets.feature_names
['a', 'b', 'c']
property n_features: int¶

Get number of features.

Returns:

Number of features defined in these targets.

Return type:

int

Examples

>>> targets = Targets(a=0.5, b=0.3, c=0.7)
>>> targets.n_features
3