pdstools.infinity.resources.prediction_studio.v24_2.champion_challenger¶
Attributes¶
Classes¶
The ChampionChallenger class manages champion and challenger models |
Module Contents¶
- logger¶
- class ChampionChallenger(client, prediction_id: str, active_model: pdstools.infinity.resources.prediction_studio.v24_2.model.Model, cc_id: str | None = None, context: str | None = None, category: str | None = None, challenger_model: pdstools.infinity.resources.prediction_studio.v24_2.model.Model | None = None, champion_percentage: float | None = None, model_objective: str | None = None)¶
Bases:
pdstools.infinity.resources.prediction_studio.base.ChampionChallenger
The ChampionChallenger class manages champion and challenger models within a prediction context. It provides functionalities for:
Refreshing champion challenger data
Deleting challenger models
Promoting challenger models
Updating challenger response percentages
Adding new models
Cloning an ADM active model
Adding/removing predictors
- Parameters:
prediction_id (str)
active_model (pdstools.infinity.resources.prediction_studio.v24_2.model.Model)
cc_id (Optional[str])
context (Optional[str])
category (Optional[str])
challenger_model (Optional[pdstools.infinity.resources.prediction_studio.v24_2.model.Model])
champion_percentage (Optional[float])
model_objective (Optional[str])
- client¶
The client used to interact with the API.
- Type:
Client
- champion_percentage¶
The percentage of responses attributed to the champion model.
- Type:
Union[float, None]
- prediction_id¶
- cc_id = None¶
- context = None¶
- category = None¶
- active_model¶
- challenger_model = None¶
- champion_percentage = None¶
- model_objective = None¶
- _removed = False¶
- _refresh_champion_challenger()¶
Updates the champion and challenger models for a specific prediction.
This function fetches the latest prediction details and refreshes the champion and challenger models accordingly. If there’s no challenger model linked, it sets the challenger attribute to None.
- delete_challenger_model()¶
Removes the challenger model linked to the current prediction.
This function checks for a challenger model’s existence, constructs a request to delete it using the prediction and model IDs, and updates the prediction’s data accordingly.
- Raises:
PegaMLopsError – If there’s no challenger model linked to the prediction.
- promote_challenger_model()¶
Switches the challenger model to be the new champion for a prediction.
Checks for an existing challenger model and sends a request to make it the new champion model. Updates the prediction’s model data afterwards.
- Raises:
PegaMLopsError – If there’s no challenger model linked to the prediction.
Adjusts traffic distribution between champion and challenger models.
Modifies how incoming traffic is split between the current champion and the challenger model by updating the challenger’s response percentage. Validates the new percentage and the existence of both models before applying changes.
- Parameters:
new_challenger_response_share (float) – The desired challenger_response_percentage directed to the challenger model.
- Raises:
ValueError – If the percentage is outside the 0-1 range, or if either the champion or challenger model is missing.
PegaMLopsError – If there’s an error when updating the challenger response percentage
- _status()¶
Checks the update status of the champion challenger configuration.
Determines if an update to the champion challenger setup is currently in progress by examining the cc_id. If no update is underway, it indicates the current setup is active.
- Returns:
The current status of the update process, or “Active” if no updates are pending.
- Return type:
- list_available_models_to_add(return_df: bool = False) pdstools.infinity.internal._pagination.PaginatedList[pdstools.infinity.resources.prediction_studio.v24_2.model.Model] | polars.DataFrame ¶
Fetches a list of models eligible to be challengers.
Queries for models that can be added as challengers to the current prediction for the current active model. Offers the option to return the results in a DataFrame format for easier data handling.
- Parameters:
return_df (bool, optional) – Determines the format of the returned data: a DataFrame if True, otherwise a list of model instances. Defaults to False.
- Returns:
A list of model instances or a DataFrame of models, based on the return_df parameter choice.
- Return type:
PaginatedList[Model] or pl.DataFrame
- add_model(new_model: pdstools.infinity.resources.prediction_studio.v24_2.model.Model | pdstools.infinity.resources.prediction_studio.v24_2.model_upload.UploadedModel, challenger_response_share: float, predictor_mapping: List[Dict[str, str | int]] | None = None, model_label: str | None = None, learn_independently: bool | None = True)¶
Add a new model as a challenger in the prediction setup.
Enables the addition of a new model as a challenger, accepting various model types. It configures the challenger’s traffic share, allows for custom predictor to property mappings, and supports labeling the model. If the active model is a scorecard, the function will replace the active model with the new challenger.
- Parameters:
new_model (Model, UploadedModel) – The model to be added as a challenger. Can be a pre-existing model, an uploaded file, or a model identifier.
challenger_response_share (int) – Defines what percentage of traffic should be directed to the challenger model.
predictor_mapping (list of dict, optional) – Custom mappings for predictors to properties, with each mapping as a dictionary.
model_label (str, optional) – A label for the new challenger model.
learn_independently (bool, optional) – If True, the challenger model will learn independently. Defaults to True.
- Raises:
NotImplementedError – If attempting to add a model instance directly, which is not supported.
ValueError – If the response_percentage for the challenger is outside the 0-1 range.
PegaMLopsError – If there’s an error when adding the challenger model.
- clone_model(challenger_response_share: float, adm_model_type: pdstools.infinity.resources.prediction_studio.types.AdmModelType | str, model_label: str | None = None, predictor_mapping: List[Dict] | None = None, learn_independently: bool | None = True)¶
Clones the current active model to create a challenger with specific settings.
This function duplicates the active model, setting it as a challenger in the prediction setup. It allows choosing the model type, adjusting traffic share, and customizing labels and predictor mappings.
- Parameters:
challenger_response_share (float) – Defines the traffic percentage for the challenger model.
adm_model_type ({'Gradient boosting', 'Naive bayes'}) – Specifies the type of the cloned model.
model_label (str, optional) – A custom label for the cloned model. Defaults to a generated unique label if not provided.
predictor_mapping (list of dict, optional) – Custom mappings of predictors to properties for the cloned model.
learn_independently (bool, optional) – If True, the challenger model will learn independently. Defaults to True.
- Raises:
PegaMLopsError – If the challenger_response_percentage is not within the 0-1 range or adm_model_type is invalid. Or if there’s an error when adding the challenger model.
- add_predictor(name: str, predictor_type: str, value: str, data_type: str, is_active_model: bool, parameterized: bool = True)¶
Adds a new predictor to a specific model in a prediction setup.
This function introduces a new predictor to a model tied to a prediction. It differentiates between parameterized and static predictors based on a flag.
- Parameters:
name (str) – Name of the predictor.
predictor_type (str) – Predictor’s type.
value (str) – Predictor’s value, for static predictors.
data_type (str) – Data type of the predictor’s value.
is_active_model (bool) – Indicates if the predictor should be added to the active model or the challenger model.
parameterized (bool, optional) – Indicates if the predictor is parameterized, default is True.
- Returns:
Outcome of the addition operation as received from the API.
- Return type:
Response
- Raises:
PegaMLopsError – If the challenger model is not set or if an error occurs when adding the predictor.
- remove_predictor(name: str, parameterized: bool | None = False, is_active_model: bool = True)¶
Removes a predictor from a model in a prediction setup.
This function deletes a predictor, identified by its name, from a model linked to a prediction.
- Parameters:
- Returns:
The result of the deletion request.
- Return type:
Response
- Raises:
PegaMLopsError – If the challenger model is not set or if an error occurs when removing the predictor.