sasctl.tasks#

Commonly used tasks in the analytics life cycle.

sasctl.tasks.get_project_kpis(project, server='cas-shared-default', caslib='ModelPerformanceData', filterColumn=None, filterValue=None)[source]#

Create a call to CAS to return the MM_STD_KPI table (Model Manager Standard KPI) generated when custom KPIs are uploaded or when a performance definition is executed on SAS Model Manager on SAS Viya 4.

Filtering options are available as additional arguments. The filtering is based on column name and column value. Currently, only exact matches are available when filtering by this method.

Parameters:
  • project (str or dict) – The name or id of the project, or a dictionary representation of the project.

  • server (str, optional) – SAS Viya 4 server where the MM_STD_KPI table exists, by default “cas-shared-default”

  • caslib (str, optional) – SAS Viya 4 caslib where the MM_STD_KPI table exists, by default “ModelPerformanceData”

  • filterColumn (str, optional) – Column name from the MM_STD_KPI table to be filtered, by default None

  • filterValue (str, optional) – Column value to be filtered, by default None

Returns:

kpiTableDf (pandas.DataFrame) – A pandas DataFrame representing the MM_STD_KPI table. Note that SAS missing values are replaced with pandas valid missing values.

sasctl.tasks.publish_model(model, destination, code=None, name=None, max_retries=60, replace=False, **kwargs)[source]#

Publish a model to a configured publishing destination.

Parameters:
  • model (str or dict) – The name or id of the model, or a dictionary representation of the model.

  • destination (str)

  • code (optional)

  • name (str, optional) – Name of custom publish name for publish calls that do not have code. Default is None.

  • max_retries (int, optional)

  • replace (bool, optional) – Whether to overwrite the model if it already exists in the destination

  • **kwargs – additional arguments will be passed to the underlying publish functions.

Returns:

RestObj – The published model

Notes

If no code is specified, the model is assumed to be already registered in the model repository and Model Manager’s publishing functionality will be used.

Otherwise, the model publishing API will be used.

Changed in version 1.1.0: Added replace option.

sasctl.tasks.register_model(model, name, project, repository=None, X=None, version=None, files=None, force=False, record_packages=True, modeler=None, input=None)[source]#

Register a model in the model repository.

Parameters:
  • model (swat.cas.table.CASTable or sklearn.base.BaseEstimator) – The model to register. If an instance of swat.cas.table.CASTable the table is assumed to hold an ASTORE, which will be downloaded and used to construct the model to register. If a scikit-learn estimator, the model will be pickled and uploaded to the registry and score code will be generated for publishing the model to MAS.

  • name (str) – Designated name for the model in the repository.

  • project (str or dict) – The name or id of the project, or a dictionary representation of the project.

  • repository (str or dict, optional) – The name or id of the repository, or a dictionary representation of the repository. If omitted, the default repository will be used.

  • X (pandas.DataFrame, type, list of type, or dict of str: type, optional) – The expected type for each input value of the target function. Can be omitted if target function includes type hints. If a DataFrame is provided, the columns will be inspected to determine type information. If a single type is provided, all columns will be assumed to be that type, otherwise a list of column types or a dictionary of column_name: type may be provided.

  • version (str or int, optional) – If str choose from {'new', 'latest'}. Version number of the project in which the model should be created. Defaults to ‘new’.

  • files (list) – A list of dictionaries of the form {‘name’: filename, ‘file’: filecontent}. An optional ‘role’ key is supported for designating a file as score code, astore, etc.

  • force (bool, optional) – Create dependencies such as projects and repositories if they do not already exist.

  • record_packages (bool, optional) – Capture Python packages registered in the environment. Defaults to True. Ignored if model is not a Python object.

  • modeler (str, optional) – The name of the user who created the model. Will default ot the current user if not specified.

  • input (pandas.DataFrame, type, list of type, or dict of str: type, optional) – Deprecated, use X instead.

Returns:

model (RestObj) – The newly registered model as an instance of core.RestObj

Notes

If the specified model is a CAS table the model data and metadata will be written to a temporary zip file and then imported using model_repository.import_model_from_zip.

If the specified model is from the Scikit-Learn package, the model will be created using model_repository.create_model and any additional files will be uploaded as content.

Changed in version v1.3: Create requirements.txt with installed packages.

Changed in version v1.4.5: Added record_packages parameter.

Changed in version v1.7.4: Update ASTORE handling for ease of use and removal of SAS Viya 4 score code errors

sasctl.tasks.score_model_with_cas(score_def_name: str, model: str | dict, table_name: str, table_file: str | Path | None = None, description: str = '', server_name: str = 'cas-shared-default', library_name: str = 'Public', model_version: str = 'latest', use_cas_gateway: bool = False)[source]#
sasctl.tasks.update_model_performance(data, model, label, refresh=True)[source]#

Upload data for calculating model performance metrics.

Model performance and data distributions can be tracked over time by designating one or more tables that contain input data and target values. Performance metrics can be updated by uploading a data set for a new time period and executing the performance definition.

Parameters:
  • data (pandas.DataFrame)

  • model (str or dict) – The name or id of the model, or a dictionary representation of the model.

  • label (str) – The time period the data is from. Should be unique and will be displayed on performance charts. Examples: ‘Q1’, ‘2019’, ‘APR2019’.

  • refresh (bool, optional) – Whether to execute the performance definition and refresh results with the new data.

Returns:

swat.cas.table.CASTable – The CAS table containing the performance data.

See also

model_management.create_performance_definition

Added in version v1.3.