:py:mod:`abacusai.model`
========================

.. py:module:: abacusai.model


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   abacusai.model.Model




.. py:class:: Model(client, name=None, modelId=None, modelPredictionConfig=None, createdAt=None, projectId=None, shared=None, sharedAt=None, trainFunctionName=None, predictFunctionName=None, predictManyFunctionName=None, initializeFunctionName=None, trainingInputTables=None, sourceCode=None, cpuSize=None, memory=None, trainingFeatureGroupIds=None, algorithmModelConfigs=None, trainingVectorStoreVersions=None, documentRetrievers=None, isPythonModel=None, defaultAlgorithm=None, customAlgorithmConfigs=None, restrictedAlgorithms=None, useGpu=None, notebookId=None, location={}, refreshSchedules={}, codeSource={}, latestModelVersion={}, modelConfig={})


   Bases: :py:obj:`abacusai.return_class.AbstractApiClass`

   A model

   :param client: An authenticated API Client instance
   :type client: ApiClient
   :param name: The user-friendly name for the model.
   :type name: str
   :param modelId: The unique identifier of the model.
   :type modelId: str
   :param modelPredictionConfig: The prediction config options for the model.
   :type modelPredictionConfig: dict
   :param createdAt: Date and time at which the model was created.
   :type createdAt: str
   :param projectId: The project this model belongs to.
   :type projectId: str
   :param shared: If model is shared to the Abacus.AI model showcase.
   :type shared: bool
   :param sharedAt: The date and time at which the model was shared to the model showcase
   :type sharedAt: str
   :param trainFunctionName: Name of the function found in the source code that will be executed to train the model. It is not executed when this function is run.
   :type trainFunctionName: str
   :param predictFunctionName: Name of the function found in the source code that will be executed run predictions through model. It is not executed when this function is run.
   :type predictFunctionName: str
   :param predictManyFunctionName: Name of the function found in the source code that will be executed to run batch predictions trhough the model.
   :type predictManyFunctionName: str
   :param initializeFunctionName: Name of the function found in the source code to initialize the trained model before using it to make predictions using the model
   :type initializeFunctionName: str
   :param trainingInputTables: List of feature groups that are supplied to the train function as parameters. Each of the parameters are materialized Dataframes (same type as the functions return value).
   :type trainingInputTables: list
   :param sourceCode: Python code used to make the model.
   :type sourceCode: str
   :param cpuSize: Cpu size specified for the python model training.
   :type cpuSize: str
   :param memory: Memory in GB specified for the python model training.
   :type memory: int
   :param trainingFeatureGroupIds: The unique identifiers of the feature groups used as the inputs to train this model on.
   :type trainingFeatureGroupIds: list of unique string identifiers
   :param algorithmModelConfigs: List of algorithm specific training configs.
   :type algorithmModelConfigs: list[dict]
   :param trainingVectorStoreVersions: The vector store version IDs used as inputs during training to create this ModelVersion.
   :type trainingVectorStoreVersions: list
   :param documentRetrievers: List of document retrievers use to create this model.
   :type documentRetrievers: list
   :param isPythonModel: If this model is handled as python model
   :type isPythonModel: bool
   :param defaultAlgorithm: If set, this algorithm will always be used when deploying the model regardless of the model metrics
   :type defaultAlgorithm: str
   :param customAlgorithmConfigs: User-defined configs for each of the user-defined custom algorithm
   :type customAlgorithmConfigs: dict
   :param restrictedAlgorithms: User-selected algorithms to train.
   :type restrictedAlgorithms: dict
   :param useGpu: If this model uses gpu.
   :type useGpu: bool
   :param notebookId: The notebook associated with this model.
   :type notebookId: str
   :param latestModelVersion: The latest model version.
   :type latestModelVersion: ModelVersion
   :param location: Location information for models that are imported.
   :type location: ModelLocation
   :param refreshSchedules: List of refresh schedules that indicate when the next model version will be trained
   :type refreshSchedules: RefreshSchedule
   :param codeSource: If a python model, information on the source code
   :type codeSource: CodeSource

   .. py:method:: __repr__()

      Return repr(self).


   .. py:method:: to_dict()

      Get a dict representation of the parameters in this class

      :returns: The dict value representation of the class parameters
      :rtype: dict


   .. py:method:: describe_train_test_data_split_feature_group()

      Get the train and test data split for a trained model by its unique identifier. This is only supported for models with custom algorithms.

      :param model_id: The unique ID of the model. By default, the latest model version will be returned if no version is specified.
      :type model_id: str

      :returns: The feature group containing the training data and fold information.
      :rtype: FeatureGroup


   .. py:method:: refresh()

      Calls describe and refreshes the current object's fields

      :returns: The current object
      :rtype: Model


   .. py:method:: describe()

      Retrieves a full description of the specified model.

      :param model_id: Unique string identifier associated with the model.
      :type model_id: str

      :returns: Description of the model.
      :rtype: Model


   .. py:method:: rename(name)

      Renames a model

      :param name: The new name to assign to the model.
      :type name: str


   .. py:method:: update_python(function_source_code = None, train_function_name = None, predict_function_name = None, predict_many_function_name = None, initialize_function_name = None, training_input_tables = None, cpu_size = None, memory = None, package_requirements = None, use_gpu = None)

      Updates an existing Python Model using user-provided Python code. If a list of input feature groups is supplied, they will be provided as arguments to the `train` and `predict` functions with the materialized feature groups for those input feature groups.

      This method expects `functionSourceCode` to be a valid language source file which contains the functions named `trainFunctionName` and `predictFunctionName`. `trainFunctionName` returns the ModelVersion that is the result of training the model using `trainFunctionName`. `predictFunctionName` has no well-defined return type, as it returns the prediction made by the `predictFunctionName`, which can be anything.


      :param function_source_code: Contents of a valid Python source code file. The source code should contain the functions named `trainFunctionName` and `predictFunctionName`. A list of allowed import and system libraries for each language is specified in the user functions documentation section.
      :type function_source_code: str
      :param train_function_name: Name of the function found in the source code that will be executed to train the model. It is not executed when this function is run.
      :type train_function_name: str
      :param predict_function_name: Name of the function found in the source code that will be executed to run predictions through the model. It is not executed when this function is run.
      :type predict_function_name: str
      :param predict_many_function_name: Name of the function found in the source code that will be executed to run batch predictions through the model. It is not executed when this function is run.
      :type predict_many_function_name: str
      :param initialize_function_name: Name of the function found in the source code to initialize the trained model before using it to make predictions using the model.
      :type initialize_function_name: str
      :param training_input_tables: List of feature groups that are supplied to the `train` function as parameters. Each of the parameters are materialized DataFrames (same type as the functions return value).
      :type training_input_tables: list
      :param cpu_size: Size of the CPU for the model training function.
      :type cpu_size: str
      :param memory: Memory (in GB) for the model training function.
      :type memory: int
      :param package_requirements: List of package requirement strings. For example: `['numpy==1.2.3', 'pandas>=1.4.0']`.
      :type package_requirements: list
      :param use_gpu: Whether this model needs gpu
      :type use_gpu: bool

      :returns: The updated model.
      :rtype: Model


   .. py:method:: update_python_zip(train_function_name = None, predict_function_name = None, predict_many_function_name = None, train_module_name = None, predict_module_name = None, training_input_tables = None, cpu_size = None, memory = None, package_requirements = None, use_gpu = None)

      Updates an existing Python Model using a provided zip file. If a list of input feature groups are supplied, they will be provided as arguments to the train and predict functions with the materialized feature groups for those input feature groups.

      This method expects `trainModuleName` and `predictModuleName` to be valid language source files which contain the functions named `trainFunctionName` and `predictFunctionName`, respectively. `trainFunctionName` returns the ModelVersion that is the result of training the model using `trainFunctionName`, and `predictFunctionName` has no well-defined return type, as it returns the prediction made by the `predictFunctionName`, which can be anything.


      :param train_function_name: Name of the function found in the train module that will be executed to train the model. It is not executed when this function is run.
      :type train_function_name: str
      :param predict_function_name: Name of the function found in the predict module that will be executed to run predictions through the model. It is not executed when this function is run.
      :type predict_function_name: str
      :param predict_many_function_name: Name of the function found in the predict module that will be executed to run batch predictions through the model. It is not executed when this function is run.
      :type predict_many_function_name: str
      :param train_module_name: Full path of the module that contains the train function from the root of the zip.
      :type train_module_name: str
      :param predict_module_name: Full path of the module that contains the predict function from the root of the zip.
      :type predict_module_name: str
      :param training_input_tables: List of feature groups that are supplied to the train function as parameters. Each of the parameters are materialized Dataframes (same type as the function's return value).
      :type training_input_tables: list
      :param cpu_size: Size of the CPU for the model training function.
      :type cpu_size: str
      :param memory: Memory (in GB) for the model training function.
      :type memory: int
      :param package_requirements: List of package requirement strings. For example: ['numpy==1.2.3', 'pandas>=1.4.0'].
      :type package_requirements: list
      :param use_gpu: Whether this model needs gpu
      :type use_gpu: bool

      :returns: The updated model.
      :rtype: Upload


   .. py:method:: update_python_git(application_connector_id = None, branch_name = None, python_root = None, train_function_name = None, predict_function_name = None, predict_many_function_name = None, train_module_name = None, predict_module_name = None, training_input_tables = None, cpu_size = None, memory = None, use_gpu = None)

      Updates an existing Python model using an existing Git application connector. If a list of input feature groups are supplied, these will be provided as arguments to the train and predict functions with the materialized feature groups for those input feature groups.

      This method expects `trainModuleName` and `predictModuleName` to be valid language source files which contain the functions named `trainFunctionName` and `predictFunctionName`, respectively. `trainFunctionName` returns the `ModelVersion` that is the result of training the model using `trainFunctionName`, and `predictFunctionName` has no well-defined return type, as it returns the prediction made by the `predictFunctionName`, which can be anything.


      :param application_connector_id: The unique ID associated with the Git application connector.
      :type application_connector_id: str
      :param branch_name: Name of the branch in the Git repository to be used for training.
      :type branch_name: str
      :param python_root: Path from the top level of the Git repository to the directory containing the Python source code. If not provided, the default is the root of the Git repository.
      :type python_root: str
      :param train_function_name: Name of the function found in train module that will be executed to train the model. It is not executed when this function is run.
      :type train_function_name: str
      :param predict_function_name: Name of the function found in the predict module that will be executed to run predictions through model. It is not executed when this function is run.
      :type predict_function_name: str
      :param predict_many_function_name: Name of the function found in the predict module that will be executed to run batch predictions through model. It is not executed when this function is run.
      :type predict_many_function_name: str
      :param train_module_name: Full path of the module that contains the train function from the root of the zip.
      :type train_module_name: str
      :param predict_module_name: Full path of the module that contains the predict function from the root of the zip.
      :type predict_module_name: str
      :param training_input_tables: List of feature groups that are supplied to the train function as parameters. Each of the parameters are materialized Dataframes (same type as the functions return value).
      :type training_input_tables: list
      :param cpu_size: Size of the CPU for the model training function.
      :type cpu_size: str
      :param memory: Memory (in GB) for the model training function.
      :type memory: int
      :param use_gpu: Whether this model needs gpu
      :type use_gpu: bool

      :returns: The updated model.
      :rtype: Model


   .. py:method:: set_training_config(training_config, feature_group_ids = None)

      Edits the default model training config

      :param training_config: The training config used to train this model.
      :type training_config: TrainingConfig
      :param feature_group_ids: The list of feature groups used as input to the model.
      :type feature_group_ids: list

      :returns: The model object corresponding to the updated training config.
      :rtype: Model


   .. py:method:: set_prediction_params(prediction_config)

      Sets the model prediction config for the model

      :param prediction_config: Prediction configuration for the model.
      :type prediction_config: dict

      :returns: Model object after the prediction configuration is applied.
      :rtype: Model


   .. py:method:: get_metrics(model_version = None, return_graphs = False, validation = False)

      Retrieves metrics for all the algorithms trained in this model version.

      If only the model's unique identifier (model_id) is specified, the latest trained version of the model (model_version) is used.


      :param model_version: Version of the model.
      :type model_version: str
      :param return_graphs: If true, will return the information used for the graphs on the model metrics page such as PR Curve per label.
      :type return_graphs: bool
      :param validation: If true, will return the validation metrics instead of the test metrics.
      :type validation: bool

      :returns: An object containing the model metrics and explanations for what each metric means.
      :rtype: ModelMetrics


   .. py:method:: list_versions(limit = 100, start_after_version = None)

      Retrieves a list of versions for a given model.

      :param limit: Maximum length of the list of all dataset versions.
      :type limit: int
      :param start_after_version: Unique string identifier of the version after which the list starts.
      :type start_after_version: str

      :returns: An array of model versions.
      :rtype: list[ModelVersion]


   .. py:method:: retrain(deployment_ids = None, feature_group_ids = None, custom_algorithms = None, builtin_algorithms = None, custom_algorithm_configs = None, cpu_size = None, memory = None, training_config = None, algorithm_training_configs = None)

      Retrains the specified model, with an option to choose the deployments to which the retraining will be deployed.

      :param deployment_ids: List of unique string identifiers of deployments to automatically deploy to.
      :type deployment_ids: list
      :param feature_group_ids: List of feature group IDs provided by the user to train the model on.
      :type feature_group_ids: list
      :param custom_algorithms: List of user-defined algorithms to train. If not set, will honor the runs from the last time and applicable new custom algorithms.
      :type custom_algorithms: list
      :param builtin_algorithms: List of the built-in algorithms provided by Abacus.AI to train. If not set, will honor the runs from the last time and applicable new built-in algorithms.
      :type builtin_algorithms: list
      :param custom_algorithm_configs: User-defined training configs for each custom algorithm.
      :type custom_algorithm_configs: dict
      :param cpu_size: Size of the CPU for the user-defined algorithms during training.
      :type cpu_size: str
      :param memory: Memory (in GB) for the user-defined algorithms during training.
      :type memory: int
      :param training_config: The training config used to train this model.
      :type training_config: TrainingConfig
      :param algorithm_training_configs: List of algorithm specifc training configs that will be part of the model training AutoML run.
      :type algorithm_training_configs: list

      :returns: The model that is being retrained.
      :rtype: Model


   .. py:method:: delete()

      Deletes the specified model and all its versions. Models which are currently used in deployments cannot be deleted.

      :param model_id: Unique string identifier of the model to delete.
      :type model_id: str


   .. py:method:: set_default_algorithm(algorithm = None, data_cluster_type = None)

      Sets the model's algorithm to default for all new deployments

      :param algorithm: Algorithm to pin in the model.
      :type algorithm: str
      :param data_cluster_type: Data cluster type to set the lead model for.
      :type data_cluster_type: str


   .. py:method:: list_artifacts_exports(limit = 25)

      List all the model artifacts exports.

      :param limit: Maximum length of the list of all exports.
      :type limit: int

      :returns: List of model artifacts exports.
      :rtype: list[ModelArtifactsExport]


   .. py:method:: get_training_types_for_deployment(model_version = None, algorithm = None)

      Returns types of models that can be deployed for a given model instance ID.

      :param model_version: The unique ID associated with the model version to deploy.
      :type model_version: str
      :param algorithm: The unique ID associated with the algorithm to deploy.
      :type algorithm: str

      :returns: Model training types for deployment.
      :rtype: ModelTrainingTypeForDeployment


   .. py:method:: update_agent(function_source_code = None, agent_function_name = None, memory = None, package_requirements = None, description = None, enable_binary_input = False)

      Updates an existing AI Agent using user-provided Python code. A new version of the agent will be created and published.

      :param function_source_code: Contents of a valid Python source code file. The source code should contain the functions named `agentFunctionName`. A list of allowed import and system libraries for each language is specified in the user functions documentation section.
      :type function_source_code: str
      :param agent_function_name: Name of the function found in the source code that will be executed to the agent when it is deployed.
      :type agent_function_name: str
      :param memory: Memory (in GB) for the agent.
      :type memory: int
      :param package_requirements: List of package requirement strings. For example: ['numpy==1.2.3', 'pandas>=1.4.0']
      :type package_requirements: list
      :param description: A description of the agent, including its purpose and instructions.
      :type description: str
      :param enable_binary_input: If True, the agent will be able to accept binary data as inputs.
      :type enable_binary_input: bool

      :returns: The updated agent
      :rtype: Agent


   .. py:method:: wait_for_training(timeout=None)

      A waiting call until model is trained.

      :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out.
      :type timeout: int, optional


   .. py:method:: wait_for_evaluation(timeout=None)

      A waiting call until model is evaluated completely.

      :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out.
      :type timeout: int, optional


   .. py:method:: wait_for_publish(timeout=None)

      A waiting call until agent is published.

      :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out.
      :type timeout: int, optional


   .. py:method:: wait_for_full_automl(timeout=None)

      A waiting call until full AutoML cycle is completed.

      :param timeout: The waiting time given to the call to finish, if it doesn't finish by the allocated time, the call is said to be timed out.
      :type timeout: int, optional


   .. py:method:: get_status(get_automl_status = False)

      Gets the status of the model training.

      :returns: A string describing the status of a model training (pending, complete, etc.).
      :rtype: str


   .. py:method:: create_refresh_policy(cron)

      To create a refresh policy for a model.

      :param cron: A cron style string to set the refresh time.
      :type cron: str

      :returns: The refresh policy object.
      :rtype: RefreshPolicy


   .. py:method:: list_refresh_policies()

      Gets the refresh policies in a list.

      :returns: A list of refresh policy objects.
      :rtype: List[RefreshPolicy]


   .. py:method:: get_train_test_feature_group_as_pandas()

      Get the model train test data split feature group as pandas.

      :returns: A pandas dataframe for the training data with fold column.
      :rtype: pandas.Dataframe



