arthurai.core.models.ArthurModel#

class arthurai.core.models.ArthurModel(partner_model_id, input_type, output_type, client=None, explainability=None, id=None, display_name=None, description=None, is_batch=False, archived=False, created_at=None, updated_at=None, attributes=None, tags=None, classifier_threshold=None, text_delimiter=None, expected_throughput_gb_per_day=None, pixel_height=None, pixel_width=None, image_class_labels=None, reference_dataframe=None, status=None, model_group_id=None, version_sequence_num=None, version_label=None)#

Bases: arthurai.core.base.ArthurBaseJsonDataclass

Arthur Model class represents the metadata which represents a registered model in the application

Parameters
  • clientarthurai.client.Client object which manages data storage

  • partner_model_id – Client provided unique id to associate with the model. This field must be unique across all active models cannot be changed once set.

  • input_typearthurai.common.constants.InputType representing the model’s input data type.

  • output_typearthurai.common.constants.OutputType representing the model’s output data format.

  • explainabilityarthurai.core.models.ExplainabilityParameters object representing parameters that will be used to create inference explanations.

  • id – The auto-generated unique UUID for the model. Will be overwritten if set by the user.

  • display_name – An optional display name for the model.

  • description – Optional description of the model.

  • is_batch – Boolean value to determine whether the model sends inferences in batch or streaming format. Defaults to False.

  • archived – Indicates whether or not a model has been archived, defaults to false.

  • created_at – UTC timestamp in ISO8601 format of when the model was created. Will be overwritten if set by the user.

  • updated_at – UTC timestamp in ISO8601 format of when the model was last updated. Will be overwritten if set by the user.

  • attributes – List of arthurai.core.attributes.ArthurAttribute objects registered to the model

  • tags – List of string keywords to associate with the model.

  • classifier_threshold – Threshold value for classification models, default is 0.5.

  • text_delimiter – Only valid for models with input_type equal to arthurai.common.constants.InputType.NLP. Represents the text delimiter to divide input strings.

  • expected_throughput_gb_per_day – Expected amount of throughput.

  • pixel_height – Only valid for models with input_type equal to arthurai.common.constants.InputType.Image. Expected image height in pixels.

  • pixel_width – Only valid for models with input_type equal to arthurai.common.constants.InputType.Image. Expected image width in pixels.

  • status – Indicates the current status of the model. See the Arthur documentation below for an in-depth explanation of each status.

Methods

add_attribute

Adds a new attribute of stage ModelPipelineInput or NonInputData to the model.

add_binary_classifier_output_attributes

Registers GroundTruth and PredictedValue attributes and their thresholds

add_classifier_output_attributes_gtclass

Registers ground truth and predicted value attributes for classification models

add_image_attribute

Wraps add_attribute for images (see ArthurModel.add_attribute())

add_multiclass_classifier_output_attributes

Registers GroundTruth and PredictedValue attributes

add_object_detection_output_attributes

Registers ground truth and predicted value attributes for an object detection model, as well as setting the image class labels.

add_regression_output_attributes

Registers ground truth attributes and predicted value attributes for regression models.

archive

Archives the model with a DELETE request

await_inferences

Await a minimum number of inferences being available for querying

await_model_ready

wait for model to be Ready

binarize

Creates a binary class probability based on classes defined in a ModelType.Multiclass model

build

Build an Arthur model from a Pandas DataFrame, inferring the attribute metadata and registering the reference data to be stored with Arthur.

build_token_sequence_model

rtype

DataFrame

check_attr_is_bias

Returns True if and only if the model has an attribute with the given name attr_name being monitored for bias by Arthur

check_has_bias_attrs

Returns True if and only if the model has any attributes being monitored for bias by Arthur

clean_nones

Helper function to filter out None objects from a json or dictionary representation of an object

close_batch

Closes the specified batch, optionally can supply the number of inferences that are contained in the batch

create_alert_rule

Creates alert rules for the current model.

create_metric

Creates a metric registered to this model and returns the UUID assigned to the newly created metric.

delete_explainer

Spin down the model explainability server

enable_bias_mitigation

Updates the bias mitigation Enrichment to be enabled

enable_explainability

Enable explainability for this model.

enable_hotspots

Updates the hotspots Enrichment to be enabled

explain_inference

Returns feature importance scores for each attribute of stage ModelPipelineInput

find_hotspots

Retrieve hotspots from the model

from_dataframe

Auto-generate attributes based on input data

from_dict

rtype

TypeVar(A, bound= DataClassJsonMixin)

from_json

rtype

TypeVar(A, bound= DataClassJsonMixin)

get_alert_rules

Returns a paginated list of alert rules registered to this model

get_alerts

Returns a paginated list of alert registered to this model.

get_attribute

Retrieves an attribute by name and stage

get_attribute_names

Returns a list of the names of attributes for the specified stage.

get_attributes

Returns a list of attributes for the specified stage.

get_enrichment

Returns configuration for the specified enrichment.

get_enrichments

Returns configuration for all enrichments.

get_image

Saves the image specified by image_id to a file

get_image_attribute

Returns the attribute with value_type=Image for input_type=Image models

get_metrics

Retrieves metrics associated with the current model.

get_positive_predicted_class

Checks if model is a binary classifier.

infer_schema

Auto-generate attributes based on input data

model_is_saved

Returns True if and only if the model has been saved to the Arthur platform

one_hot_encode

Creates a one hot encoding of a class label based on classes defined in a ModelType.Multiclass model

query

Execute query against the model's inferences.

remove_attribute

Removes an already-made ArthurAttribute from the model.

rename_attribute

Renames an attribute by name and stage

review

Prints a summary of the properties of all attributes in the model.

save

Check and save this model

schema

rtype

SchemaF[TypeVar(A)]

send_batch_ground_truths

Deprecated since version 3.10.0.

send_batch_inferences

Send many inferences at once

send_bulk_ground_truths

Uploads a large batch of ground truth values to Arthur

send_bulk_inferences

Uploads a large batch of inferences to Arthur

send_inference

Deprecated since version 3.20.0.

send_inferences

Send inferences to the Arthur API.

set_attribute_as_sensitive

Sets the passed-in attribute to be sensitive by setting attr.monitor_for_bias = True.

set_attribute_labels

Sets labels for individual categories of a specific attribute

set_predict_function_input_order

Sets the expected order of attributes used by the prediction function.

set_reference_data

Validates and sets the reference data for the given stage to the provided data.

swap_predicted_attribute_positions

Swap the position of the model's two predicted attributes

to_dict

Creates a dictionary representation of this object

to_json

Creates a json representation of this object

update

Update the current model object in the Arthur platform

update_alert

Updates alert to have a particular status.

update_alert_rule

Updates alert rule fields included in the alert_rule object for the specified alert rule id.

update_enrichment

Update the configuration for a single enrichment

update_enrichments

Update the configuration for 1 or more enrichments.

update_inference_ground_truths

Updates inferences with the supplied ground truth values

Attributes

archived

attributes

classifier_threshold

client

created_at

dataclass_json_config

description

display_name

expected_throughput_gb_per_day

explainability

ground_truth_type

Returns GroundTruthClass if Arthur performed one-hot encoding in the creation of this model's current ground truth attribute.

id

image_class_labels

is_batch

model_group_id

pixel_height

pixel_width

reference_dataframe

status

tags

text_delimiter

updated_at

version_label

version_sequence_num

partner_model_id

input_type

output_type

add_attribute(name=None, value_type=None, stage=None, label=None, position=None, categorical=False, min_range=None, max_range=None, monitor_for_bias=False, categories=None, bins=None, is_unique=False, is_positive_predicted_attribute=False, attribute_link=None, arthur_attribute=None, gt_pred_attrs_map=None)#

Adds a new attribute of stage ModelPipelineInput or NonInputData to the model.

