AutoMLx

Initialization

automl.interface. init ( engine = 'dask' , engine_opts = {'dask_scheduler': None} , logger = None , loglevel = 30 )

Initializes the AutoMLx framework’s execution engine. AutoMLx can work with a variety of parallelization platforms.

Parameters
  • engine ( str ) –

    Name of the parallelization framework. Can be one of:

    • local: Use Python’s inbuilt multiprocessing framework

    • threading: Use Python’s inbuilt multithreading framework

    • spark: Use Spark as the distributed compute engine. Note: Spark support in AutoMLx is currently experimental and might be unstable.

    • dask: Use Dask as the distributed compute engine.

  • engine_opts ( dict ) –

    Options for the parallelization framework. When engine is:

    • local: engine_opts is of the form {‘n_jobs’ : val1, ‘model_n_jobs’ : val2}, where val1 is the degree of inter-model parallelism and val2 is the degree of intra-model parallelism

    • threading: engine_opts is of the form {‘n_jobs’ : val}, where val is the degree of parallelism

    • spark: engine_opts is of the form {‘spark_master’ : val}, where val is the URI to the spark master (e.g. spark://localhost:7077)

    • dask: engine_opts is of the form {‘dask_scheduler’ : val}, where val can be one of

      • URI of the dask scheduler (e.g. 127.0.0.1:8786)

      • an already initialized Client() instance

  • logger ( logging.Logger , str or None ) –

    Logging mode. One of

    • None: Log to default logging path <Current directory>/logs/automl/ (file + console)

    • str: Log to provided file

    • logging.Logger : Use existing Logger object

  • loglevel ( int ) – Log levels are similar to log levels in python logging module, takes values like logging.INFO.

AutoML

AutoMLx python package automatically provides a tuned ML pipeline that best models the given training dataset and a prediction task at hand. AutoML has a simple pipeline-level Python API that quickly jump-starts the datascience process with an accurate tuned model. AutoML has support for any of the following tasks:

1. Supervised classification or regression prediction with tabular dataset where the target can be a simple binary or a multi-class value or a real valued column in a table, respectively. 2. Unsupervised anomaly detection, where the target or the labels are not provided. 3. Univariate timeseries forecasting task.

The AutoML package consists of five major stages of the ML pipeline: preprocessing , algorithm selection , adaptive sampling , feature selection , and model tuning

These pieces are readily combined into a simple AutoML pipeline which automatically optimizes the whole pipeline with limited user input/interaction.

Pipeline

class automl. Pipeline ( task = 'classification' , score_metric = None , random_state = 7 , n_algos_tuned = 1 , model_list = [] , adaptive_sampling = True , min_features = 1 , optimization = 3 , preprocessing = True , search_space = None , time_series_period = None , min_class_instances = 5 , max_tuning_trials = None )

Bases: automl.interface.base_pipeline_stage.BasePipelineStage

Automatic Machine Learning Pipeline object, uses metalearning to quickly identify most relevant features, model and hyperparameters for a given training dataset.

Parameters
  • task ( str , default=classification ) – Machine learning task, supported: classification, regression, anomaly_detection, forecasting

  • score_metric

    One or more score functions (or loss functions) to be computed for each candidate model and hyperparameter configuration.

    If None:

    It will be determined automatically depending on the task.

    If a list:

    Should be a list of str, callable or tuple. The first score metric in the list will be the one for which the pipeline optimizes.

    If a callable:

    Score function (or loss function) with signature score_func(model, X, y) .

    If a tuple:

    Should be a tuple with two values with types (str, callable). The string corresponds to the name of the scoring metric, and the callable should have the same signature as above.

    If a str:

random_state int, default=7

Random seed used by AutoML.

model_list list of str, default=[]

Models that will be evaluated by the Pipeline. (by default all supported models for a given task are used) Supported models per task:

  • classification: AdaBoostClassifier, DecisionTreeClassifier, ExtraTreesClassifier, TorchMLPClassifier, KNeighborsClassifier, LGBMClassifier, LinearSVC, LogisticRegression RandomForestClassifier, SVC, XGBClassifier, GaussianNB, CatBoostClassifier

  • regression: AdaBoostRegressor, DecisionTreeRegressor, ExtraTreesRegressor, TorchMLPRegressor, KNeighborsRegressor, LGBMRegressor, LinearSVR, LinearRegression, RandomForestRegressor, SVR, XGBRegressor

  • anomaly_detection: IsolationForestOD, SubspaceOD, HistogramOD, ClusteringLocalFactorOD, PrincipalCompOD, MinCovOD, AutoEncoder, KNearestNeighborsOD, OneClassSVMOD.

  • forecasting:

    • NaiveForecaster - Naive and Seasonal Naive method

    • ThetaForecaster - Equivalent to Simple Exponential Smoothing (SES) with drift

    • ExpSmoothForecaster - Holt-Winters’ damped method

    • STLwESForecaster - Seasonal Trend LOESS (locally weighted smoothing) with Exponential Smoothing substructure

    • STLwARIMAForecaster - Seasonal Trend LOESS (locally weighted smoothing) with ARIMA substructure

    • SARIMAXForecaster - Seasonal Autoregressive Integrated Moving Average with Exogenous Variables

    • ETSForecaster - Error, Trend, Seasonality (ETS) Statespace Exponential Smoothing

    • ProphetForecaster (optional) - Facebook Prophet with Exogenous Variables. (Available only if installed locally with pip install fbprophet)

    • OrbitForecaster - Uber Orbit model with Exogenous Variables.

    • VARMAXForecaster - Vector AutoRegressive Moving Average with Exogenous Variables

    • DynFactorForecaster - Dynamic Factor Models in state-space form with Exogenous Variables

n_algos_tuned int, default=1

Number of algorithms that are optimized by the AutoML pipeline. Higher values might make AutoML more accurate at the expense of runtime.

  • To disable algorithm selection set n_algos_tuned = len(model_list) .

adaptive_sampling bool, default=True

Set to False to disable class balancing and adaptive sampling done in AutoML. Disabling this might significantly increase runtime.

min_features int, float, list, default=1

Minimum number of features to keep. Acceptable values:

  • If int, 0 < min_features <= n_features

  • If float, 0 < min_features <= 1.0

  • If list, names of features to keep, for example [‘a’, ‘b’] means keep features ‘a’ and ‘b’ This parameter is ignored for meta-learned feature selection.

  • To disable feature selection set min_features = 1.0

optimization int, default=3

Sets AutoML speed, accuracy, and reproducibility level.

  • Level 0: Optimized for reproducibility (controls most randomness)

  • Level 1: Undefined (placeholder for future version)

  • Level 2: Faster than Level 0, more reproducible than Level 3

  • Level 3: Optimized for speed and accuracy

To be used by advanced users only.

preprocessing : bool, default=True

  • If True, auto-preprocesser runs on dataset to normalize data. Categorical features are label encoded and numeric features are normalized to mean of 0 and variance of 1 using sklearn.preprocessing.StandardScaler. Features with more than 20 percent missing values are ignored. The remaining missing values are imputed by mean for numeric features and mode for categorical features.

  • If False, user must cleanse (and normalize if desired) dataset before passing data to AutoML. The use of NaNs in the dataset is not allowed and will produce a ValueError. AutoML will leave it to the underlying algorithm implementations to handle strings (it is recommended to encode strings).

This setting should only be used by advanced users.

search_space dict, default=None

This parameter defines the Model Tuning search space. Dictionary keys are algorithm names (str) with search space as the key value. Key values must have two parameters: (1) ‘range’ which is a list containing the range and (2) ‘type’ which is one of ‘continuous’, ‘discrete’, ‘categorical’. For example, if the user wishes to provide a custom tune search space for LogisticRegression, search_space = { ‘LogisticRegression’ : {

‘C’: {‘range’: [0.03125, 512], ‘type’: ‘continuous’}, ‘solver’: {‘range’: [‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’], ‘type’: ‘categorical’}, ‘class_weight’: {‘range’: [None, ‘balanced’], ‘type’: ‘categorical’}}}

  • To disable Model Tune for all models set search_space = {}

  • If a key value is an empty dictionary, then Model Tune is disabled for that key.

  • If None, default search space defined inside AutoML is used.

time_series_period int, default=None

The period of time series for the forecasting task

min_class_instances int, default=5

The minimum number of instances all classes must have when doing classification. If any class has less than this number of instances, training is stopped. This argument may take any value of 2 or higher.

max_tuning_trials int|dict|None, default=None

The maximum number of HPO trials, may be exceeded slightly.

If None:

AutoML automatically determines when enough HPO trials have been completed.

If an integer:

The maximum number of trials for each algorithm. That is, if n_algos_tuned == 2, then up to 2 * max_tuning_trials are performed in total.

If a dict:

By passing a dictionary you can specify this parameter per algorithm. e.g., {‘LogisticRegression’: 100, ‘RandomForestClassifier’: 200}. Missing values in the dictionary are defaulted to None.

classes_

Holds the label for each class (for task=classification only, else it is set to None).

Type

array of shape (n_classes,)

selected_features_

Indices of features selected by the AutoML pipeline

Type

list of int

selected_features_names_

Names of features selected by the AutoML pipeline

Type

list of strings

ranked_models_

List of model names ranked in order of their goodness for a fit() call

Type

list of str

selected_model_

Name of the best model selected by AutoML

Type

str

selected_model_params_

Dictionary containing the optimal hyperparameters for the selected model. Keys are hyperparameter names with their corresponding values.

Type

dict

selected_rows_

List of indices in the original train dataset provided to AutoML corresponding to the rows sampled during Adaptive Sampling. in the case of CV, this attribute will result in a list of lists corresponding to indices selected in each fold. For example, in the case of no CV, this attribute looks like: [0, 1, 5], indicating indices 0, 1, and 5 have been selected during adaptive sampling. In the case of CV=3, this attribute looks like: [ [0, 1], [0, 5], [1, 5] ], indicating indices 0,1 were selected from the first fold, 0,5 were selected in the 2nd fold, and 1,5 were selected in the 3rd fold.

Type

list

selected_valid_rows_

List of indices in the original validation dataset (CV=None) provided to AutoML corresponding to the rows sampled during Adaptive Sampling. If CV is not None, the returned value is always None given that Adaptive Sampling does not sample the validation set when CV is enabled.

Type

list

pipelines_

Sorted list of pipelines (length equal to n_algos_tuned), with 0th element being the best model.

Type

list

model_selection_trials_

ML model choices evaluated by model selection. Each tuple is of the form (algorithm, #samples, #features, mean validation score, hyperparameters, all validation scores, runtime, memory_usage), where the hyperparameters are a dict.

Type

list of tuples

adaptive_sampling_trials_

Sampling choices evaluated by adaptive sampling. Each tuple is of the form (algorithm, #samples, #features, mean validation score, hyperparameters, all validation scores, runtime, memory_usage), where the hyperparameters are a dict.

Type

list of tuples

feature_selection_trials_

Subset/Ranking algorithm choices evaluated by feature selection. Each tuple is of the form (algorithm, #samples, #features, mean validation score, hyperparameters, all validation scores, runtime, memory_usage), where the hyperparameters are a dict.

Type

list of tuples

tuning_trials_

Hyperparameter choices evaluated by model tuning ranked in order of their achieved cross-validation scores. Each tuple is of the form (algorithm, #samples, #features, mean validation score, hyperparameters, all validation scores, runtime, memory_usage), where the hyperparameters are a dict.

Type

list of tuples

all_trials_

All trials performed by the AutoML Pipeline. This includes model_selection_trials_, adaptive_sampling_trials_, feature_selection_trial_ and tuning_trials_. Each tuple is of the form (algorithm, #samples, #features, mean validation score, hyperparameters, all validation scores, runtime, memory_usage), where the hyperparameters are a dict.

Type

list of tuples

all_trials_extra_scores_

A DataFrame indicating all trials performed by the AutoML Pipeline with all score metrics value. Each row is of the form (Algorithm, Hyperparameters, # Samples, # Features, Features, Stage, Scoring Metric, CV Fold ID, Score).

Type

DataFrame

n_jobs_

Parallelism internally used by AutoML. Calculated as inter_model_parallelism*intra_model_parallelism.

Type

int

feature_importances_

List of feature importance tuples. Each tuple contains feature name, its importance, and its standard deviation

Type

list of tuples

fit ( X = None , y = None , X_valid = None , y_valid = None , cv = 'auto' , col_types = None , time_budget = 0 , contamination = None )

Automatically identifies the most relevant features, model and hyperparameters for a given training data (X) and target (y). Final model fit is conducted on a full dataset.

Parameters
  • X ( pandas.DataFrame ) – Training dataset features. Optional for forecasting tasks.

  • y ( pandas.DataFrame , pandas.Series , optional ) – Training dataset target. Optional for semi-supervised tasks, e.g., anomaly detection. Note that y is required for forecasting task. (Needs to be passed as None for unsupervised anomaly detection)

  • X_valid ( pandas.DataFrame , optional ) – Validation dataset features

  • y_valid ( pandas.DataFrame , pandas.Series , optional ) – Validation dataset target

  • cv ( auto , int, cross-validation generator or an iterable, optional) –

    Determines the cross-validation splitting strategy. Possible inputs for cv are:

    • None: use X_valid and y_valid for validation

    • auto : 5 folds if number of instances < 1M, disable cv-folds otherwise

    • integer, to specify the number of folds in a (Stratified)KFold ,

    • An iterable yielding (train, test) splits as arrays of indices.

    For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.

  • col_types ( list of strings ) – List of length X.shape[1] with string values indicating type of features. Supported types are: [‘categorical’, ‘numerical’, ‘text’. ‘datetime’, ‘timedelta’] Note: Datetime support is in experimental stage

  • time_budget ( float , optional ) –

    Time budget in seconds.

    • 0 for unconstrained time budget: best effort mode is enabled and optimization continues until convergence.

    (default: 0)

  • contamination ( float , None , optional ) – Fraction of training dataset corresponding to anomalies (between 0.0 and 0.5). Should only be set for supervised anomaly detection (y_valid is required). Should be set to None for unsupervised anomaly detection (when using the unsupervised metrics). (default: None)

Returns

self

Return type

object

forecast ( periods , alpha = 0.05 , X = None )

Forecast with the selected model.

Only out-of-sample forecasts are supported. In-sample fit values should be accessed via the predict interface.

Parameters
  • periods ( int ) – The number of time steps to forecast from the end of the sample.

  • alpha ( float , optional ) – A significance level. To receive a prediction interval of 95% alpha must be set to 0.05

  • X ( pandas.Dataframe , optional ) – A dataframe of explanatory variables that support forecast for period number of timesteps. Columns must match that used in fit().

Returns

summary_frame – A dataframe with three columns listing prediction, ci_lower and ci_upper for the given confidence interval (ci) provided by level of alpha. Note: ci columns are excluded for models that don’t support intervals.

Return type

pandas.Dataframe

predict ( X )

Predict labels for features (X).

Parameters

X ( pandas.DataFrame ) – Training dataset features, or Explanatory features if task is ‘forecasting’

Returns

y_pred – The predicted values.

Return type

array of shape [n_samples]

predict_proba ( X )

Probability estimates.

More information can be found here: Prediction Probabilities

Parameters

X ( pandas.DataFrame ) – Training dataset features

Returns

y_pred – The predicted probabilities.

Return type

array of shape = [n_samples, n_classes]

print_memory_usage ( in_ipython = None )

Prints max memory usage information about the last pipeline run.

Parameters

in_ipython ( bool ) – Sets to True if IPython kernel is being used

print_profile_summary ( in_ipython = None )

Prints profiling information about the last pipeline run.

Parameters

in_ipython ( bool ) – Sets to True if IPython kernel is being used

print_summary ( in_ipython = None )

Prints information about the last fit() call.

Parameters

in_ipython ( bool ) – Sets to True if IPython kernel is being used

print_times ( in_ipython = None )

Prints timing and speedup information about the last fit() call.

Parameters

in_ipython ( bool ) – Sets to True if IPython kernel is being used

print_trials ( max_rows = None , sort_column = 'Mean Validation Score' , in_ipython = None )

Prints all trials executed by the AutoML Pipeline in the last fit() call.

Parameters
  • max_rows ( int ) – Number of trials to print. Pass in None to print all trials

  • sort_column ( str ) – Column to sort results by. Must be one of [‘Algorithm’, ‘#Samples’, ‘#Features’, ‘Mean Validation Score’, ‘Hyperparameters’, ‘All Validation Scores’, ‘CPU Time’]

  • in_ipython ( bool ) – Sets to True if IPython kernel is being used

refit ( X = None , y = None , X_valid = None , y_valid = None , cv = 'auto' )

This method is used to refit previously tuned AutoML Pipeline with new data. Pipeline stages are not re-run on the new datasets. All settings and parameters from Model Selection, Feature Selection, Model Tune are re-used. fit() must have been called before calling this method. If validation set is provided, it will be concatenated with training set before doing the refit.

Parameters
  • X ( pandas.DataFrame ) – Training dataset features. Optional for forecasting tasks.

  • y ( pandas.DataFrame , pandas.Series , optional ) – Training dataset target. Optional for semi-supervised tasks, like anomaly detection.

  • X_valid ( pandas.DataFrame , optional ) – Validation dataset features

  • y_valid ( pandas.DataFrame , pandas.Series , optional ) – Validation dataset target

  • cv ( auto , int, cross-validation generator or an iterable, optional) –

    Determines the cross-validation splitting strategy. Used for ensemble generation. Possible inputs for cv are:

    • None, to use X_valid and y_valid for validation

    • auto : 5 folds if number of instances < 1M, disable cv-folds otherwise

    • integer, to specify the number of folds in a (Stratified)KFold ,

    • An iterable yielding (train, test) splits as arrays of indices.

    For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.

Returns

self

Return type

object

score ( X , y )

Score of this pipeline for a given set of features (X) and labels (y). If inferred_score_metric has multiple score metrics, the first score metric would be calculated. :param X: Training dataset features :type X: pandas.DataFrame :param y: Training dataset target :type y: pandas.DataFrame

Returns

score – Score of self.predict(X) wrt. y.

Return type

float

to_onnx ( X , y )

Serializes an AutoML estimator to the ONNX format. Only requires one sample from the training or test set as input. This sample is used to infer the final types and shapes

Parameters
Returns

An ONNX model

Return type

ModelProto

train ( X = None , y = None , X_valid = None , y_valid = None , cv = 'auto' , col_types = None , time_budget = 0 , contamination = None )

Automatically identifies the most relevant features, model and hyperparameters for this given set of features (X) and target (y). Does not conduct final model fit. If the latter is desired, use fit().

Parameters
  • X ( pandas.DataFrame ) – Training dataset features. Optional for forecasting task.

  • y ( pandas.DataFrame , pandas.Series , optional ) – Training dataset target. Optional for semi-supervised tasks, like anomaly detection.

  • X_valid ( pandas.DataFrame , optional ) – Validation dataset features

  • y_valid ( pandas.DataFrame , pandas.Series , optional ) – Validation dataset target

  • cv ( auto , int, cross-validation generator or an iterable, optional) –

    Determines the cross-validation splitting strategy. Possible inputs for cv are:

    • None, to use X_valid and y_valid for validation

    • auto : 5 folds if number of instances < 1M, disable cv-folds otherwise

    • integer, to specify the number of folds in a (Stratified)KFold ,

    • An iterable yielding (train, test) splits as arrays of indices.

    For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.

  • col_types ( list of strings ) – List of length X.shape[1] with string values indicating type of features. Supported types are: [‘categorical’, ‘numerical’, ‘text’. ‘datetime’, ‘timedelta’] Note: Datetime support is in experimental stage

  • time_budget ( float , optional ) –

    Time budget in seconds.

    • 0 for unconstrained time budget: best effort mode is enabled and optimization continues until convergence.

    (default: 0)

  • contamination ( float , None , optional ) – Fraction of training dataset corresponding to anomalies (between 0.0 and 0.5). Should only be set for supervised anomaly detection (y_valid is required). Should be set to None for unsupervised anomaly detection (when using the unsupervised metrics). (default: None)

Returns

self

Return type

object

transform ( X , y )

Applies automatic preprocessing to a given set of features (X) and labels (y).

Parameters
Returns

  • X ( pandas.DataFrame ) – Transformed dataset features

  • y ( pandas.DataFrame ) – Transformed dataset target

ModelTune

class automl. ModelTune ( task = 'classification' , score_metric = None , random_state = 7 )

Bases: automl.interface.base_pipeline_stage.BasePipelineStage

Automatic Model Tuning object, uses a highly parallel, scalable and asynchronous gradient-based hyperparameter optimizer to quickly prune the hyperparameter search space and tune the given model object.

Parameters
  • task ( str , default=classification ) – Machine learning task, supported inputs: classification, regression, anomaly_detection, forecasting

  • score_metric ( str , callable , default=task-dependent ) –

    Score function (or loss function) with signature score_func(y, y_pred, **kwargs)

    Supported scoring metrics for specific tasks:

    Default score metrics for binary: neg_log_loss, multiclass: neg_log_loss, continuous: neg_mean_squared_error, continuous_forecast: neg_sym_mean_abs_percent_error, unsupervised: unsupervised_unify95

    binary – neg_log_loss, roc_auc, accuracy, f1, precision, recall, f1_micro, f1_macro, f1_weighted, f1_samples, recall_micro, recall_macro, recall_weighted, recall_samples, precision_micro, precision_macro, precision_weighted, precision_samples

    multiclass – neg_log_loss, recall_macro, accuracy, f1_micro, f1_macro, f1_weighted, f1_samples, recall_micro, recall_weighted, recall_samples, precision_micro, precision_macro, precision_weighted, precision_samples

    continuous – neg_mean_squared_error, r2, neg_mean_absolute_error, neg_mean_squared_log_error, neg_median_absolute_error

    continuous_forecast – neg_sym_mean_abs_percent_error, neg_root_mean_squared_percent_error, neg_mean_abs_scaled_error, neg_root_mean_squared_error, neg_mean_squared_error, neg_max_absolute_error, neg_mean_absolute_error, neg_max_abs_error, neg_mean_abs_error

    unsupervised – unsupervised_unify95, unsupervised_unify95_log_loss, unsupervised_calinski_harabasz, unsupervised_davies_bouldin, unsupervised_relative, unsupervised_additive, unsupervised_separation, unsupervised_inertia, unsupervised_ncompact, unsupervised_acompact, unsupervised_log_loss, unsupervised_mean95, unsupervised_n-1_experts__unify95_tuning, unsupervised_n-1_experts__unify95_log_loss_tuning

    More information on scoring metrics can be found here : Classification metrics , Regression metrics .

    Note: Scoring variations like recall_macro is equivalent to sklearn.metrics.recall_score(...,average="macro")

  • random_state ( int , default=7 ) – Random seed used by ModelTune.

selected_model_params_

Dictionary containing the optimal hyperparameters for the selected_model. Keys are hyperparameter names with their corresponding values.

Type

dict

tuning_trials_

Hyperparameter choices evaluated by tuning ranked in order of their achieved cross-validation scores. Each tuple is of the form (float, dict), the float is the cross-validation score of a corresponding dict which is a particular set of hyperparameters.

Type

list of tuples

at_summary

Dictionary containing the following stats: all trials, in the form of list of tuples, where each tuple is (score, hyperparameter, EvalResult (This is an internal class that holds all relevant results for each model evaluation)), total runtime of ModelTune, score of default run, default hyperparameter values, scoring metric, shape of train dataset, and shape of validation dataset (if it is available)

Type

dict

fit ( model , X , y , X_valid = None , y_valid = None , cv = 5 , param_space = None , col_types = None , contamination = None )

Automatically identifies the best model hyperparameters for this given set of features (X) and target (y).

Parameters
  • model ( str or sklearn-like model object ) – Model to tune on the given dataset, where it can be either one of the supported model names or sklearn-like object that implements at least the following methods: get_params , set_params , fit , predict and score . When providing an unsupported custom model, param_space argument should not be None . %s%s

  • X ( pandas.DataFrame ) – Training dataset features

  • y ( pandas.DataFrame , pandas.Series ) – Training dataset target

  • X_valid ( pandas.DataFrame ) – Validation dataset features

  • y_valid ( pandas.DataFrame , pandas.Series ) – Validation dataset target

  • cv ( int , cross-validation generator or an iterable , optional ) –

    Determines the cross-validation splitting strategy. Possible inputs for cv are:

    • None, to use X_valid and y_valid for validation

    • integer, to specify the number of folds in a (Stratified)KFold ,

    • a generator like a StratifiedKFold or KFold ,

    • An iterable yielding (train, test) splits as arrays of indices.

    For integer/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used.

  • param_space ( dict ) – The search ranges for each hyperparameter (default: none, uses predefined model specific hyperparameter search space). Example param_space input for RandomForest algorithm tuning: {{ ‘n_estimators’: {{ ‘range’: [5, 500], ‘type’: ‘discrete’}}, ‘max_features’: {{ ‘range’: [0.01, 0.5], ‘type’: ‘continuous’}}, ‘class_weight’: {{ ‘range’: [‘balanced’, ‘balanced_subsample’], ‘type’: ‘categorical’}}, }}

  • col_types ( list ) – List of string identifying type of features. Supported types are: [‘categorical’,’numerical’,datetime’,’timedelta’]

  • contamination ( float , optional ) – Fraction of training dataset corresponding to anomalies. contamination has to be between 0 and 0.5. Default value is 0.01.

Returns

self

Return type

object

predict ( X )

Predict labels for features (X).

Parameters

X ( pandas.DataFrame ) – Training dataset features, or Explanatory features if task is ‘forecasting’

Returns

y_pred – The predicted values.

Return type

array of shape [n_samples]

predict_proba ( X )

Probability estimates.

More information can be found here: Prediction Probabilities

Parameters

X ( pandas.DataFrame ) – Training dataset features

Returns

y_pred – The predicted probabilities.

Return type

array of shape = [n_samples, n_classes]

score ( X , y )

Score of this pipeline for a given set of features (X) and labels (y). If inferred_score_metric has multiple score metrics, the first score metric would be calculated. :param X: Training dataset features :type X: pandas.DataFrame :param y: Training dataset target :type y: pandas.DataFrame

Returns

score – Score of self.predict(X) wrt. y.

Return type

float

transform ( X , y )

Applies automatic preprocessing to a given set of features (X) and labels (y).

Parameters
Returns

  • X ( pandas.DataFrame ) – Transformed dataset features

  • y ( pandas.DataFrame ) – Transformed dataset target

Explainability

Explainers

MLExplainer

automl.interface.mlx. MLExplainer ( model , X , y = None , task = 'classification' , target_names = None , score_metric = None , col_types = None , selected_features = 'auto' )

A factory method that returns either an TabularExplainer or an TextExplainer , depending on the type of dataset.

Parameters
  • model ( model object ) – The model to explain. Must implement the predict method (and the predict_proba method, if the task is classification).

  • X ( pandas.DataFrame | list of str ) – A reference dataset drawn from the same distribution as the training dataset and the future test dataset. May be the training dataset. If the dataset type is tabular it must be a pandas DataFrame. If the dataset type is text then it can be a list of str or a pandas DataFrame with a single column and col_types must be [‘text’].

  • y ( pandas.Series | None ) – Dataset targets for X, if available.

  • task ( 'clasification' | 'regression' | 'anomaly_detection' ) – The type of machine learning task performed by the model.

  • target_names ( list of str | None ) – A list of names for the targets. If None and dataset_type=’tabular’, they will be inferred from y, if provided. Otherwise, target_names are required.

  • score_metric ( str | callable | None ) –

    The score_metric to compute explanations on.
    • If str, it is the name of the scoring metric.

    • If callable, it has to have the score_metric(model, X, y) signature.

    • If None, will default to the metric used to train the model argument.

  • col_types ( list of str | None ) – List of length X.shape[1] with string values indicating type of features. Supported types are: [‘categorical’, ‘numerical’, ‘text’]. If ‘text’, there should only be one column in X.

  • selected_features ( 'auto' | list of str | None ) – List of features/tokens that have been internally selected by the model. If the model is an AutoML pipeline and set to ‘auto’, the list will be automatically populated from the model. If None, all features/tokens will be used by the explainers.

TabularExplainer

class automl.mlx.interface. TabularExplainer ( model , X , y = None , task = 'classification' , target_names = None , scoring_metric = None , col_types = None , selected_features = 'auto' , ** kwargs )

Bases: automl.mlx.interface.base.BaseExplainer

Automatic ML model explanation object.

See MLExplainer for argument documentation.

aggregate ( explanations )

Returns an explanation that aggregates the list of pre-computed explanations.

Parameters

explanations ( list of automl.mlx.explanation.LFIExplanation ) – List of at least two explanations to be summarized

Returns

An Aggregate Local Feature Importance object (ALFI)

Return type

automl.mlx.explanation.aggregate_local_feature_importance.tabular_alfi

configure_explain_counterfactual ( strategy = 'dice_random' , dice_posthoc_sparsity_algorithm = 'binary' , dice_posthoc_sparsity_param = 0.1 , stopping_threshold = 0.5 , target_name = 'target' , target_precision = None , ** kwargs )

Configure the counterfactual explainer. If a parameter is not provided, the default value will be used. Notice that it doesn’t update the pervious provided configuration. A new CFExplainer with the current configuration will be initialized.

Parameters
  • strategy ( str , default='dice_random' ) – Name of the dice method to use for generating counterfactuals. Currently, only ‘dice_random’ is supported because it has the best performance among dice strategies.

  • dice_posthoc_sparsity_algorithm ( str , default='binray' ) – Perform either linear or binary search. Takes “linear” or “binary”.

  • stopping_threshold ( float between 0.5 and 1 , default=0.5 ) – Minimum threshold for counterfactuals target class probability. Notice: Dice has an internal error and it doesn’t support for positive stopping_threshold < 0.5 in the classification/anomaly_detection. However, it works well for regression.

  • dice_posthoc_sparsity_param ( float between 0 and 1 , default=0.1 ) – Parameter for the post-hoc operation on continuous features to enhance sparsity. For each feature, the dice_posthoc_sparsity_param quantile of Absolute Deviations is computed and if the difference betweeen query instance and counterfactual is less than this quantile, the posthoc sparsity algorithm is executed for the corresponding feature.

  • target_name ( str , default='target' ) – The label feature name.

  • target_precision ( int ) – The decimal precision of target

  • kwargs ( dict ) –

    Optional parameters passed to the DiCE Data interface.

    Accepted parameters are as following:
    permitted_range: dict, default=None

    Dictionary with feature names as keys and permitted range in list as values. Defaults to the range inferred from training data.

    continuous_features_precision: dict, default=None

    Dictionary with feature names as keys and precisions as values.

    data_name: str, default=None

    Dataset name

configure_explain_feature_dependence ( explanation_type = None , encoder_type = None , ** kwargs )

Configure the Feature Dependence explainer. This configuration will be used either to specify which FD explainer is selected or/and which encoder is used for ALE explanation.

Parameters
  • explanation_type ( 'pdp' | 'ale' | None ) – If ‘pdp’, explain_feature_dependence will use the partial dependence plot (PDP) explainer. If ‘ale’, the accumulated local effects (ALE) explainer will be used instead. If None, explain_feature_dependence will use by default ‘pdp’ if the explainer is not configured yet, otherwise it will use the most-recently provided.

  • encoder_type ( 'distance_similarity' | 'jamesstein' | None ) – The encoder type to be used for ALE to sort categorical features. If no encoder is specified (None), ALE explainer will use ‘distance_similarity’ if the explainer is not configured yet, otherwise it will use the most-recently used.

configure_explain_model ( ** kwargs )

Updates one or more parameters of the model explainer. If a parameter is not provided, the most-recently provided value from the last time configure_explain_model was called will be used. If no value has been previously provided, then the defaults will be used.

Parameters
  • explanation_type ( 'interventional' | 'observational' ) –

    If ‘interventional’ (default for classification & regression),

    then the explanation that is computed is as faithful to the model as possible. That is, features that are ignored by the model will not be considered important. This setting should be preferred if the primary goal is to learn about the machine learning model itself. Technically, this setting is called ‘interventional’, because the method will intervene on the data distribution when assessing the importance of features.

    If ‘observational’ (default for anomaly_detection),

    then the explanation that is computed is more faithful to the dataset than the model. For example, a feature that is ignored by the model may have a non-zero feature importance if it could have been used by some model to predict the target. This setting should be preferred if the model is merely a means to learn more about the relationships that exist within the data. Technically, this setting is called ‘observational’, because it observes the relationships in the data without breaking the existing data distribution.

  • tabulator_type ( 'permutation' , 'kernel_shap' , 'shapley' , 'shap_pi' ) –

    If ‘permutation’ (default),

    then the feature importance attributions will be calculated as in the classic feature permutation importance algorithm (assuming that explanation_type is set to ‘interventional’). Technically, this measures the importance of each feature independently from all others, and therefore it runs in linear time with respect to the number of features in the dataset.

    If ‘kernel_shap’,

    then the feature importance attributions will be calculated using an approximation of the Shapley value method. Until reaching the budget of the algorithm, it will look for more coalitions. The downside is not having confidence intervals.

    If ‘shapley’,

    then the feature importance attributions will be calculated using the popular game-theoretic Shapley value method. Technically, this measures the importance of each feature while includes the effect of all feature interactions. As a result, it runs in exponential time with respect to the number of features in the dataset.

    If ‘shap_pi’,

    then the feature importance attributions wil be calculated using an approximation of the Shapley value method. It will run in linear time; however, because of this, it may miss the effect of the interactions between some features and may therefore produce lower-quality results. Most likely, you will notice that this method yields larger confidence intervals than the other three.

  • sampling ( dict | None ) –

    If not None, the samples will be clustered or sampled according to the provided technique. sampling is a dictionary containing the information about which technique to use and the corresponding parameters. Format is described below. (Default = None)

    • ’technique’: Can be one of ‘kd-tree’, ‘dbscan’, ‘kmeans’, ‘auto’ or ‘random’.

      • If ‘kd_tree’, also requires:

        • ’n_clusters’: The number of clusters (leaves) in the tree.

        • ’n_samples’: The number of samples to return.

      • If ‘dbscan’, also requires:

        • ’eps’: Maximum distance between two samples to be considered in the same cluster

        • ’min_samples’: Minimum number of samples to include in each cluster

        • ’fast’: if True, the dataset is downsampled first then dbscan is applied to it. Suitable for large datasets.

      • If ‘kmeans’, also requires:

        • n_clusters: The number of clusters to form.

      • If ‘random’, also requires:

        • ’n_samples’: Number of samples to return

  • confidence_interval ( dict | None ) –

    If not None, the confidence intervals will be determined according to the provided technique. confidence_interval is a dictionary containing the information about which technique to use and the corresponding parameters. Format is described below. (Default = ‘student-t’)

    • ’technique’: Can be one of ‘student-t’, ‘bootstrap’,

      or ‘none’

      • If ‘bootstrap’, can also provide:

        • ’n_bootstrap’: int | ‘auto[n]’

          The number of bootstrap samples. Should be an integer greater than 10 or ‘auto[n]’, where n (if provided) determines how stable the bootstrap sampling procedure will be. The default value for n is 5, greater values increase the stability. Using ‘auto[n]’ provides minimum guarantees on the stability of the intervals regardless of the confidence level.

        • ’confidence_level’: float | int

          The confidence level of the confidence intervals. Must be in (0, 100).

        • ’n_bootstrap_data_pools’ int

          The number of bootstrap samples taken of the data set when calculating confidence intervals.

configure_explain_prediction ( ** kwargs )

Updates one or more parameters of the prediction explainer. If a parameter is not provided, the most-recently provided value from the last time configure_explain_prediction was called will be used. If no value has been previously provided, then the defaults will be used.

Parameters
  • explainer_type ( 'perturbation' | 'surrogate' ) –

    If ‘perturbation’ (default),

    then the explanation(s) will be computed by perturbing the features of the indicated data instance(s) and measuring the impact on the model predictions. Values for ‘explanation_type’, ‘tabulator_type’ and ‘confidence_interval’ will be ignored unless the ‘perturbation option is selected.

    If ‘surrogate’,

    then the LIME-style explanation(s) will be computed by fitting a surrogate model to the predictions of the original model in a small region around the indicated data instance(s) and measuring the importance of the features to the interpretable surrogate model. Only recommended for advanced users

  • explanation_type ( 'interventional' | 'observational' ) –

    Only used if explainer_type is ‘perturbation’.

    If ‘interventional’ (default for classification & regresion),

    then the explanation that is computed is as faithful to the model as possible. That is, features that are ignored by the model will not be considered important. This setting should be preferred if the primary goal is to learn about the machine learning model itself. Technically, this setting is called ‘interventional’, because the method will intervene on the data distribution when assessing the importance of features.

    If ‘observational’ (default for anomaly detection),

    then the explanation that is computed is more faithful to the dataset than the model. For example, a feature that is ignored by the model may have a non-zero feature importance if it could have been used by some model to predict the target. This setting should be preferred if the model is merely a means to learn more about the relationships that exist within the data. Technically, this setting is called ‘observational’, because it observes the relationships in the data without breaking the existing data distribution.

  • tabulator_type ( 'permutation' , 'kernel_shap' , 'shapley' , 'shap_pi' ) –

    Only used if explainer_type is ‘perturbation’.

    If ‘permutation’ (default),

    then the feature importance attributions will be calculated as in the classic feature permutation importance algorithm (assuming that explanation_type is set to ‘interventional’). Technically, this measures the importance of each feature independently from all others, and therefore it runs in linear time with respect to the number of features in the dataset.

    If ‘kernel_shap’,

    then the feature importance attributions will be calculated using an approximation of the Shapley value method. Until reaching the budget of the algorithm, it will look for more coalitions. The downside is not having confidence intervals.

    If ‘shapley’,

    then the feature importance attributions will be calculated using the popular game-theoretic Shapley value method. Technically, this measures the importance of each feature while includes the effect of all feature interactions. As a result, it runs in exponential time with respect to the number of features in the dataset.

    If ‘shap_pi’,

    then the feature importance attributions wil be calculated using an approximation of the Shapley value method. It will run in linear time; however, because of this, it may miss the effect of the interactions between some features and may therefore produce lower-quality results. Most likely, you will notice that this method yields larger confidence intervals than the other three.

  • method ( 'systematic' or 'lime' ) –

    Only used if explainer_type is ‘surrogate’.

    If ‘systematic’,

    Uses an Oracle AutoMLx prioprietary method that improves the quality of LIME explanations with a systematic sampling and a custom sampling weighting technique.

    If ‘lime’,

    Uses an in-house implementation of the traditional local model-agnostic explanations (LIME) algorithm.

  • sampling ( dict | None ) –

    If not None, the samples will be clustered or sampled according to the provided technique. sampling is a dictionary containing the information about which technique to use and the corresponding parameters. Format is described below. (Default = None)

    • ’technique’: Can be one of ‘kd-tree’, ‘dbscan’, ‘kmeans’,

      ’auto’ or ‘random’.

      • If ‘kd_tree’, also requires:

        • ’n_clusters’: The number of clusters (leaves) in the

          tree.

        • ’n_samples’: The number of samples to return.

      • If ‘dbscan’, also requires:

        • ’eps’: Maximum distance between two samples to be

          considered in the same cluster

        • ’min_samples’: Minimum number of samples to include

          in each cluster

        • ’fast’: if True, the dataset is downsampled first

          then dbscan is applied to it. Suitable for large datasets.

      • If ‘kmeans’, also requires:

        • n_clusters: The number of clusters to form.

      • If ‘random’, also requires:

        • ’n_samples’: Number of samples to return

  • confidence_interval ( dict | None ) –

    If not None, the confidence intervals will be determined according to the provided technique. confidence_interval is a dictionary containing the information about which technique to use and the corresponding parameters. Format is described below. (Default = ‘student-t’)

    • ’technique’: Can be one of ‘student-t’, ‘bootstrap’,

      or ‘none’

      • If ‘bootstrap’, can also provide:

        • ’n_bootstrap’: int | ‘auto[n]’

          The number of bootstrap samples. Should be an integer greater than 10 or ‘auto[n]’, where n (if provided) determines how stable the bootstrap sampling procedure will be. The default value for n is 5, greater values increase the stability. Using ‘auto[n]’ provides minimum guarantees on the stability of the intervals regardless of the confidence level.

        • ’confidence_level’: float | int

          The confidence level of the confidence intervals. Must be in (0, 100).

        • ’n_bootstrap_data_pools’ int

          The number of bootstrap samples taken of the data set when calculating confidence intervals.

explain_counterfactual ( X , n_counterfactuals = 1 , desired_pred = 'auto' , permitted_range = None , features_to_fix = [] , features_to_vary = None , random_seed = None , limit_steps_ls = 10000 )

Find counterfactuals by using a trained ML model predictions. The DiCE idea is to change features values randomly one by one until enough counterfactuals are found. Then make counterfactuals more sparse by doing a binray/linear search over changed features.

Parameters
  • X ( pandas.DataFrame , pandas.Series ) – Input dataset with one or more for which counterfactuals are to be generated.

  • n_counterfactuals ( int ( 1 , 2 , ... ) , default=1 ) – Total number of counterfactuals required.

  • desired_pred ( "auto" , array-like , int , tuple , default="auto" ) –

    The desired outcome class or range based on the setting.

    If classification:
    If an array-like:

    List of desired counterfactual class for each row of query instances.

    If an int:

    Desired counterfactual class for every query instances.

    If “auto”:

    Default value is “auto” which is the opposite outcome class of query_instances for binary classification. However, the desired_pred value is necessary for multi-class classification.

    If regression:
    If a list:

    List of tuples, where each tuple is the outcome range to generate counterfactuals in.

    If a tuple:

    the outcome range to generate all counterfactuals in.

    If “auto” or int:

    Raise an exception saying that this value is not valid for regression.

  • permitted_range ( dict , default=None ) – Dictionary with feature names as keys and permitted range in list as values. For numeric features, a list of two values specifying the permitted range (inclusive), and for categorical features, a list of permitted values (e.g. permitted_range={‘age’: [20, 30], ‘education’: [‘Doctorate’, ‘Prof-school’]). Defaults to the range inferred from training data. If None, uses the parameters initialized in data_interface.

  • features_to_fix ( list , default= [ ] ) – A list of feature names to fix. These are immutable features. If both features_to_vary and features_to_fix are None or both are not None, raise an error that just one of them should be None.

  • features_to_vary ( list , default=None ) – A list of feature names to vary.

  • random_seed ( int , default=None ) – Random seed for reproducibility.

  • limit_steps_ls ( int , default=10000 ) – Defines an upper limit for the linear search step in the dice_posthoc_sparsity_algorithm.

Returns

  • A list of CFExplanation object that contains the explanation

  • for each query_instance.

Raises

AutoMLxValueError:

  • if only one of the features_to_vary and features_to_fix parameters is not None. - if X length is zero.

explain_feature_dependence ( feature_names , feature_range = 'auto' , n_feature_values = 'auto' , X = None , y = None , sampling = None , confidence_interval = 'auto' )

Computes a Feature Dependence explanation for how the model predictions depend on the specified features.

If the explainer is configured with explanation_type = ‘pdp’, or it’s not configured yet, a Partial Dependence Plot (PDP) explanation is computed, and an individual conditional expectation explanation (ICE) in case only one feature is provided. Otherwise, compute Accumulated Local Effects (ALE) explanation.

Parameters
  • feature_names ( list | str | None ) – A list that contains the feature names for which the explanation is to be computed, or a single feature name. For PDP, if more than four features are provided, visualizations will not be available; however, a tabular form of the explanation will still be computed. For ALE, only two-features explanations are supported.

  • feature_range ( tuple of float | 'auto' ) – Determines the range of feature values evaluated in the explanation. If ‘auto’ is provided, use the default (0.05, 0.95) for PDP and (0, 1) for ALE The feature_range should be a sorted tuple of two floats, in [0, 1]. The range of values of the features used is determined by taking these percentiles of the marginal distribution(s) of the feature(s). (Default ‘auto’)

  • n_feature_values ( int | 'auto' ) – Max number of values to include between the feature range. If a categorical feature, selects all possible categorical values. If not an int, then it must be ‘auto’, in which case the number of values will be automatically chosen based on the number of features in order to maximize the interpretability of the explanations when plotted by show_in_notebook. (Default = ‘auto’)

  • X ( pandas.DataFrame | None ) – An alternate dataset for which the explanation should be computed. If not provided, the dataset used to initialize the explainer will be used instead. If provided, X must have similar columns to the original dataset that was provided. (Default = None)

  • sampling ( dict | None ) –

    If not None, the dataset will be downsampled using the indicated technique in the dictionary. Format is described below.

    • ’technique’: Can be one of ‘kdtree’, ‘random’ or ‘kmeans’.

    • If ‘kdtree’, also requires:
      • ’n_samples’: it will uniformly draw n_samples samples from the leaves of each tree.

    • If ‘random’, also requires:
      • ’n_samples’: Number of samples to return

    • If ‘kmeans’, also requires:
      • ’n_clusters’: Number of clusters to form

      • ’return_centroid’: A boolean flag whether to return cluster centroids

      • ’n_samples’: if return_centroid is False, it will uniformly draw n_samples samples from the clusters.

  • confidence_interval ( dict | 'auto' ) – If not ‘auto’, the confidence intervals will be determined according to the provided technique. confidence_interval is a dictionary containing the information about which technique to use and the corresponding parameters. If ‘auto’, use the default ‘student-t’ for PDP, and ‘none’ for ALE. (Default ‘auto’) For full description, see mlx.explainer.fd.FDExplainerBase.explain()

Returns

The feature dependence explanation.

Return type

automl.mlx.explanation.FDExplanation

explain_model ( n_iter = 'auto' )

Computes a global feature importance explanation for the model and dataset.

To configure how the explanation is computed, see configure_explain_model.

Parameters

n_iter ( 'auto' | int ) – The number of iterations used to evaluate the global importance of the model. Increasing n_iter will require a linear increase in compute; however, it will provide more accurate importance estimates, thereby decreasing the variance in repeated calls to explain_model with identical inputs and decreasing the size of the confidence intervals. If ‘auto’, it will be determined later on based on the type of explainer.

Returns

explanation – An explanation object that contains the global explanation.

Return type

automl.mlx.explanation.GFIExplanation

explain_prediction ( X , y = None , labels = 'auto' , n_iter = 'auto' )

Reports the local explanation for the given samples by providing contribution score per feature

Parameters
  • X ( pandas.DataFrame | pandas.Series ) – One or more dataset rows to be explained

  • y ( pandas.Series ) – Dataset target for the rows of X.

  • labels ( 'auto' | tuple of int | int ) – If ‘auto’, the explanation will be predicted for the label with the highest probability (for a classification model). Otherwise, the index or indices of specific labels can be passed to compute the explanation with respect to those labels instead.

  • n_iter ( 'auto' | int ) – The number of iterations used to evaluate the importance of each of the data instances. Increasing n_iter will require a linear increase in compute; however, it will provide more accurate importance estimates, thereby decreasing the variance in repeated calls to explain_prediction with identical inputs and decreasing the size of the confidence intervals. If ‘auto’, it will be determined later on based on the type of explainer.

Returns

explanations – A list of object that contain the local feature importance explanations, one for each instance in X.

Return type

list of automl.mlx.explanation.LFIExplanation

explore_whatif ( X , y , train = None , target_title = None , row_index = None , features = None , max_features = 32 , x_axis = None , y_axis = None , label = None , plot_type = 'scatter' , discretization = None )

Provides UI/API to explore how a sample prediction changes by modifying the sample feature values and the relationship between feature values and the model predictions.

Parameters
  • X ( pd.DataFrame ) – Data to explore

  • y ( list , pandas.DataFrame , or numpy.ndarray ) – Ground truth labels for X.

  • train ( pd.DataFrame | None ) – Data used to train the ML model. (Default = None)

  • target_title ( str | None ) – Title of the dataset’s target. (Default = None)

  • row_index ( int | None ) – Index of the sample to explore. If None, the first sample in X is selected. (Default = None)

  • features ( list [ str | int ] | None ) – Feature columns to explore. (Default = None)

  • max_features ( int ) – Maximum number of features to make available for modification. (Default = 32)

  • x_axis ( str | None ) – Feature column on x-axis. If None is provided, then the first column of X is selected. (Default = None)

  • y_axis ( str | None ) – Feature column or model prediction column on the y-axis. If None, model prediction column is selected. (Default = None)

  • label ( str | None ) – Target label to explore. (Default = None)

  • discretization ( str | None ) – Discretization method to apply to the x-axis if continuous. Can be chosen from [‘quartile’, ‘decile’, ‘percentile’]. If the axis’s cardinality > 100, and none of these method is selected, ‘decile’ is used. (Default = None)

  • plot_type ( str | None ) – Visualization plot type. Could be from [‘scatter’, ‘box’, ‘bar’] if classification or [‘scatter’, ‘box’] if regression. (Default = ‘scatter’)

Returns

UI entry point to the explore sample tool: Two widget instances, one contains select boxes, tables, and plots to explore the sample prediction. and the other one contains a menu and plotly plot to explore the relationship between feature values and the model predictions.

Return type

ipywidgets.widgets.VBox

TextExplainer

class automl.mlx.interface. TextExplainer ( model , X , y = None , task = 'classification' , scoring_metric = None , target_names = None , selected_tokens = None )

Bases: automl.mlx.interface.base.BaseExplainer

Automatic NLP ML model explanation object.

configure_explain_model ( ** kwargs )

Used to configure the model-level explainer’s parameters to values other than their defaults.

Parameters
  • replacement ( str | None ) – The token to use when replacing tokens in the dataset. Usually this is a token that has never been seen before by the model, e.g., ‘UNTK’. If None, un-important tokens from the dataset will be automatically determined. (default = None)

  • n_tokens ( int ) – The number of tokens to evaluate in depth. A heuristic procedure is used to identify, predict and rank which tokens are most likely to be important. From those, only the top n_tokens tokens will be evaluated in depth. (default = 60)

  • n_iter ( int ) – The number of iterations used to evaluate the importance of each of the tokens. Increasing n_iter will require a linear increase in compute; however, it will provide more accurate importance estimates, thereby decreasing the variance in repeated call to explain_model with identical inputs and decreasing the size of the confidence intervals. (default = 3)

configure_explain_prediction ( explainer_type = None , ** kwargs )

Updates one or more parameters of the prediction explainer.

Parameters

explainer_type ( 'surrogate' | None ) –

If None,

Does not modify the currently configured explainer.

If ‘surrogate’,

then the LIME-style explanation(s) will be computed by fitting a surrogate model to the predictions of the original model in a small region around the indicated data instance(s) and measuring the importance of the features to the interpretable surrogate model.

explain_model ( X = None , y = None , target = None )

Identifies what tokens are most important to the model using the Text Perturbation Importance explainer.

Parameters
  • X ( list of str | pandas.DataFrame ) – The dataset for which the explanations are computed.

  • y ( numpy ndarray | None ) – Ground truth target values for X (default = None). If None, unsupervised TextPI will be activated. If X is None, this input will be ignored and the computation will be based on the dataset provided when the explainer was initialized.

  • target ( int | None ) – Indicates the target index to be explained (default = None).

explain_prediction ( X , y = None , labels = 'auto' )

Reports the local explanation for the given samples by providing contribution score per token

Parameters
  • X ( pandas.DataFrame | pandas.Series ) – One or more dataset rows to be explained

  • y ( pandas.Series ) – Dataset target for the rows of X.

  • labels ( 'auto' | tuple of int | int ) – If ‘auto’, the explanation will be predicted for the label with the highest probability (for a classification model). Otherwise, the index or indices of specific labels can be passed to compute the explanation with respect to those labels instead.

Returns

explanations – A list of object that contain the local feature importance explanations, one for each instance in X.

Return type

list of automl.mlx.explanation.LFIExplanation

Explaination Objects

BaseLFIExplanation

class automl.mlx.explanation. BaseLFIExplanation ( explanation , sample , inference_time = None , task = 'classification' , explanation_type = 'tabular' , target_names = None , y_prediction = None )

Bases: automl.mlx.explanation.base.BaseExplanation

Generic wrapper class for local feature importance based explanations (e.g., LIME, Systematic local explainer, or SHAP).

show_in_notebook ( label = 'auto' )

Return the explanation as a plotly graph object figure for the specified target label.

Parameters

label ( int | 'auto' | None ) – Label index to visualize. If ‘auto’ and the model is either classification or anomaly detection, then the label that was predicted by the model is used. If None, label 0 is used.

Returns

The explanation as a dataframe.

Return type

pd.DataFrame

to_dataframe ( labels = None )

Return the explanation in dataframe format for the specified labels. There will be at least three columns “Feature”, “Attribution”, and “Target”, but there may also be “Upper Bound” and “Lower Bound”, which corresponds to the confidence intervals for the attributions, if they are calculated by the given method.

Parameters

labels ( tuple , list , int ) – Label indices to include. If None, all of the labels that the explanation was generated for will be included. (Default = None)

Returns

The explanation as a dataframe.

Return type

pd.DataFrame

FDExplanation

class automl.mlx.explanation. FDExplanation ( total_preds , mean_preds , std_preds , mean_preds_lower , mean_preds_upper , partial_feature_values , samples_per_feature , feature_names , target_names , is_categorical_feature , mode = 'classification' , explanation_type = 'pdp' , feature_distribution = None , feature_distribution_percentage_column = None , feature_priority = None , feature_correlations = None )

Bases: automl.mlx.explanation.base.BaseExplanation

Feature Dependence Explanation, that is, PDP, ALE and ICE. PDP supports N-feature partial dependence, ALE supports two-feature and ICE supports only single feature. ICE is optional, and it can be computed only alongside PDP for a single feature.

Parameters
  • total_preds ( dict of Numpy arrays ) – For each label, contains an array of all predicted values for each partial feature value.

  • mean_preds ( list of float ) – List of mean prediction values from the model.

  • std_preds ( list of float ) – List of sandard deviation of the prediction values from the model.

  • partial_feature_values ( dict of list of int ) –

    Dictionary containing:

    • (feature_name, list of evaluated values for this feature). The values from all features at the same index is the complete partial value used for this explanation. If a categorical feature, this is the actual feature names, not label encoded.

  • samples_per_feature ( int ) – List containing the different feature values tried for the explanation.

  • feature_names ( list of str ) – List of feature names used in the explanation,

  • target_names ( list of str ) – List of target names predicted in this PDP. For N-feature PDP, this must only be a single target name.

  • is_categorical_feature ( list of bool ) – List of boolean values to specify if the corresponding features are categorical or not.

  • mode ( str ) – String representing the ML task (‘classification’, ‘regression’ or ‘anomaly_detection’)

  • explanation_type ( str ) – ‘pdp’ or ‘ice’

  • feature_distribution ( Pandas.DataFrame ) – A histogram of the training data distribution.

  • feature_distribution_percentage_column ( str ) – The name of the column that contains the percentage of the data for the buckets in the feature_distribution histogram.

  • feature_priority ( list of int ) – A list of the feature indexes in the order in which they should be prioritized when plotting. Must match the order used when the histogram feature_distribution was created.

  • feature_correlations ( dict ) – Dictionary of features correlated with the features being evaluated.

Notes

If feature A and feature B are being explained, samples_per_feature might look like:

  • feature A: samples_per_feature[0] = [0, 1, 2, 3]

  • feature B: samples_per_feature[1] = [‘X’, ‘Y’]

partial_feature_values would be the cross-product:

  • partial_feature_values[‘A’] = [0, 0, 1, 1, 2, 2, 3, 3]

  • partial_feature_values[‘B’] = [‘X’, ‘Y’, ‘X’, ‘Y’, ‘X’, ‘Y’, ‘X’, ‘Y’,]

and mean_preds and std_preds contain the corresponding marginalized predicted values from the black-box model for each index of partial_feature_values.

show_in_notebook ( ice = False , labels = (0,) , prefer_widescreen = True , show_distribution = True , clip_distribution = True , force_heatmap = False , centered = False , show_median = True , sampling = {'n_clusters': 50, 'n_samples': 50, 'technique': 'kdtree'} )

Creates accumulated local effects (ALE), partial dependence plot (PDP) and individual conditional expectation (ICE) visualizations for the explanation.

An AutoMLxRuntimeError is raised if trying to visualize a PDP with more than four features, an ICE explanation with more than one feature, or an ALE with two categorical features or with more than 2 features.

Parameters
  • ice ( bool ) –

    Determines whether or not an ICE plot or and PD plot is returned. (Default = False) if ice == False:

    Plots a partial dependence explanation for up to four feature explanations

    1. feature: Generates a line graph or bar chart over the distribution of feature values evaluated

    2. features: Depending on the cardinality of the feature grid, either generates a heat map or a colored line/bar chart over the distribution of both feature values evaluated

    3. features: Uses the same encoding strategy as with 2 features; however, the third feature is encoded by plotting multiple small versions of the plot that are horizontally or vertically aligned (using row- or column-facetting) – one for plot for each value of the third feature in the grid.

    4. features: Uses the same encoding strategy as with 2 features; however, the third and fourth features are encoded by plotting multiple small versions of the plot that are both horizontally and vertically algined in a grid (using row-and column-facetting) – one plot for each unique combination of values for the third and fourth features.

    elif ice == True:

    Plots an ICE plot:

    • Numerical features: line chart

    • Categorical features: violin plot

  • labels ( tuple of int | list of int | int ) – Index(ices) of the labels (targets) to visualize. (Default = 0)

  • prefer_widescreen ( bool ) – If True, the shape of the returned figure will tend to be wider than it is tall when using row-or column-facetting for 3- and 4-feature PDPs. (Default = True)

  • show_distribution ( bool ) – If True, a histogram of the features’ value distributions (from the provided dataset) will be shown along the corresponding axis. When plotting heatmaps, the marginal distributions of the features on the x-and y-axes will be shown (conditioned on the values of any features encoded using row-or column-facets). In all other cases joint feature distributions will be displayed. (Default = True)

  • clip_distribution ( bool ) – If True, then portions of the feature distributions that extend beyond the domain of the feature value grid will be clipped (although they may still be viewed by zooming out). (Default = True)

  • force_heatmap ( bool ) – If True, and a PDP with more than 1 feature is computed, this will force a heatmap plot. If False, a heatmap is only chosen for high-cardinality data. (Default = False)

  • centered ( bool ) – If true, ICE plots will be centered based on the first value of each sample (i.e., all values are subtracted from the first value). (Default = False)

  • show_median ( bool ) – If true, a median line is included in the ICE explanation plot. (Default = True)

  • sampling ( dict | None ) – For all datasets of non-trivial size, plotting all of the data instances in an ICE plot produces an un-interpretable explanation due to overcrowding. Plotting too many lines at once also requires substantial time to render the figure. Therefore, by default we use a space-filling sampling technique to sample 50 random instances to plot. However, this can be configured to use any valid sampling strategy. See automl.mlx.sample_cluster.create_down_sampler for valid options. (Default = {‘technique: ‘kdtree’, ‘n_samples’: 50})

Returns

Plotly figure object containing a line chart, bar chart, heat map, or violin plot for this feature dependence explanation.

Return type

plotly.graph_object.figure

to_dataframe ( ice = False , show_median = True , centered = True , sampling = {'n_clusters': 50, 'n_samples': 100, 'technique': 'kdtree'} )

Returns a pandas DataFrame representation of the PDP, ALE or ICE explanation from this FDExplanation object. ICE is optional, and it can be set to True only if a single-feature PDP was computed.

Parameters
  • ice ( bool ) –

    If ice == False, the columns contain:
    • Each of the feature names evaluated in this PDP/ALE.

    • The corresponding mean prediction from the ML model for the given feature values for each target (“Mean”).

    • The corresponding standard deviation of the predictions from the ML model for the given feature values (“Standard Deviation”) – only applies for PDPs.

    • The 95% confidence interval lower bound for the prediction from the ML model for the given feature values (“Lower Bound”).

    • The 95% confidence interval upper bound for the prediction from the ML model for the given feature values for each target (“Upper Bound”).

    • The name of the current target (“Target”)

    If mode == True, the columns contain:
    • Each of the feature names evaluated in this ICE explanation.

    • A column containing the names of the targets being predicted.

    • The index of the data instance explained in the original dataset.

    • The corresponding prediction from the ML model for the given feature values, target and data index.

  • show_median ( bool ) – Determines whether or not the median is included in the dataframe. Only used if ice == True. Adds an additional column to the dataframe that specifies whether or not the current row corresponds to a data instance (“datum”) or the median (“median”). The “Index” column will also contain -1 for all occurences of the median.

  • centered ( bool ) – Determines whether or not the ICE explanation is centered. Only used if ice == True.

  • sampling ( dict | None ) – For all datasets of non-trivial size, plotting all of the data instances in an ICE plot produces an un-interpretable explanation due to overcrowding. Plotting too many lines at once also requires substantial time to render the figure. Therefore, by default we use a space-filling sampling technique to sample 100 random instances to plot. However, this can be configured to use any valid sampling strategy. See automl.mlx.sample_cluster.create_down_sampler for valid options.

Returns

Pandas DataFrame representation of the PDP/ICE or ALE explanation.

Return type

pandas.DataFrame

GFIExplanation

class automl.mlx.explanation. GFIExplanation ( feature_names = None , explanations = None , scoring_metric_name = None )

Bases: automl.mlx.explanation.base.BaseExplanation

Generic wrapper class for global explanation models (e.g., PermutationImportance).

Parameters
  • feature_names ( list of str ) – List of feature names (e.g., [‘A’, ‘B’, ‘C’]).

  • explanations ( list of dict ) –

    List (features within an explanation) of Dictionaries (feature explanation). Explanations are in the form {‘feature’: <feat_name>, ‘attribution’: <feat_importance>}. Example:

    [{‘feature’: ‘B’, ‘attribution’: 0.6’, ‘std’: 0.4}, {‘feature’: ‘A’, ‘attribution’: 0.25’, ‘std’: 0.9}, {‘feature’: ‘C’, ‘attribution’: 0.15’, ‘std’: 0.7}]

  • scoring_metric_name ( str ) – The name of the scoring metric used to evaluate the features.

show_in_notebook ( n_features = None , mode = 'bar' , box_points = 'suspectedoutliers' )

Generates a visualization for this global perturbation-based feature attribution explanation object.

Parameters
  • n_features ( int , None ) – If n_features is not None, only show the top n_features most important features.

  • mode ( str ) –

    Visualization mode. (Default value = ‘bar’) Can be one of:

    • ’bar’: Returns a plotly figure object that visualizes the feature attributions using a bar chart. Each bar represents the average feature attribution from each iteration. If available, confidence intervals for the mean will be included in the plot. (default)

    • ’box_plot’: Returns a plotly figure object that visualizes the feature attributions using a box plot of the raw feature attributions from each iteration of the algorithm. The box_points parameter can be used to further configure the visualization of the data.

  • box_points ( str ) –

    Sets the type of BoxPlot (default = ‘suspectedoutliers’)

    • ’suspectedoutliers’: Only shows the suspected anomalies. (default)

    • ’outliers’: Shows all the outliers.

    • ’all’: Shows all the points.

    Only used if mode = ‘box_plot’.

Returns

A figure containing a visualization of the explanation.

Return type

plotly.graph_objects.Figure

to_dataframe ( n_features = None , mode = 'normal' )

Return a representation of the explanation as a dataframe. If n_features is not None, return only the top n_features most important features.

Parameters
  • n_features ( int | None ) – If n_features is not None, returns only the top n_features most important features.

  • mode ( 'normal' | 'detailed' ) – If mode == ‘detailed’ then the dataframe contains the feature attributions from each individual iteration. Otherwise it contains the mean feature attributions and their corresponding upper and lower bounds.

Returns

explanation – The explanation as a dataframe.

Return type

pandas.DataFrame

GTIExplanation

class automl.mlx.explanation. GTIExplanation ( tokens = None , explanations = None , target = None , target_names = None )

Bases: automl.mlx.explanation.base.BaseExplanation

Generic wrapper class for text global explanation models (e.g., TextPerturbationImportance).

Parameters
  • tokens ( list of str ) – List of token names (e.g., [‘A..’, ‘B..’, ‘C..’]).

  • explanations ( list of dict ) –

    List (tokens within an explanation) of Dictionaries (token explanation). Explanations are in the form:

    {‘token’: <token_value>, ‘attribution’: <token_importance>, ‘std’: <importance_standard_deviation>, ‘flat_attributions’: <token_importance_per_iteration>, ‘target_impact_rate’: <target_based_importance>, ‘target_coverage_rate’: <target_coverage_rate_of_token>, ‘coverage_rate’: <coverage_rate_of_token>, }

    Example:

    [{‘token’: ‘B’, ‘attribution’: 0.6’, ‘std’: 0.4, ‘flat_attributions’: [0.5, 0.7, 0.6], ‘target_impact_rate’: -0.2, ‘target_coverage_rate’:0.08 , ‘coverage_rate’:0.1, }, {‘token’: ‘A’, ‘attribution’: 0.4’, ‘std’: 0.2, ‘flat_attributions’: [0.6, 0.35, 0.35], ‘target_impact_rate’: 0.3, ‘target_coverage_rate’:0.1 , ‘coverage_rate’:0.25, }, ]

  • target ( int ) – Indicates the target index to be explained (Default = None).

  • target_names ( list of str or int or None ) – List of target names corresponding to the output targets of the black box model (Default = None).

show_in_notebook ( n_tokens = None )

Generate a model-level explanation visualization for this explanation object.

Parameters

n_tokens ( int or None ) – Top-k tokens to show.

Returns

A figure that shows the relative importance of the top n_tokens tokens. If the explanation was computed with more than one iteration, the figure will include 95% confidence intervals for the estimates of the tokens’ importance.

Return type

plotly.graph_objs.Figure

to_dataframe ( n_tokens = None )

Return a representation of the explanation as a dataframe. If n_tokens is not None, returns only the top n_tokens most important tokens.

Parameters

n_tokens ( int | None ) – If n_tokens is not None, returns only the top n_tokens most important tokens.

Returns

explanation – The explanation as a dataframe.

Return type

oandas.DataFrame