pdstools.infinity.resources.prediction_studio.v24_2.champion_challenger ======================================================================= .. py:module:: pdstools.infinity.resources.prediction_studio.v24_2.champion_challenger Attributes ---------- .. autoapisummary:: pdstools.infinity.resources.prediction_studio.v24_2.champion_challenger.logger Classes ------- .. autoapisummary:: pdstools.infinity.resources.prediction_studio.v24_2.champion_challenger.ChampionChallenger Module Contents --------------- .. py:data:: logger .. py:class:: ChampionChallenger(client, prediction_id: str, active_model: pdstools.infinity.resources.prediction_studio.v24_2.model.Model, cc_id: Optional[str] = None, context: Optional[str] = None, category: Optional[str] = None, challenger_model: Optional[pdstools.infinity.resources.prediction_studio.v24_2.model.Model] = None, champion_percentage: Optional[float] = None, model_objective: Optional[str] = None) Bases: :py:obj:`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 .. attribute:: client The client used to interact with the API. :type: Client .. attribute:: prediction_id The ID of the prediction. :type: str .. attribute:: active_model The active model in the prediction. :type: Model .. attribute:: cc_id The ID of the champion challenger. :type: Union[str, None] .. attribute:: context The context of the prediction. :type: Union[str, None] .. attribute:: category The category of the prediction. :type: Union[str, None] .. attribute:: challenger_model The challenger model. :type: Union[Model, None] .. attribute:: champion_percentage The percentage of responses attributed to the champion model. :type: Union[float, None] .. attribute:: model_objective The objective of the model. :type: Union[str, None] .. py:attribute:: prediction_id .. py:attribute:: cc_id :value: None .. py:attribute:: context :value: None .. py:attribute:: category :value: None .. py:attribute:: active_model .. py:attribute:: challenger_model :value: None .. py:attribute:: champion_percentage :value: None .. py:attribute:: model_objective :value: None .. py:attribute:: _removed :value: False .. py:method:: describe() -> dict Describe the champion challenger object. .. py:method:: _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. .. py:method:: 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. .. py:method:: 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. .. py:method:: update_challenger_response_share(new_challenger_response_share: float) 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. :param new_challenger_response_share: The desired challenger_response_percentage directed to the challenger model. :type new_challenger_response_share: float :raises ValueError: If the percentage is outside the 0-1 range, or if either the champion or challenger model is missing. :raises PegaMLopsError: If there's an error when updating the challenger response percentage .. py:method:: _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. :rtype: str .. py:method:: _introduce_model(champion_response_share: float, learn_independently: bool = True) .. py:method:: _check_then_update(champion_response_share: float, learn_independently: bool = True) .. py:method:: list_available_models_to_add(return_df: bool = False) -> Union[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. :param return_df: Determines the format of the returned data: a DataFrame if True, otherwise a list of model instances. Defaults to False. :type return_df: bool, optional :returns: A list of model instances or a DataFrame of models, based on the `return_df` parameter choice. :rtype: PaginatedList[Model] or pl.DataFrame .. py:method:: add_model(new_model: Union[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: Optional[List[Dict[str, Union[str, int]]]] = None, model_label: Optional[str] = None, learn_independently: Optional[bool] = 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. :param new_model: The model to be added as a challenger. Can be a pre-existing model, an uploaded file, or a model identifier. :type new_model: Model, UploadedModel :param challenger_response_share: Defines what percentage of traffic should be directed to the challenger model. :type challenger_response_share: int :param predictor_mapping: Custom mappings for predictors to properties, with each mapping as a dictionary. :type predictor_mapping: list of dict, optional :param model_label: A label for the new challenger model. :type model_label: str, optional :param learn_independently: If True, the challenger model will learn independently. Defaults to True. :type learn_independently: bool, optional :raises NotImplementedError: If attempting to add a model instance directly, which is not supported. :raises ValueError: If the response_percentage for the challenger is outside the 0-1 range. :raises PegaMLopsError: If there's an error when adding the challenger model. .. py:method:: clone_model(challenger_response_share: float, adm_model_type: Union[pdstools.infinity.resources.prediction_studio.types.AdmModelType, str], model_label: Optional[str] = None, predictor_mapping: Union[List[Dict], None] = None, learn_independently: Union[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. :param challenger_response_share: Defines the traffic percentage for the challenger model. :type challenger_response_share: float :param adm_model_type: Specifies the type of the cloned model. :type adm_model_type: {'Gradient boosting', 'Naive bayes'} :param model_label: A custom label for the cloned model. Defaults to a generated unique label if not provided. :type model_label: str, optional :param predictor_mapping: Custom mappings of predictors to properties for the cloned model. :type predictor_mapping: list of dict, optional :param learn_independently: If True, the challenger model will learn independently. Defaults to True. :type learn_independently: bool, optional :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. .. py:method:: 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. :param name: Name of the predictor. :type name: str :param predictor_type: Predictor's type. :type predictor_type: str :param value: Predictor's value, for static predictors. :type value: str :param data_type: Data type of the predictor's value. :type data_type: str :param is_active_model: Indicates if the predictor should be added to the active model or the challenger model. :type is_active_model: bool :param parameterized: Indicates if the predictor is parameterized, default is True. :type parameterized: bool, optional :returns: Outcome of the addition operation as received from the API. :rtype: Response :raises PegaMLopsError: If the challenger model is not set or if an error occurs when adding the predictor. .. py:method:: remove_predictor(name: str, parameterized: Optional[bool] = 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. :param name: The name of the predictor to remove. :type name: str :param parameterized: True if the predictor is parameterized, False if it's static. Defaults to False. :type parameterized: bool, optional :returns: The result of the deletion request. :rtype: Response :raises PegaMLopsError: If the challenger model is not set or if an error occurs when removing the predictor.