For an introduction to attributes and stages, see https://docs.arthur.ai/user-guide/basic_concepts.html#attributes-and-stages

If you have built your model using arthur_model.build(), your model attributes may already be inferred and you do not need to add them with this function.

Formatting requirement: attribute names must contain only letters, numbers, and underscores, and cannot begin with a number.

from arthurai.common.constants import Stage, ValueType

# adds a float input attribute directly to the model
arthur_model.add_attribute(
    name="attribute_name",
    value_type=ValueType.Float,
    stage=Stage.ModelPipelineInput
)

This method can be used to add any attribute to your Arthur model and configure its properties. For some specific model types and data types, it can be more convenient to use a method for adding model attributes from this table:

Adding Model Attributes#

Method

InputType

OutputType

Stage

ArthurModel.add_attribute()

Any

Any

Any

ArthurModel.add_binary_classifier_output_attributes()

Any

Binary

PredictedValue and GroundTruth

ArthurModel.add_classifier_output_attributes_gtclass()

Any

Multiclass

PredictedValue and GroundTruthClass

ArthurModel.add_multiclass_classifier_output_attributes()

Any

Multiclass

PredictedValue and GroundTruth

ArthurModel.add_regression_output_attributes()

Any

Regression

PredictedValue and GroundTruth

ArthurModel.add_image_attribute()

Image

Any

ModelPipelineInput

ArthurModel.add_object_detection_output_attributes()

Image

ObjectDetection

PredictedValue and GroundTruth

Parameters
  • attribute_link (Optional[str]) – Only applicable for GroundTruth or PredictedValue staged attributes. If stage is equal to GroundTruth, this represents the associated PredictedValue attribute and vice versa

  • is_positive_predicted_attribute (bool) – Only applicable for PredictedValue attributes on a Binary Classification model. Should be set to True on the positive predicted value attribute.

  • is_unique (bool) – Boolean value used to signal if the values of this attribute are unique.

  • bins (Optional[List[Union[int, float, AttributeBin]]]) – List of bin cut-offs used to discretize continuous attributes. Use None as an open ended value. [None, 18, 65, None] represents the three following bins: value < 18, 18 < value < 65, value > 65

  • monitor_for_bias (bool) – boolean value set to True if the attribute should be monitored for bias

  • max_range (Union[int, float, None]) – Max value for a continuous attribute

  • min_range (Union[int, float, None]) – Min value for a continuous attribute

  • categorical (bool) – Boolean value set to True if the attribute has categorical values.

  • position (Optional[int]) – The array position of attribute within the stage. Required in the PREDICT_FUNCTION_INPUT stage.

  • label (Optional[str]) – Label for attribute. If attribute has an encoded name, a more readable label can be set.

  • stage (Optional[Stage]) – arthurai.common.constants.Stage of this attribute in the model pipeline

  • value_type (Optional[ValueType]) – arthurai.common.constants.ValueType associated with this attributes values

  • name (Optional[str]) – Name of the attribute. Attribute names can only contain alpha-numeric characters and underscores and cannot start with a number.

  • categories (Optional[List[Union[str, AttributeCategory]]]) – [Only for Categorical Attributes] If the attribute is categorical, this will contain the attribute’s categories. It is required only if the categorical flag is set to true.

  • arthur_attribute (Optional[ArthurAttribute]) – Optional ArthurAttribute to add to the model

  • gt_pred_attrs_map (Optional[Dict]) –

    Deprecated since version version: 2.0.0

    Use ArthurModel.add_[model_type]_output_attributes() instead

Return type

List[ArthurAttribute]

Returns

ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

add_binary_classifier_output_attributes(positive_predicted_attr, pred_to_ground_truth_map, threshold=0.5)#

Registers GroundTruth and PredictedValue attributes and their thresholds

For an introduction to attributes and stages, see https://docs.arthur.ai/user-guide/basic_concepts.html#attributes-and-stages

This function will create a predicted value and ground truth attribute for each mapping specified in pred_to_ground_truth_map.

# map PredictedValue attributes to their corresponding GroundTruth attributes
PRED_TO_GROUND_TRUTH_MAP = {'pred_0' : 'gt_0',
                            'pred_1' : 'gt_1'}

# add the ground truth and predicted attributes to the model
# specifying that the `pred_1` attribute is the
# positive predicted attribute, which means it corresponds to the
# probability that the binary target attribute is 1
arthur_model.add_binary_classifier_output_attributes(positive_predicted_attr='pred_1',
                                                     pred_to_ground_truth_map=PRED_TO_GROUND_TRUTH_MAP)

For binary models, GroundTruth is always an integer, and PredictedAttribute is always a float. Additionally, PredictedAttribute is expected to be a probability (e.g. the output of a scikit-learn model’s predict_proba method), rather than a classification to 0/1.

This assumes that separate columns for predicted values and ground truth values have already been created, and that they have both been broken into two separate (pseudo-onehot) columns: for example, the column ground_truth_label becomes ground_truth_label=0 and ground_truth_label=1, and the column pred_prob becomes pred_prob=0 and pred_prob=1. The pandas function pd.get_dummies() can be useful for reformatting the ground truth column, but be sure that the datatype is specified correctly as an int.

Parameters
  • positive_predicted_attr (str) – string name of the predicted attribute to register as the positive predicted attribute

  • pred_to_ground_truth_map (Dict[str, str]) – Map of predicted value attributes to their corresponding ground truth attribute names. The names provided in the dictionary will be used to register the one-hot encoded version of the attributes. For example: {‘pred_0’: ‘gt_0’, ‘pred_1’: ‘gt_1’}, Ensure the ordering of items in this dictionary is an accurate representation of how model predictions (probability vectors) will be generated.

  • threshold (float) – Threshold to use for the classifier model, defaults to 0.5

Return type

Dict[str, ArthurAttribute]

Returns

Mapping of added attributes string name -> ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

add_classifier_output_attributes_gtclass(pred_to_ground_truth_class_map, ground_truth_column, data, positive_predicted_attr=None)#

Registers ground truth and predicted value attributes for classification models

Registers a GroundTruthClass attribute. In addition, registers a predicted value attribute for each of the model’s predicted values.

For an introduction to attributes and stages, see https://docs.arthur.ai/user-guide/basic_concepts.html#attributes-and-stages

Create a predicted value attribute for each key in pred_to_ground_truth_class_map and a ground truth class attribute for the ground_truth_column.

# Map PredictedValue attribute to its corresponding GroundTruth attribute value.
# This tells Arthur that the `pred_survived` column represents
# the probability that the ground truth column has the value 1
PRED_TO_GROUND_TRUTH_MAP = {
    "pred_value": 1
}

# Add the ground truth and predicted attributes to the model,
# specifying which attribute represents ground truth and
# which attribute represents the predicted value.
arthur_model.add_classifier_output_attributes_gtclass(
    positive_predicted_attr = 'pred_value',
    pred_to_ground_truth_class_map = PRED_TO_GROUND_TRUTH_MAP,
    ground_truth_column = 'gt_column'
)
Parameters
  • pred_to_ground_truth_class_map (Dict[str, Any]) – map from predicted column names to corresponding ground truth values

  • ground_truth_column (str) – column name of column in data holding the ground truth values

  • data (DataFrame) – DataFrame containing ground truth column data

  • positive_predicted_attr (Optional[str]) – string name of the predicted attribute to register as the positive predicted attribute, if binary classification

return: Mapping of added attributes string name -> ArthurAttribute Object

Return type

Dict[str, ArthurAttribute]

add_image_attribute(name=None)#

Wraps add_attribute for images (see ArthurModel.add_attribute())

Automatically sets the stage as ModelPipelineInput

Return type

List[ArthurAttribute]

Returns

ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

add_multiclass_classifier_output_attributes(pred_to_ground_truth_map)#

Registers GroundTruth and PredictedValue attributes

