trendminer.sdk.models.models module

This module provides user-facing API’s for interacting with Machine Learning models.

class trendminer.sdk.models.models.MlModelsAPI

Bases: ABC

Provides model instances for different model types, such as PMML.

Represents an abstract interface for retrieving model objects based on their types.

property pmml: PmmlModelsAPI

Returns an API instance for managing PMML models.

Use this property to access functionalities for listing, deploying, searching and deleting PMML models.

Returns:

The API instance for PMML models

Return type:

PmmlModelsAPI

Example

models = client.ml.pmml.list()
class trendminer.sdk.models.models.PmmlModelsAPI

Bases: ABC

Abstract base class for PMML model API’s.

Provides an interface for concrete implementations to offer user-friendly methods for interacting with PMML models.

abstract delete_model(model_id: str) None

Deletes a specific PMML model.

Parameters:

model_id (str) – The identifier of the PMML model to delete

Example

client.ml.pmml.delete_model("RandomForestRegressor")
abstract deploy_model(model: str) str

Deploys a PMML model by providing its content as a string.

Parameters:

model (str) – The PMML model content in string format

Returns:

A response string indicating the success or failure of the deployment, often containing model deployment details or error messages

Return type:

str

Example

response = client.ml.pmml.deploy_model('''<?xml version="1.0" encoding="UTF-8"?>
    <!--(Comment generated by ADAPA) PMML processed by ADAPA (Version : 4.4)-->
    <PMML xsi:schemaLocation="http://www.dmg.org/PMML-4_4 http://www.dmg.org/v4-4/pmml-4-4.xsd" version="4.4"
        xmlns="http://www.dmg.org/PMML-4_4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Header copyright=""/>
        <DataDictionary numberOfFields="3">
            <DataField dataType="double" name="X1" optype="continuous"/>
            <DataField dataType="double" name="X2" optype="continuous"/>
            <DataField dataType="double" name="Y" optype="continuous"/>
        </DataDictionary>
        <RegressionModel functionName="regression" modelName="Decisionclassifier">
            <MiningSchema>
                <MiningField name="X1"/>
                <MiningField name="X2"/>
                <MiningField name="Y" usageType="target"/>
            </MiningSchema>
            <Output>
                <OutputField dataType="double" feature="predictedValue" name="Predicted_Y" optype="continuous"/>
            </Output>
            <RegressionTable intercept="3">
                <NumericPredictor coefficient="1" exponent="1" name="X1"/>
                <NumericPredictor coefficient="2.5" exponent="1" name="X2"/>
            </RegressionTable>
        </RegressionModel>
    </PMML>''')
abstract deploy_model_file(model_path: str) str

Deploys a PMML model from a model file.

Parameters:

model_path (file) – The path to the PMML model file to deploy

Returns:

A response string indicating the success or failure of the deployment, often containing model deployment details or error messages

Return type:

str

Note

The model file must be present in the directory

Example

# Upload model by providing file path
response = client.ml.pmml.deploy_model_file("regressor.pmml")
abstract get_by_identifier(model_id: str) dict

Retrieves information about a specific PMML model using its identifier.

Parameters:

model_id (str) – The identifier of the PMML model to retrieve

Returns:

A dictionary containing information about the model

Return type:

dict

Example

model_info = client.ml.pmml.get_by_identifier("BA_SOM")
abstract list() list[dict]

Lists information about all available PMML models.

Returns:

A list of dictionaries containing metadata for each model

Return type:

list

Example

models = client.ml.pmml.list()
abstract search(*args, **kwargs) list[dict]

Searches for PMML models based on various criteria.

Note

Atleast one of the below mentioned Keyword Arguments should be provided. Otherwise, an empty list will be returned. If multiple keywords are provided, they will be combined using an AND operation.

Keyword Arguments:

name (str) – The model identifier or name to search for

Note

Wildcards are not supported when searching for machine learning models by name

Returns:

A list of dictionaries containing information about the matching models

Return type:

list

Example

models = client.ml.pmml.search(name="RandomForestRegressor")