Skip to content

Reference

The Comet MPM class is used to upload a model's input and output features to MPM

CometMPM.init

__init__(api_key: Optional[str] = None,
    workspace_name: Optional[str] = None,
    model_name: Optional[str] = None,
    model_version: Optional[str] = None,
    disabled: Optional[bool] = None, asyncio: bool = False,
    max_batch_size: Optional[int] = None,
    max_batch_time: Optional[int] = None)

Creates the Comet MPM Event logger object.

Args:

  • api_key: The Comet API Key
  • workspace_name: The Comet Workspace Name of the model
  • model_name: The Comet Model Name of the model
  • model_version: The Comet Model Version of the model
  • disabled: If set to True, CometMPM will not send anything to the backend.
  • asyncio: Set to True if you are using an Asyncio-based framework like FastAPI.
  • max_batch_size: Maximum number of MPM events sent in a batch, can also be configured using the environment variable MPM_MAX_BATCH_SIZE.
  • max_batch_time: Maximum time before a batch of events is submitted to MPM, can also be configured using the environment variable MPM_MAX_BATCH_SIZE.

CometMPM.connect

connect() -> None

When using CometMPM in asyncio mode, this coroutine needs to be awaited at the server start.

CometMPM.join

join(timeout: Optional[int] = None) -> Optional[Awaitable[None]]

When using CometMPM in asyncio mode, this coroutine needs to be awaited at the server stop.

CometMPM.log_dataframe

log_dataframe(dataframe, prediction_id_column: str,
    feature_columns: Optional[List[str]] = None,
    output_value_column: Optional[str] = None, output_probability_column: Optional[str] = None) -> LogEventsResult

Log a pandas DataFrame to MPM. Every row in the dataframe will be interpreted as an event to be logged.

Events are structured as described in .log_event() method, please refer to it to have the full context.

Args:

  • dataframe: the pandas DataFrame to be logged.
  • prediction_id_column: this column should have the prediction_id values for the events.
  • feature_columns: if provided, this column will be used as the input_features parameter for the events.
  • output_value_column: if provided, this column will be used as the output_value for the events.
  • output_probability_column: if provided, this column will be used as the output_probability for the events.

CometMPM.log_event

log_event(prediction_id: str, input_features: Optional[Dict[str,
    Any]] = None, output_value: Optional[Any] = None, output_probability: Optional[Any] = None) -> Optional[Awaitable[None]]

Log a single event asynchronously to MPM. Events are identified by the mandatory prediction_id parameter. You can send multiple events with the same prediction_id, events will be merged on the backend side automatically.

Args:

  • prediction_id: The unique prediction ID, could be provided by the framework, you or a random unique value could be provided like str(uuid4())
  • input_features: If provided must be a flat Dictionary where the keys are the feature name and the value are native Python scalars, int, floats, booleans or strings. For example: {“age”: 42, “income”: 42894.89}
  • output_value: The prediction as a native Python scalar, int, float, boolean or string.
  • output_probability: If provided, must be a float between 0 and 1 indicating the confidence of the model in the prediction
Mar. 21, 2023