For an introduction to attributes and stages, see https://docs.arthur.ai/user-guide/basic_concepts.html#attributes-and-stages

This function will create a predicted value and ground truth attribute for each mapping specified in pred_to_ground_truth_map.

# map PredictedValue attributes to their corresponding GroundTruth attributes
PRED_TO_GROUND_TRUTH_MAP = {
    "dog": "dog_gt",
    "cat": "cat_gt",
    "horse": "horse_gt"
}

# add the ground truth and predicted attributes to the model
arthur_model.add_multiclass_classifier_output_attributes(
    pred_to_ground_truth_map = PRED_TO_GROUND_TRUTH_MAP
)
Parameters

pred_to_ground_truth_map (Dict[str, str]) – Map of predicted value attributes to their corresponding ground truth attribute names. The names provided in the dictionary will be used to register the one-hot encoded version of the attributes. Ensure the ordering of items in this dictionary is an accurate representation of how model predictions (probability vectors) will be generated.

Return type

Dict[str, ArthurAttribute]

Returns

Mapping of added attributes string name -> ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

add_object_detection_output_attributes(predicted_attr_name, gt_attr_name, image_class_labels)#

Registers ground truth and predicted value attributes for an object detection model, as well as setting the image class labels.

For a guide to onboarding object detection models, see https://docs.arthur.ai/user-guide/walkthroughs/cv_onboarding.html#object-detection

This function will create a predicted value attribute and ground truth attribute using the names provided, giving each a value type of Bounding Box. Image class labels are also set on the model object. The index of each label in the list should correspond to a class_id the model outputs.

Ex: image_class_labels = [‘cat’, ‘dog’, ‘person’] So a bounding box with class_id of 0 would have label ‘cat’, class_id of 1 would have label ‘dog’, and class_id of 2 would have label ‘person’

predicted_attribute_name = "objects_detected"
ground_truth_attribute_name = "label"
class_labels = ['cat', 'dog', 'person']

arthur_model.add_object_detection_output_attributes(
    predicted_attribute_name,
    ground_truth_attribute_name,
    class_labels)
Parameters
  • predicted_attr_name (str) – The name of the predicted value attribute

  • gt_attr_name (str) – The name of the ground truth attribute

  • image_class_labels (List[str]) – The labels for each class the model can predict, ordered by their class_id

Return type

Dict[str, ArthurAttribute]

Returns

Mapping of added attributes string name -> ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

add_regression_output_attributes(pred_to_ground_truth_map, value_type, data=None)#

Registers ground truth attributes and predicted value attributes for regression models.

For an introduction to attributes and stages, see https://docs.arthur.ai/user-guide/basic_concepts.html#attributes-and-stages

from arthurai.common.constants import ValueType

# map PredictedValue attributes to their corresponding GroundTruth attributes
PRED_TO_GROUND_TRUTH_MAP = {
    "pred_value": "gt_value",
}

# add the ground truth and predicted attributes to the model
arthur_model.add_regression_output_attributes(
    pred_to_ground_truth_map = PRED_TO_GROUND_TRUTH_MAP,
    value_type = ValueType.Float
)
Parameters
  • pred_to_ground_truth_map (Dict[str, str]) – Map of predicted value attributes to their corresponding ground truth attribute names. The names provided in the dictionary will be used to register the one-hot encoded version of the attributes.

  • value_type (ValueType) – Value type of regression model output attribute (usually either ValueType.Integer or ValueType.Float)

  • data (Optional[DataFrame]) – a reference DataFrame to build the model from. This is optional since it is currently only used to calculate the min_range and max_range values of the predicted + ground truth attributes. If data is not passed, min_range and max_range are not set in the attributes

Return type

Dict[str, ArthurAttribute]

Returns

Mapping of added attributes string name -> ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

archive()#

Archives the model with a DELETE request

Returns

the server response

Raises

Exception – the model has no ID, or the model has not been archived

Permissions

model delete

await_inferences(min_count=1, with_ground_truth=True, timeout_min=5)#

Await a minimum number of inferences being available for querying

Parameters
  • min_count (int) – Minimum number of inferences present for success (default 1)

  • with_ground_truth – if True, only count inferences with corresponding ground truth values

  • timeout_min – max number of minutes to wait before timing out

Return type

None

Returns

None

Raises

TimeoutError – if time limit is exceeded

await_model_ready()#

wait for model to be Ready

Wait until the model reaches Ready or CreationFailed state. It also prints the log that a model is onboarding until a valid model state is reached.

Raises

ArthurInternalError – If an exception occurs when checking the status of the model or model reaches CreationFailed state

binarize(attribute_value)#

Creates a binary class probability based on classes defined in a ModelType.Multiclass model

This function is only valid for models with two PredictedValue attributes which correspond to the positive and negative probabilities of a binary classifier

# creates a binary class probability
# evaluating the model's two predicted values against this value
model.binarize({'ground_truth_column' : value})
Parameters

attribute_value – a mapping of the name of a predicted value attribute to its value

Returns

A two-value dictionary with probabilities for both predicted classes.

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

build(data, pred_to_ground_truth_map, positive_predicted_attr=None, non_input_columns=None, ground_truth_column=None, set_reference_data=True)#

Build an Arthur model from a Pandas DataFrame, inferring the attribute metadata and registering the reference data to be stored with Arthur.

For a quickstart guide to building an ArthurModel, see https://docs.arthur.ai/user-guide/arthur_quickstart.html

The pred_to_ground_truth_map parameter tells Arthur how the predicted value attributes relate to the ground truth attributes of your model.

This dictionary can be formatted two different ways:

  1. a prediction column name to ground truth column name mapping passed to pred_to_ground_truth_map

# map PredictedValue attribute to its corresponding GroundTruth attribute
# this tells Arthur that the `pred_value` column represents
# the predicted value corresponding to the
# ground truth values in the `gt_column` column
PRED_TO_GROUND_TRUTH_MAP = {'pred_value' : 'gt_column'}

arthur_model.build(reference_df,
                   pred_to_ground_truth_map=PRED_TO_GROUND_TRUTH_MAP)
  1. a prediction column name to ground truth class value mapping passed to pred_to_ground_truth_map,

    plus the name of the column holding the ground truth class values passed to ground_truth_column

# map PredictedValue attribute to its corresponding GroundTruth attribute value
# this tells Arthur that the `pred_value` column represents
# the probability that the GroundTruth attribute `gt_column` = 1
# which we indicate in arthur_model.build() with the `ground_truth_column` parameter
PRED_TO_GROUND_TRUTH_MAP = {'pred_value' : 1}

arthur_model.build(reference_df,
                   ground_truth_column="gt_column",
                   pred_to_ground_truth_map=PRED_TO_GROUND_TRUTH_MAP)

Note that this function will remove any previously existing attributes. Combines calls to ArthurModel.infer_schema() and (if set_reference_data is True) ArthurModel.set_reference_data()

Parameters
  • data (DataFrame) – a reference DataFrame to build the model from

  • pred_to_ground_truth_map (Dict[str, Any]) – a mapping from predicted column names to their corresponding ground truth column names, or ground truth values in ground_truth_column

  • positive_predicted_attr (Optional[str]) – name of the predicted attribute to register as the positive predicted attribute

  • non_input_columns (Optional[List[str]]) – list of columns that contain auxiliary data not directly passed into the model

  • set_reference_data – if True, register the provided DataFrame as the model’s reference dataset

  • ground_truth_column (Optional[str]) – a single column name containing ground truth labels. must be used with pred to ground truth class map

Return type

DataFrame

Returns

a DataFrame summarizing the inferred types

check_attr_is_bias(attr_name)#

Returns True if and only if the model has an attribute with the given name attr_name being monitored for bias by Arthur

check_has_bias_attrs()#

Returns True if and only if the model has any attributes being monitored for bias by Arthur

static clean_nones(d)#

