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

.. py:module:: abacusai.model


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

Classes
~~~~~~~

.. autoapisummary::

   abacusai.model.Model




.. py:class:: Model(client, name=None, modelId=None, modelConfig=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, isPythonModel=None, defaultAlgorithm=None, customAlgorithmConfigs=None, restrictedAlgorithms=None, location={}, refreshSchedules={}, codeSource={}, latestModelVersion={})

   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 modelConfig: The training config options used to train this model.
   :type modelConfig: dict
   :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 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 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 model id. Only supported for models with custom algorithms.

      :param model_id: The unique ID of the model. By default will return for latest model version if version is not specified.
      :type model_id: str

      :returns: The feature group containing the training data and folds 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: The unique ID associated with the model.
      :type model_id: str

      :returns: The description of the model.
      :rtype: Model


   .. py:method:: rename(name)

      Renames a model

      :param name: The name to apply 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)

      Updates an existing python Model using user provided Python code. If a list of input feature groups are supplied,

      we will provide 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` and `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 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 source code 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 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: Json with key value pairs corresponding to package: version for each dependency
      :type package_requirements: dict

      :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)

      Updates an existing python Model using a provided zip file. If a list of input feature groups are supplied,

      we will provide 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 contains 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 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 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 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 package_requirements: Json with key value pairs corresponding to package: version for each dependency
      :type package_requirements: dict

      :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)

      Updates an existing python Model using an existing git application connector. If a list of input feature groups are supplied,

      we will provide 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 contains 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 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 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

      :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 key/value pairs used to train this model.
      :type training_config: dict
      :param feature_group_ids:
      :type feature_group_ids: list

      :returns: The model object correspoding after the training config is applied
      :rtype: Model


   .. py:method:: set_prediction_params(prediction_config)

      Sets the model prediction config for the model

      :param prediction_config: The prediction config for the model
      :type prediction_config: dict

      :returns: The model object correspoding after the prediction config is applied
      :rtype: Model


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

      Retrieves a full list of the metrics for the specified model.

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


      :param model_version: The version of the model.
      :type model_version: str
      :param baseline_metrics: If true, will also return the baseline model metrics for comparison.
      :type baseline_metrics: bool

      :returns: An object to show 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 the version for a given model.

      :param limit: The max length of the list of all dataset versions.
      :type limit: int
      :param start_after_version: The id of the version after which the list starts.
      :type start_after_version: str

      :returns: An array of model versions.
      :rtype: ModelVersion


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

      Retrains the specified model. Gives you an option to choose the deployments you want the retraining to be deployed to.

      :param deployment_ids: List 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 last time and applicable new custom algorithms.
      :type custom_algorithms: list
      :param builtin_algorithms: List of the builtin algorithms provided by Abacus.AI to train. If not set, honor the runs from last time and applicable new builtin algorithms.
      :type builtin_algorithms: list
      :param custom_algorithm_configs: The 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 train.
      :type cpu_size: str
      :param memory: Memory (in GB) for the user-defined algorithms during train.
      :type memory: int
      :param training_config: The training config key/value pairs used to train this model.
      :type training_config: dict

      :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: The ID of the model to delete.
      :type model_id: str


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

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

      :param model_id: The model to set
      :type model_id: Unique String Identifier
      :param algorithm: the algorithm to pin in the model
      :type algorithm: Enum String

      :param algorithm:
      :type algorithm: str


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

      Returns types of models we can deploy for 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:: 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_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



