Scoring model
ScoringModel
¶
Abstract class that defines the interface for models that can score individual entities.
__call__
¶
__call__(
entity_id: int, entity_features: Optional[Series] = None
) -> Optional[tuple[float, float, float]]
Score a single entity and return its evaluation results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity_id
|
int
|
|
required |
entity_features
|
Optional[Series]
|
Features of the entity that may be used for scoring. |
None
|
Returns:
Type | Description |
---|---|
Optional[tuple[float, float, float]]
|
If scoring is successful, returns a tuple of three float values
representing (score, left_uncertainty, right_uncertainty). |
scored_entities
¶
Get the set of entity IDs that can be scored by this model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entities
|
Optional[DataFrame]
|
DataFrame containing entities to score with their features. |
None
|
Returns:
Type | Description |
---|---|
set[int]
|
Set of entity IDs that are available for scoring. |
iter_entities
¶
Iterate over all available entities and yield their scoring results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entities
|
DataFrame
|
DataFrame containing entity features. |
None
|
Yields:
Type | Description |
---|---|
tuple[int, tuple[float, float, float]]
|
Pairs of (entity_id, scoring_results) for each entity that can be scored. |
Notes
This method provides a default implementation that calls scored_entities()
to get available IDs and __call__()
to score each entity.
DirectScoringModel
¶
ScaledScoringModel
¶
ScaledScoringModel(
base_model: ScoringModel,
multiplicator: float = 1.0,
translation: float = 0.0,
multiplicator_left_uncertainty: float = 0.0,
multiplicator_right_uncertainty: float = 0.0,
translation_left_uncertainty: float = 0.0,
translation_right_uncertainty: float = 0.0,
)
Bases: ScoringModel
A ScoringModel
with scaling parameters applied.
When base_model
is itself a scaled scoring model,
the scalings are aggregated, so that the base model is actually
the scaled scoring model's base model.
Note
Note that this requires aggregating the uncertainties in a heuristic manner. At the core, this is because the uncertainties should grow quadratically with the size of the scores. Put differently, because of uncertainties, the composition of scaled scoring models is not an internal composition law (but it is if uncertainties are not accounted for).
multiplicator_left_uncertainty
¶
multiplicator_left_uncertainty = (
multiplicator_left_uncertainty
+ multiplicator * multiplicator_left_uncertainty
)
multiplicator_right_uncertainty
¶
multiplicator_right_uncertainty = (
multiplicator_right_uncertainty
+ multiplicator * multiplicator_right_uncertainty
)
translation_left_uncertainty
¶
translation_left_uncertainty = (
translation_left_uncertainty
+ multiplicator * translation_left_uncertainty
)
translation_right_uncertainty
¶
translation_right_uncertainty = (
translation_right_uncertainty
+ multiplicator * translation_right_uncertainty
)
scale_score
¶
PostProcessedScoringModel
¶
PostProcessedScoringModel(
base_model: ScoringModel, post_process: Callable
)
Bases: ScoringModel
Defines a derived scoring model, based on a base model and a post process
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_model
|
ScoringModel
|
|
required |
post_process
|
Callable
|
Must be a monotonous function float -> float |
required |