Helper function to filter out None objects from a json or dictionary representation of an object

Parameters

d – a Dictionary or Json representation of an ArthurBaseJsonDataclass object

Returns

Dictionary of the object with all None components removed

close_batch(batch_id, num_inferences=None)#

Closes the specified batch, optionally can supply the number of inferences that are contained in the batch

Parameters
  • batch_id (str) – String batch_id associated with the batch that will be closed

  • num_inferences (Optional[int]) – Optional number of inferences that are contained in the batch

Return type

Dict

Returns

Response of the batch close rest call

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data write

create_alert_rule(metric_id, bound, threshold, severity, name=None, lookback_period=None, subsequent_alert_wait_time=None, metric_parameters=None, filters=None)#

Creates alert rules for the current model.

For an introduction to alerts, see https://docs.arthur.ai/user-guide/basic_concepts.html#alerts

For a guide to configuring alerts, see https://docs.arthur.ai/user-guide/walkthroughs/metrics_alerts.html#id1

Parameters
  • metric_id (str) – unique id (UUID) of the metric to use to create an alert rule.

  • name (Optional[str]) – A name for the alert rule, a default will be generated if this is not supplied.

  • bound (AlertRuleBound) – Whether the alert is triggered crossing the threshold from above or below. Either AlertRuleBound.Upper or AlertRuleBound.Lower

  • threshold (Union[int, float]) – Threshold value of the alert rule. When the metric crosses this threshold, the alert is triggered.

  • severity (AlertRuleSeverity) – AlertRuleSeverity of the alert which gets triggered when the metric violates the threshold of the alert rule.

  • lookback_period (Union[int, float, None]) – The lookback time or “window length” in minutes to use when calculating the alert rule metric. For example, a lookback period of 5 minutes for an alert rule on average prediction will calculate average prediction for the past 5 minutes in a rolling window format. This will default to 5 minutes

  • subsequent_alert_wait_time (Union[int, float, None]) – If metric continues to pass threshold this is the time in minutes to wait before triggering another alert. This defaults to 0. This does not need to be set for batch alerts.

  • metric_parameters (Optional[Dict[str, Any]]) – mapping from metric parameter name to desired value

  • filters (Optional[Dict[str, Any]]) – filters to use when evaluating the metric used in the alert rule

Return type

AlertRule

Returns

the created alert rule

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

alert_rule write

create_metric(name, query, is_data_drift=False)#

Creates a metric registered to this model and returns the UUID assigned to the newly created metric.

This metric can be used to create alert rules on.

For an introduction to creating metrics for alert rules, see https://docs.arthur.ai/user-guide/walkthroughs/metrics_alerts.html#creating-custom-metrics

Parameters
  • name (str) – Name of the metric to create.

  • query (Dict[str, Any]) – Query which makes up the metric

  • is_data_drift (bool) – Boolean to signal whether this query is a data drift metric or not.

Return type

str

Returns

UUID of the newly created metric

Permissions

metric_query write

delete_explainer()#

Spin down the model explainability server

After calling this function, explainability will have to be re-enabled if you want to compute feature importance scores for your model.

Return type

None

Returns

the server response

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

enrichment_config write

enable_bias_mitigation()#

Updates the bias mitigation Enrichment to be enabled

See also

This convenience function wraps ArthurModel.update_enrichment()

Permissions

enrichment_config write

enable_explainability(df=None, project_directory=None, user_predict_function_import_path=None, streaming_explainability_enabled=True, requirements_file='requirements.txt', python_version=None, sdk_version='3.26.2', model_server_num_cpu=None, model_server_memory=None, model_server_max_replicas=None, inference_consumer_num_cpu=None, inference_consumer_memory=None, inference_consumer_thread_pool_size=None, inference_consumer_score_percent=None, explanation_nsamples=None, explanation_algo=None, ignore_dirs=None)#

Enable explainability for this model.

Parameters
  • df (Optional[DataFrame]) – a dataframe containing the Stage.ModelPipelineInput values for this model. Required for non-image models.

  • project_directory (Optional[str]) – the name of the directory containing the model source code. Required.

  • user_predict_function_import_path (Optional[str]) – the name of the file that implements or wraps the predict function. Required.

  • streaming_explainability_enabled (Optional[bool]) – Defaults to true. flag to turn on streaming explanations which will explain every inference sent to the platform. If false, explanations will need to be manually generated for each inference via the Arthur API. Set to false if worried about compute cost.

  • requirements_file (str) – the name of the file that contains the pip requirements (default: requirements.txt)

  • python_version (Optional[str]) – the python version (default: sys.version). Should be in the form of <major>.<minor>

  • sdk_version (str) – the version of the sdk to initialize the model servier with

  • model_server_num_cpu (Optional[str]) – string number of CPUs to provide to model server docker container. If not provided, 1 CPU is used. Specified in the format of Kubernetes CPU resources. ‘1’, ‘1.5’, ‘100m’, etc.

  • model_server_memory (Optional[str]) – The amount of memory to allocate to the model server docker container. Provided in the format of kubernetes memory resources “1Gi” or “500Mi” (default: None).

  • model_server_max_replicas (Optional[int]) – The max number of model servers to create

  • inference_consumer_num_cpu (Optional[str]) – string number of CPUs to provide to inference consumer docker container. If not provided, 1 CPU is used. Specified in the format of Kubernetes CPU resources. ‘1’, ‘1.5’, ‘100m’, etc. (default: ‘1’)

  • inference_consumer_memory (Optional[str]) – The amount of memory to allocate to the model server docker container. Provided in the format of kubernetes memory resources “1Gi” or “500Mi” (default: ‘1G’).

  • inference_consumer_thread_pool_size (Optional[int]) – The number of inference consumer workers, this determines how many requests to the model server can be made in parallel. Default of 5. If increasing, CPU should be increased as well.

  • inference_consumer_score_percent (Optional[float]) – What percent of inferences should get scored. Should be a value between 0.0 and 1.0. Default 1.0 (everything is scored)

  • explanation_nsamples (Optional[int]) – number of predictions to use in the explanation. For SHAP and LIME, the default is 2000. (default: None)

  • explanation_algo (Optional[str]) – the algorithm to use for explaining inferences. Valid values are ‘lime’ and ‘shap’. Defaults to ‘lime’.

  • ignore_dirs (Optional[List[str]]) – a list of directories within the project_directory that you do not want to include when uploading the model. Path is relative to project_directory.

Return type

Dict[str, Any]

Returns

response content

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

enrichment_config write

enable_hotspots()#

Updates the hotspots Enrichment to be enabled

See also

This convenience function wraps ArthurModel.update_enrichment()

Permissions

enrichment_config write

explain_inference(partner_inference_id, algorithm='lime', page=1, page_size=500, n_samples=None, sort=None)#

Returns feature importance scores for each attribute of stage ModelPipelineInput

Parameters
  • partner_inference_id (str) – the ID attached to the inference

  • algorithm (str) – the explanation algorithm (‘lime’ or ‘shap’) used to generate the feature importance scores

  • page (int) – the number of batches to split the results into

  • page_size (int) – the maximum number of inferences in each batch if returning inferences in batches

  • n_samples (Optional[int]) – # local perturbations for explanation (if None, uses default from lime or shap)

  • sort (Optional[str]) – option for the ordering of returned explanations

Return type

Dict[str, Any]

Returns

Upload status response in the following format:

