Skip to content

model

Model

Operations for working with machine learning models.

add_analysis_data classmethod

add_analysis_data(model_id: str, data: pd.DataFrame) -> None

Add analysis data to a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required
data DataFrame

Data to be added.

required
Note

This method does not update existing data. It only adds new data. If you want to update existing data, use upsert_analysis_data instead.

add_analysis_target_data classmethod

add_analysis_target_data(model_id: str, data: pd.DataFrame) -> None

Add (delayed) target data to a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required
data DataFrame

Data to be added.

required
Note

This method can only be used if the model has a target data source. If you want to add analysis data to a model without a target data source, use add_analysis_data instead.

Note

This method does not update existing data. It only adds new data. If you want to update existing data, use upsert_analysis_target_data instead.

create classmethod

create(
    name: str,
    schema: ModelSchema,
    reference_data: pd.DataFrame,
    analysis_data: pd.DataFrame,
    target_data: Optional[pd.DataFrame] = None,
    main_performance_metric: Optional[PerformanceMetric] = None,
    chunk_period: Optional[ChunkPeriod] = None,
    chunk_size: Optional[int] = None,
) -> ModelDetails

Create a new model.

Parameters:

Name Type Description Default
name str

Name for the model.

required
schema ModelSchema

Schema of the model. Typically, created using Schema.from_df.

required
reference_data DataFrame

Reference data to use for the model.

required
analysis_data DataFrame

Analysis data to use for the model. If the data contains targets, targets must always be provided together with analysis data.

required
target_data Optional[DataFrame]

Optional target data to use for the model.

None
main_performance_metric Optional[PerformanceMetric]

Optional main performance metric for the model. If not provided, no performance metric will be tagged as main.

None
chunk_period Optional[ChunkPeriod]

Time period per chunk. Should only be set for time-based chunking.

None
chunk_size Optional[int]

Number of rows per chunk. Should only be set for size-based chunking.

None

Returns:

Type Description
ModelDetails

Detailed about the model once it has been created.

delete classmethod

delete(model_id: str) -> None

Delete a model.

Parameters:

Name Type Description Default
model_id str

ID of the model to delete.

required

delete_analysis_data classmethod

delete_analysis_data(model_id: str, data_ids: pd.DataFrame) -> None

Delete analysis data from a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required
data_ids DataFrame

ID's for the data to be deleted.

required

delete_analysis_target_data classmethod

delete_analysis_target_data(model_id: str, data_ids: pd.DataFrame) -> None

Delete target data from a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required
data_ids DataFrame

ID's for the data to be deleted.

required

get classmethod

get(model_id: str) -> ModelDetails

Get details for a model.

Parameters:

Name Type Description Default
model_id str

ID of the model to get details for.

required

Returns:

Type Description
ModelDetails

Detailed information about the model.

get_analysis_data_history classmethod

get_analysis_data_history(model_id: str) -> List[DataSourceEvent]

Get analysis data history for a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required

Returns:

Type Description
List[DataSourceEvent]

List of events related to analysis data for the model.

get_analysis_target_data_history classmethod

get_analysis_target_data_history(model_id: str) -> List[DataSourceEvent]

Get target data history for a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required

Returns:

Type Description
List[DataSourceEvent]

List of events related to target data for the model.

get_reference_data_history classmethod

get_reference_data_history(model_id: str) -> List[DataSourceEvent]

Get reference data history for a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required

Returns:

Type Description
List[DataSourceEvent]

List of events related to reference data for the model.

list classmethod

list(
    name: Optional[str] = None, problem_type: Optional[ProblemType] = None
) -> List[ModelSummary]

List defined models.

Parameters:

Name Type Description Default
name Optional[str]

Optional name filter.

None
problem_type Optional[ProblemType]

Optional problem type filter.

None

Returns:

Type Description
List[ModelSummary]

List of models that match the provided filter criteria.

upsert_analysis_data classmethod

upsert_analysis_data(model_id: str, data: pd.DataFrame) -> None

Add or update analysis data for a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required
data DataFrame

Data to be added/updated.

required
Note

This method compares existing data with the new data to determine which rows to update and which to add. If you are certain you are only adding new data, it is recommended to use add_analysis_data instead for better performance.

upsert_analysis_target_data classmethod

upsert_analysis_target_data(model_id: str, data: pd.DataFrame) -> None

Add or update (delayed) target data for a model.

Parameters:

Name Type Description Default
model_id str

ID of the model.

required
data DataFrame

Data to be added/updated.

required
Note

This method can only be used if the model has a target data source. If you want to update analysis data in a model without a target data source, use upsert_analysis_data instead.

Note

This method compares existing data with the new data to determine which rows to update and which to add. If you are certain you are only adding new data, it is recommended to use add_analysis_target_data instead for better performance.

ModelDetails

Bases: ModelSummary

Detailed information about a model.

Attributes:

Name Type Description
latestRun Optional[RunSummary]

The currently active run or latest run performed for the model. This is None if no runs have been performed yet.

nextRun Optional[RunSummary]

The next run scheduled for the model. This is None if there is a run currently active.

ModelSummary

Bases: TypedDict

Summary of a model.

Attributes:

Name Type Description
id str

Unique identifier of the model (generated by NannyML Cloud when a model is created).

name str

User-defined name of the model.

problemType ProblemType

Type of problem the model is trying to solve.

createdAt datetime

Timestamp when the model was created.