{
    "explanation": [
        {
            "algorithm": "shap",
            "predicted_attribute_name": "class_a",
            "importance_scores": [
                {
                    "attribute_name": "feature_a",
                    "explanation_value": 0.12,
                    "tokens": [
                        {
                            "token": "dog",
                            "position": 0,
                            "explanation_value": 0.48
                        }
                    ]
                }
            ]
        }
    ],
    "expected_value": [
        {
            "predicted_attribute_name": "feature_a",
            "expected_value": 0.12
        }
    ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data read

find_hotspots(metric='accuracy', threshold=0.5, batch_id=None, date=None, ref_set_id=None)#

Retrieve hotspots from the model

For an introduction to the hotspots Enrichment, see http://docs.arthur.ai/user-guide/walkthroughs/enrichments.html#hotspots

Parameters
  • metric (AccuracyMetric) – accuracy metric used to filter hotspots tree by, defaults to “accuracy”

  • threshold (float) – threshold for of performance metric used for filtering hotspots, defaults to 0.5

  • batch_id (Optional[str]) – string id for the batch to find hotspots in, defaults to None

  • date (Optional[str]) – string used to define date, defaults to None

  • ref_set_id (Optional[str]) – string id for the reference set to find hotspots in, defaults to None

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data read

Return type

Dict[str, Any]

from_dataframe(data, stage)#

Auto-generate attributes based on input data

Deprecated since version 3.12.0: Please use ArthurModel.infer_schema() to add fields from a DataFrame to a model.

Note that this does not automatically set reference data; this method only reads the passed-in data, and then infers attribute names, types, etc. and sets them up within the ArthurModel.

See also

To also set your data as reference data, see ArthurModel.build()

For PredictedValue and GroundTruth stages, use the correct add_<modeltype>_output_attributes() method instead.

Parameters
  • data (Union[DataFrame, Series]) – the data to infer attribute metadata from

  • stage (Stage) – Stage of the data

Return type

None

Returns

a DataFrame summarizing the inferred types

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

get_alert_rules(page=1, page_size=20)#

Returns a paginated list of alert rules registered to this model

For an introduction to alerts, see https://docs.arthur.ai/user-guide/basic_concepts.html#alerts

For a guide to configuring alerts, see https://docs.arthur.ai/user-guide/walkthroughs/metrics_alerts.html#id1

Parameters
  • page (int) – page of alert rules to retrieve, defaults to 1

  • page_size (int) – number of alert rules to return per page, defaults to 20

Return type

List[AlertRule]

Returns

List of arthurai.client.apiv3.AlertRule objects

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

alert_rule read

get_alerts(page=1, page_size=500, status=None, alert_rule_id=None, batch_id=None, start_time=None, end_time=None)#

Returns a paginated list of alert registered to this model.

For an introduction to alerts, see https://docs.arthur.ai/user-guide/basic_concepts.html#alerts

For a guide to configuring alerts, see https://docs.arthur.ai/user-guide/walkthroughs/metrics_alerts.html#id1

Parameters
  • page (int) – page of alert rules to retrieve, defaults to 1

  • page_size (int) – number of alert rules to return per page, defaults to 500

  • status (Optional[str]) – status of alert rule

  • alert_rule_id (Optional[str]) – id of alert rule

  • batch_id (Optional[str]) – constrain returned alert rules to this batch id

  • start_time (Optional[str]) – constrain returned alert rules to after this time

  • end_time (Optional[str]) – constrain returned alert rules to before this time

Return type

List[Alert]

Returns

List of arthurai.client.apiv3.Alert objects

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

alert read

get_attribute(name, stage=None)#

Retrieves an attribute by name and stage

Parameters
  • name (str) – string name of the attribute to retrieve

  • stage (Optional[Stage]) – Optional Stage of attribute to retrieve

Return type

ArthurAttribute

Returns

ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

get_attribute_names(stage=None)#

Returns a list of the names of attributes for the specified stage. If stage is not supplied the function will return all attribute names.

Parameters

stage (Optional[Stage]) – arthurai.common.constants.Stage to filter by

Return type

List[str]

Returns

List of string attribute names

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

get_attributes(stage=None)#

Returns a list of attributes for the specified stage. If stage is not supplied the function will return all attributes.

Parameters

stage (Optional[Stage]) – arthurai.common.constants.Stage to filter by

Return type

List[ArthurAttribute]

Returns

List of arthurai.attributes.ArthurAttribute

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

get_enrichment(enrichment)#

Returns configuration for the specified enrichment.

For an introduction to enrichments, see https://docs.arthur.ai/user-guide/basic_concepts.html#enrichments

For a guide to configuring enrichments, see https://docs.arthur.ai/user-guide/walkthroughs/enrichments.html

Parameters

enrichment (Enrichment) – Enrichment constant

Return type

Dict[str, Any]

Returns

Enrichment config

{
    "enabled": true,
    "config": {
        "python_version": "3.7",
        "sdk_version": "3.0.11",
        "streaming_explainability_enabled": false,
        "user_predict_function_import_path": "entrypoint",
        "shap_expected_values": "[0.7674405187893311, 0.23255948121066888]",
        "model_server_cpu": "2",
        "model_server_memory": "1Gi",
        "model_server_max_replicas": "5",
        "explanation_nsamples": 1000,
        "explanation_algo": "lime",
        "inference_consumer_cpu": "100m",
        "inference_consumer_memory": "512Mi",
        "inference_consumer_score_percent": "1.0",
        "inference_consumer_thread_pool_size": "1",
        "service_account_id": "8231affb-c107-478e-a1b4-e24e7f1f6619"
    }
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

enrichment_config read

get_enrichments()#

Returns configuration for all enrichments.

For an introduction to enrichments, see https://docs.arthur.ai/user-guide/basic_concepts.html#enrichments

For a guide to configuring enrichments, see https://docs.arthur.ai/user-guide/walkthroughs/enrichments.html

Return type

Dict[str, Any]

Returns

Upload status response in the following format:

{
    "anomaly_detection": {
        "enabled": false
    },
    "explainability": {
        "config": {
            "python_version": "3.7",
            "sdk_version": "3.0.11",
            "streaming_explainability_enabled": false,
            "user_predict_function_import_path": "entrypoint",
            "shap_expected_values": "[0.7674405187893311, 0.23255948121066888]",
            "model_server_cpu": "2",
            "model_server_memory": "1Gi",
            "model_server_max_replicas": "5",
            "explanation_nsamples": 1000,
            "explanation_algo": "lime",
            "inference_consumer_cpu": "100m",
            "inference_consumer_memory": "512Mi",
            "inference_consumer_score_percent": "1.0",
            "inference_consumer_thread_pool_size": "1",
            "service_account_id": "8231affb-c107-478e-a1b4-e24e7f1f6619"
        },
        "enabled": true
    }
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

enrichment_config read

get_image(image_id, save_path, type='raw_image')#

Saves the image specified by image_id to a file

Parameters
  • image_id (str) – id of image in model

  • save_path (str) – directory to save the downloaded image to

  • type (ImageResponseType) – type of response data

Return type

str

Returns

location of downloaded image file

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data read

get_image_attribute()#

Returns the attribute with value_type=Image for input_type=Image models

Return type

ArthurAttribute

Returns

ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

get_metrics(default_metrics=False, metric_type=None, metric_id=None, metric_name=None, attribute_name=None)#

Retrieves metrics associated with the current model. Can add optional filters to search with function parameters. :type default_metrics: bool :param default_metrics: If set to True will return only metrics that are automatically created by default for your model :type metric_type: Optional[MetricType] :param metric_type: MetricType to filter metric query with :type metric_id: Optional[str] :param metric_id: Metric UUID to use in filtering metric search :type metric_name: Optional[str] :param metric_name: Metric name filter to use in metric search :type attribute_name: Optional[str] :param attribute_name: Attribute name filter to use in metric search :rtype: List[Metric] :return: list of metrics returned from metric search :permissions: metric_query read

get_positive_predicted_class()#

Checks if model is a binary classifier. Returns False if multiclass, otherwise returns the name of the positive predicted attribute

property ground_truth_type: Optional[arthurai.common.constants.Stage]#

Returns GroundTruthClass if Arthur performed one-hot encoding in the creation of this model’s current ground truth attribute. Otherwise, returns GroundTruth.

The GroundTruthClass stage is an Arthur-generated stage of attributes, which are made after one-hot encoding attributes of the GroundTruth stage.

Return type

Optional[Stage]

infer_schema(data, stage)#

Auto-generate attributes based on input data

For an introduction to the model schema, see https://docs.arthur.ai/user-guide/basic_concepts.html#model-schema

Note that this method does not automatically set reference data; this method only reads the passed-in data, and then infers attribute names, types, etc. and sets them up within the ArthurModel.

See also

To infer the model schema and set reference data in a single call, see ArthurModel.build().

Once you’ve inferred the model schema with this function, you may want to set reference data separately with ArthurModel.set_reference_data().

For PredictedValue and GroundTruth stages, use the correct add_<modeltype>_output_attributes() method instead.

Parameters
  • data (Union[DataFrame, Series]) – the data to infer attribute metadata from

  • stage (Stage) – Stage of the data

Return type

None

Returns

a DataFrame summarizing the inferred types

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

model_is_saved()#

Returns True if and only if the model has been saved to the Arthur platform

Return type

bool

one_hot_encode(value)#

Creates a one hot encoding of a class label based on classes defined in a ModelType.Multiclass model

This function does not modify your model’s attributes.

arthur_model.one_hot_encode('attribute_name')
Parameters

value – the name of the ground truth attribute to one-hot-encode

Returns

A dictionary with a one hot encoding of possible ground truth values.

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

query(body, query_type='base')#

Execute query against the model’s inferences. For full description of possible functions, aggregations, and transformations, see https://docs.arthur.ai/user-guide/api-query-guide/index.html

Parameters
  • body (Dict[str, Any]) – dict

  • query_type – str Can be either ‘base’, ‘drift’, or ‘drift_psi_bucket_table’

body = {
           "select":[
              {"property":"batch_id"},
              {
                 "function":"count",
                 "alias":"inference_count"
              }
           ],
           "group_by":[
              {"property":"batch_id"}
           ]
        }
body = {
           "select":[,
              {"property":"batch_id"},
              {
                 "function":"rate",
                 "alias":"positive_rate",
                 "parameters":{
                    "property":"predicted_1",
                    "comparator":"gt",
                    "value":0.75
                 }
              }
           ],
           "group_by":[
              {"property":"batch_id"}
           ]
        }
Returns

the query response

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

query execute

remove_attribute(name=None, stage=None, attribute=None)#

Removes an already-made ArthurAttribute from the model.

Note that attributes may only be removed from unsaved models - for a saved model, attributes are immutable.

Parameters
  • name (Optional[str]) – Optional string, the name of the ArthurAttribute Object to remove from the model

  • stage (Optional[Stage]) – Optional Stage, the stage of the ArthurAttribute Object to remove from the model

  • attribute (Optional[ArthurAttribute]) – Optional ArthurAttribute Object to remove from the model

Return type

None

Returns

None

Raises
  • MethodNotApplicableError – failed due to incorrect usage on saved model

  • UserValueError – failed due to user error inputting unrecognized attribute

rename_attribute(old_name, new_name, stage)#

Renames an attribute by name and stage

Parameters
  • old_name (str) – string name of the attribute to rename

  • new_name (str) – string new name of the attribute

  • stage (Stage) – Stage of attribute

Return type

ArthurAttribute

Returns

ArthurAttribute Object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

review(stage=None, props=None, print_df=False)#

Prints a summary of the properties of all attributes in the model.

Parameters
  • stage (Optional[Stage]) – restrict the output to a particular Stage (defaults to all stages)

  • props (Optional[List[str]]) – a list of properties to display in the summary valid properties are data_type, categorical, is_unique, categories, cutoffs, range, monitor_for_bias, position (defaults to data_type, categorical, is_unique)

  • print_df – boolean value whether to print df or return it, defaults to False

Return type

Optional[DataFrame]

Returns

a DataFrame summarizing the inferred types; or None if print_df is True

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

save()#

Check and save this model

After this method is called successfully, your model is sent to the Arthur Platform where all its data and metrics are saved. The method will start an async call to get the model ready to accept inferences and will run a spinner until model reaches Ready or CreationFailed state. If you cancel the call when the spinner is running, the model is still being provisioned and does not cancel model onboarding. You won’t be able to send inferences until model reaches Ready state. You can use await_model_ready() method to wait for it.

If the model onboarding fails, you can execute this method again to retry model onboarding.

Returns the model’s ID in the Arthur platform once the upload is successful.

model_id = arthur_model.save()
with open("fullguide_model_id.txt", "w") as f:
    f.write(model_id) # saving this model's id to a local file
Return type

str

Returns

The model id

Raises
  • MethodNotApplicableError – the model has already been saved

  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

model write AND (usually) reference_data write

send_batch_ground_truths(directory_path=None, data=None)#

Deprecated since version 3.10.0: Please use ArthurModel.send_bulk_ground_truths() for both streaming and batch data.

Parameters
  • directory_path (Optional[str]) – file path to a directory of parquet files containing ground truth data

  • data (Union[DataFrame, Series, None]) – a DataFrame or Series containing the reference data for the Stage

Returns

Upload status response in the following format:

{
    "counts": {
        "success": 1,
        "failure": 0,
        "total": 1
    },
    "results": [
        {
            "message": "success",
            "status": 200
        }
    ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

send_batch_inferences(batch_id, directory_path=None, data=None, complete_batch=True)#

Send many inferences at once

Deprecated since version 3.10.0: Use ArthurModel.send_inferences() to send batch or streaming data synchronously (recommended fewer than 100,000 rows), or ArthurModel.send_bulk_inferences() to send many inferences or Parquet files.

Parameters
  • batch_id (Optional[str]) – string id for the batch to upload; if supplied, this will override any batch_id column specified in the provided dataset

  • data (Optional[DataFrame]) – a DataFrame containing the reference data.

  • directory_path (Optional[str]) – file path to a directory of parquet files containing ground truth data

  • complete_batch (bool) – Defaults to true and will automatically close a batch once it is sent

Returns

A tuple of the batch upload response and the close batch response. The batch upload response is in the following format:

{
    "counts": {
        "success": 0,
        "failure": 0,
        "total": 0
    },
    "failures": []
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

send_bulk_ground_truths(directory_path=None, data=None)#

Uploads a large batch of ground truth values to Arthur

Uploads a DataFrame or directory containing parquet files to the Arthur bulk inferences ingestion endpoint. Recommended for uploads of >100,000 rows of data.

Parameters
  • directory_path (Optional[str]) – file path to a directory of parquet files containing ground truth data. Required if data is not provided, and cannot be populated if data is provided.

  • data (Union[DataFrame, Series, None]) – a DataFrame or Series containing the ground truth data. Required if directory_path is not provided, and cannot be populated it directory_path is not provided.

Returns

Upload status response in the following format:

{
    "counts": {
        "success": 0,
        "failure": 0,
        "total": 0
    },
    "results": [
        {
            "message": "success",
            "status": 200
        }
    ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data write

send_bulk_inferences(batch_id=None, directory_path=None, data=None, complete_batch=True, ignore_join_errors=False)#

Uploads a large batch of inferences to Arthur

Uploads a DataFrame or directory containing parquet and/or json files to the Arthur bulk inferences ingestion endpoint. Recommended for uploads of >100,000 rows of data.

Validates and uploads parquet and/or json files containing columns for inference data, partner_inference_id, inference_timestamp, and optionally a batch_id. Either directory_path or data must be specified.

See also

To send ground truth for your inferences, see ArthurModel.send_bulk_ground_truth()

The columns for predicted attributes should follow the column format specified in add_<modeltype>_classifier_output_attributes(). Additionally, partner_inference_id, must be specified for all inferences unless ignore_join_errors is True.

Parameters
  • batch_id (Optional[str]) – string id for the batch to upload; if supplied, this will override any batch_id column specified in the provided dataset

  • directory_path (Optional[str]) – file path to a directory of parquet and/or json files containing inference data. Required if data is not provided, and cannot be populated if data is provided.

  • data (Optional[DataFrame]) – a DataFrame or Series containing the inference data. Required if directory_path is not provided, and cannot be populated if directory_path is not provided.

  • complete_batch (bool) – Defaults to true and will automatically close a batch once it is sent

  • ignore_join_errors (bool) – if True, allow inference data without partner_inference_id or ground truth data

Returns

A tuple of the batch upload response and the close batch response. The batch upload response is in the following format:

{
    "counts": {
        "success": 1,
        "failure": 0,
        "total": 1
    },
    "results": [
        {
            "message": "success",
            "status": 200
        }
    ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data write

send_inference(inference_timestamp, partner_inference_id='', model_pipeline_input=None, non_input_data=None, predicted_value=None, ground_truth=None)#

Deprecated since version 3.20.0: Please use ArthurModel.send_inferences() to send a single inference.

Parameters
  • inference_timestamp (Union[str, datetime]) – timestamp for inference to send; generated by external partner (not Arthur)

  • partner_inference_id (str) – an external id (partner_inference_id) to assign to the inferences

  • model_pipeline_input – a mapping of the name of pipeline input attributes to their value

  • non_input_data – a mapping of the name of non-input data attributes to their value

  • predicted_value – a mapping of the name of predicted value attributes to their value

  • ground_truth – a mapping of the name of ground truth attributes to their value

Returns

Upload status response in the following format:

{
    "counts": {
        "success": 0,
        "failure": 0,
        "total": 0
    },
    "results": [
        {
            "message": "success",
            "status": 200
        }
    ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data write

send_inferences(inferences, predictions=None, inference_timestamps=None, ground_truths=None, ground_truth_timestamps=None, tz=None, partner_inference_ids=None, batch_id=None, fail_silently=False, complete_batch=True)#

Send inferences to the Arthur API. The inferences parameter may contain all the inference data, or only the input data if predictions and metadata are supplied separately. At a minimum, input data and predictions should be passed in: partner_inference_id, inference_timestamp, and (if ground truth data is supplied) ground_truth_timestamp fields are required by the Arthur API, but these will be generated if not supplied.

See also

To send large amounts of data or Parquet files, see ArthurModel.send_bulk_inferences()

Examples:

An input dataframe and predicted probabilities array, leaving the partner inference IDs and timestamps to be auto-generated:

input_df = pd.DataFrame({"input_attr": [2]})
pred_array = my_sklearn_model.predict_proba(input_df)
arthur_model.send_inferences(input_df, predictions=pred_array, batch_id='batch1')

All data in the inferences parameter in the format expected by the Arthur API POST Inferences Endpoint:

inference_data = [
    {
        "inference_timestamp": "2021-06-16T16:52:11Z",
        "partner_inference_id": "inf1",
        "batch_id": "batch1",
        "inference_data": {
            "input_attr": 2,
            "predicted_attr": 0.6
        },
        "ground_truth_timestamp": "2021-06-16T16:53:45Z",
        "ground_truth_data": {
            "ground_truth_attr": 1
        }
    }
]
arthur_model.send_inferences(inference_data)

A list of dicts without nested inference_data or ground_truth fields:

inference_data = [
    {
        "inference_timestamp": "2021-06-16T16:52:11Z",
        "partner_inference_id": "inf1",
        "batch_id": "batch1",
        "input_attr": 2,
        "predicted_attr": 0.6,
        "ground_truth_timestamp": "2021-06-16T16:53:45Z",
        "ground_truth_attr": 1
    }
]
arthur_model.send_inferences(inference_data)
Parameters
  • inferences (Union[List[Dict[str, Any]], Dict[str, List[Any]], DataFrame]) – inference data to send, containing at least input values and optionally predictions, ground truth, timestamps, partner inference ids, and batch IDs.

  • predictions (Union[List[Dict[str, Any]], Dict[str, List[Any]], DataFrame, Sequence[Any], None]) – the model predictions, in a table-like format for one or more columns or a list-like format if the model has only one predicted column. overwrites any predictions supplied in the inferences parameter

  • inference_timestamps (Optional[Sequence[Union[datetime, str]]]) – the inference timestamps, in a list-like format as ISO-8601 strings or datetime objects. if no timestamps are supplied in inferences or this parameter, they will be generated from the current time. overwrites any timestamps in the inferences parameter.

  • ground_truths (Union[List[Dict[str, Any]], Dict[str, List[Any]], DataFrame, Sequence[Any], None]) – the optional ground truth data (true labels), in a table-like format for one or more columns or a list-like format if the model has only one ground truth column. overwrites any ground truth values supplied in the inferences parameter

  • ground_truth_timestamps (Optional[Sequence[Union[datetime, str]]]) – the ground truth timestamps, in a list-like format as ISO-8601 strings or datetime objects. if no ground truth timestamps are supplied in inferences or this parameter but ground truth data is supplied, they will be generated from the current time. overwrites any timestamps in the inferences parameter.

  • tz (Optional[str]) – datetime timezone object or timezone string

  • partner_inference_ids (Optional[Sequence[str]]) – partner_inference_ids to be attached to these inferences, which can be used to send ground truth data later or retrieve specific inferences, in a list-like format containing strings. if no partner_inference_ids are supplied in inference or this parameter, they will be auto-generated.

  • batch_id (Optional[str]) – a single batch ID to use for all inferences supplied. overwrites any batch IDs in the inferences parameter

  • fail_silently (bool) – if True, log failed inferences but do not raise an exception

  • complete_batch (bool) – if True, mark all batches in this dataset as completed

Returns

Upload status response in the following format:

{
  "counts": {
    "success": 1,
    "failure": 0,
    "total": 1
  },
  "results": [
    {
      "partner_inference_id" "inf-id",
      "message": "success",
      "status": 200
    }
  ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data write

set_attribute_as_sensitive(attribute_name, attribute_stage=None)#

Sets the passed-in attribute to be sensitive by setting attr.monitor_for_bias = True.

You will need to call self.save() or self.update() after this method; we do not automatically call the API in this method.

Parameters
  • attribute_name (str) – Name of attribute to set as sensitive.

  • attribute_stage (Optional[Stage]) – Stage of attribute to set as sensitive.

Return type

None

Returns

None

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

set_attribute_labels(attribute_name, labels, attribute_stage=None)#

Sets labels for individual categories of a specific attribute

This function should be used to set the labels corresponding to the different possible values that an attribute can take.

# labels the value 0 for the attribute 'education_level'
# to have the label 'elementary', etc.
arthur_model.set_attribute_labels(
    'education_level',
    {0 : 'elementary', 1 : 'middle', 2 : 'high', 3 : 'university'}
)
Parameters
  • attribute_name (str) – Attribute name to set the categories labels

  • attribute_stage (Optional[Stage]) – Optional stage of the attribute which is being updated

  • labels (Dict[Union[int, str], str]) – Dictionary where the key is the categorical value and the value is the string categorical label

Returns

None

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

set_predict_function_input_order(attributes)#

Sets the expected order of attributes used by the prediction function.

This function should be used when enabling explainability: in particular, if your model’s predict function requires attributes in a specific order, but the attribute positions have not yet been inferred correctly.

Parameters

attributes (List[str]) – a list of attribute names

Return type

None

Returns

None

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

set_reference_data(directory_path=None, data=None)#

Validates and sets the reference data for the given stage to the provided data.

For an introduction to reference data, see https://docs.arthur.ai/user-guide/basic_concepts.html#reference-dataset

To set reference data at the same time as inferring the model schema, see ArthurModel.build() To infer the model schema without setting reference data, see ArthurModel.infer_schema()

# reference dataframe of model inputs
reference_set = ...

# produce model predictions on reference set
# in this example, the predictions are classification probabilities
preds = model.predict_proba(reference_set)

# assign the column corresponding to the positive class
# as the `pred` attribute in the reference data
reference_set["pred"] = preds[:, 1]

# set ground truth labels
reference_set["gt"] = ...

# configure the ArthurModel to use this dataframe as reference data
arthur_model.set_reference_data(data=reference_set)

Either directory_path or data must be provided. Additionally, there must be one column per ModelPipelineInput and NonInput attribute.

For Image models, the image file path should be included as the image atribute value, in either the parquet files specified by directory_path or the DataFrame provided.

Parameters
  • directory_path (Optional[str]) – file path to a directory of parquet files to upload for batch data

  • data (Union[DataFrame, Series, None]) – a DataFrame or Series containing the ground truth data

Returns

Returns a tuple, the first variable is the response from sending the reference set and the second is the response from closing the dataset.

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

reference_data write

swap_predicted_attribute_positions(persist_if_saved=True)#

Swap the position of the model’s two predicted attributes

This function should be used when enabling explainability: in particular, if your model’s predict function requires attributes in a specific order, but the attribute positions have not yet been inferred correctly.

Parameters

persist_if_saved – if the model has been saved, call update() to persist the change

Returns

to_dict(skip_none=True)#

Creates a dictionary representation of this object

This function can be applied to any extension of the ArthurBaseJsonDataClass

Return type

dict

Returns

Dictionary of object data

to_json(skip_none=True)#

Creates a json representation of this object

This function can be applied to any extension of the ArthurBaseJsonDataClass

Return type

str

Returns

json of object data

update()#

Update the current model object in the Arthur platform

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

model write

update_alert(status, alert_id)#

Updates alert to have a particular status.

For an introduction to alerts, see https://docs.arthur.ai/user-guide/basic_concepts.html#alerts

For a guide to configuring alerts, see https://docs.arthur.ai/user-guide/walkthroughs/metrics_alerts.html#id1

Parameters
  • status (AlertStatus) – one of “resolved” or “acknowledged”

  • alert_id (str) – alert id

Return type

Alert

Returns

updated alert object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

alert write

update_alert_rule(alert_rule, alert_rule_id=None)#

Updates alert rule fields included in the alert_rule object for the specified alert rule id. If the alert rules id field is present in the alert_rule parameter that is used otherwise alert_rule_id must be supplied

For an introduction to alerts, see https://docs.arthur.ai/user-guide/basic_concepts.html#alerts

For a guide to configuring alerts, see https://docs.arthur.ai/user-guide/walkthroughs/metrics_alerts.html#id1

Parameters
  • alert_rule (AlertRule) – Object which contains fields to update on the specified alert rule

  • alert_rule_id (Optional[str]) – If the alert rule id is not specified in the alert_rule_to_update object then this must be provided to determine which alert rule to update.

Returns

Updates alert rule object

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

alert_rule write

update_enrichment(enrichment, enabled=None, config=None)#

Update the configuration for a single enrichment

For an introduction to enrichments, see https://docs.arthur.ai/user-guide/basic_concepts.html#enrichments

For a guide to configuring enrichments, see https://docs.arthur.ai/user-guide/walkthroughs/enrichments.html

Parameters
  • enrichment (Enrichment) – the enrichment to update

  • enabled (Optional[bool]) – whether the enrichment should be enabled or disabled

  • config (Optional[Dict[str, Any]]) – the configuration for the enrichment, None by default

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

enrichment_config write

Return type

Dict[str, Any]

update_enrichments(enrichment_configs)#

Update the configuration for 1 or more enrichments.

For an introduction to enrichments, see https://docs.arthur.ai/user-guide/basic_concepts.html#enrichments

For a guide to configuring enrichments, see https://docs.arthur.ai/user-guide/walkthroughs/enrichments.html

Parameters

enrichment_configs (Dict[Union[str, Enrichment], Any]) –

Dict containing the configuration for each enrichment

{
    "anomaly_detection": {
        "enabled": false
    },
    "explainability": {
        "config": {
            "streaming_explainability_enabled": false,
            "explanation_nsamples": 1000,
            "explanation_algo": "lime",
            "inference_consumer_score_percent": "1.0"
        },
        "enabled": true
    }
    "hotspots": {
        "enabled": false
    }
}

Return type

Dict[str, Any]

Returns

the resulting enrichments configuration

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

enrichment_config write

update_inference_ground_truths(ground_truths, partner_inference_ids=None, ground_truth_timestamps=None, tz=None, fail_silently=False)#

Updates inferences with the supplied ground truth values

For an introduction to sending data to Arthur, see https://docs.arthur.ai/user-guide/basic_concepts.html#sending-data-to-arthur

The ground_truth parameter may contain all the required data, or only the data for the attributes from Stage.GroundTruth if metadata is supplied separately. At a minimum, Stage.GroundTruth attribute data and partner_inference_id should be passed in, either along with the attribute data in the ground_truths parameter, or in the partner_inference_ids parameter. Additionally, a ground_truth_timestamp field is required by the Arthur API, but this will be generated if not supplied.

See also

To send large amounts of data or Parquet files, see ArthurModel.send_bulk_ground_truths()

Examples:

A DataFrame containing all required values:

y_test = [1, 0, 1]
existing_inference_ids = [f"batch_1-inf_{i}" for i in len(y_test)]
ground_truth_df = pd.DataFrame({"ground_truth_positive_labels": y_test,
                                "ground_truth_negative_labels": 1 - y_test,
                                "partner_inference_id": existing_inference_ids})
arthur_model.update_inference_ground_truths(ground_truth_df)

A single list of values, with partner_inference_ids supplied separately:

y_test = [14.3, 19.6, 15.7]
existing_inference_ids = [f"batch_1-inf_{i}" for i in len(y_test)]
arthur_model.update_inference_ground_truths(y_test, partner_inference_ids=existing_inference_ids)

All data in the inferences parameter in the format expected by the Arthur API PATCH Inferences Endpoint:

ground_truth_data = [
    {
        "partner_inference_id": "inf1",
        "ground_truth_timestamp": "2021-06-16T16:53:45Z",
        "ground_truth_data": {
            "ground_truth_attr": 1
        }
    }
]
arthur_model.update_inference_ground_truths(ground_truth_data)

A list of dicts without nested ground_truth fields:

inference_data = [
    {
        "partner_inference_id": "inf1",
        "ground_truth_timestamp": "2021-06-16T16:53:45Z",
        "ground_truth_attr": 1
    }
]
arthur_model.send_inferences(inference_data)
Parameters
  • ground_truths (Union[List[Dict[str, Any]], Dict[str, List[Any]], DataFrame, Sequence[Any]]) – ground truth data to send, containing at least values for the ground truth attributes, and optionally ground_truth_timestamp and partner_inference_id.

  • partner_inference_ids (Optional[Sequence[str]]) – partner_inference_ids for the existing inferences to be updated, in a list-like format as strings. Required if not a field in ground_truths.

  • ground_truth_timestamps (Optional[Sequence[Union[datetime, str]]]) – the ground truth timestamps, in a list-like format as ISO-8601 strings or datetime objects. if no ground truth timestamps are supplied in inferences or this parameter, they will be generated from the current time. overwrites any timestamps in the ground_truths parameter.

  • tz (Optional[str]) – datetime timezone object or timezone string

  • fail_silently (bool) – if True, log failed inferences but do not raise an exception.

Returns

Upload status response in the following format:

{
    "counts": {
        "success": 1,
        "failure": 0,
        "total": 1
    },
    "results": [
        {
            "message": "success",
            "status": 200
        }
    ]
}

Raises
  • ArthurUserError – failed due to user error

  • ArthurInternalError – failed due to an internal error

Permissions

raw_data write