API Reference

Documentation for the interpretableai package

Index

Setup

installFunction
install(**kwargs)

Install Julia packages required for interpretableai.iai.

This function must be called once after the package is installed to configure the connection between Python and Julia.

Parameters

Refer to the installation instructions for information on any additional parameters that may be required.

install_juliaFunction
install_julia(**kwargs)

Download and install Julia automatically.

Parameters

  • prefix: (string, optional) The directory where Julia will be installed. Defaults to a location determined by appdirs.user_data_dir.
install_system_imageFunction
install_system_image(**kwargs)

Download and install the IAI system image automatically.

Parameters

  • version: (string, optional) The version of the IAI system image to install (e.g. '2.1.0'). Defaults to 'latest', which will install the most recent release.
  • replace_default: (bool) Whether to replace the default Julia system image with the downloaded IAI system image. Defaults to False.
  • prefix: (string, optional) The directory where Julia will be installed. Defaults to a location determined by appdirs.user_data_dir.
get_machine_idFunction
iai.get_machine_id()

Return the machine ID for the current computer.

General Utilities

read_jsonFunction
iai.read_json(filename)

Read in a learner or grid saved in JSON format from filename.

Julia Equivalent: IAI.read_json

Data Preparation

MixedDataType
iai.MixedData(values, ordinal_levels=None)

Represents a mixed data feature

MixedData features can represent a feature with either numeric/categoric or ordinal/categoric values.

Parameters

  • values: (list-like) The values of the mixed feature. In a numeric/categoric mix, all numeric elements will be treated as numeric and all remaining elements as categoric. In an ordinal/categoric mix, all elements belonging to the ordinal_levels will be treated as ordinal, and all remaining elements as categoric.
  • ordinal_levels: (Index-like, optional) If not supplied, the feature is treated as a numeric/categoric mix. If supplied, these are the ordered levels of the ordinal values in the ordinal/categoric mix.
split_dataFunction
iai.split_data(task, X, *y, **kwargs)

Split the data (X and y) into a tuple of training and testing data, (X_train, y_train), (X_test, y_test), for a problem of type task.

Julia Equivalent: IAI.split_data

Learners

Learner

LearnerType

Abstract type encompassing all learners

fitMethod
lnr.fit(X, *y, sample_weight=None)

Fit a model using the parameters in learner and the data X and y.

Julia Equivalent: IAI.fit!

Parameters

Refer to the documentation on data preparation for information on how to format and supply the data.

cloneMethod
lnr.clone()

Return an unfitted copy of the learner with the same parameters.

Julia Equivalent: IAI.clone

write_jsonMethod
lnr.write_json(filename, **kwargs)

Write learner or grid to filename in JSON format.

Julia Equivalent: IAI.write_json

SupervisedLearner

SupervisedLearnerType

Abstract type encompassing all learners for supervised tasks

predictMethod
lnr.predict(X)

Return the predictions made by the learner for each point in the features X.

Julia Equivalent: IAI.predict

scoreMethod
lnr.score(X, *y, **kwargs)

Calculates the score for the learner on data X and y.

Julia Equivalent: IAI.score

variable_importanceMethod
lnr.variable_importance()

Generate a ranking of the variables in the learner according to their importance during training. The results are normalized so that they sum to one.

Julia Equivalent: IAI.variable_importance

get_features_usedFunction
lnr.get_features_used()

Return a list of feature names used by the learner.

Julia Equivalent: IAI.get_features_used

IAI Compatibility

Requires IAI version 2.2 or higher.

UnsupervisedLearner

ClassificationLearner

predict_probaMethod
lnr.predict_proba(X)

Return the probabilities of class membership predicted by the learner for each point in the features X.

Julia Equivalent: IAI.predict_proba

RegressionLearner

RegressionLearnerType

Abstract type encompassing all learners for regression tasks

SurvivalLearner

SurvivalLearnerType

Abstract type encompassing all learners for survival tasks

predict_hazardMethod
lnr.predict_hazard(X)

Return the fitted hazard coefficient estimate made by the learner for each point in the data X.

A higher hazard coefficient estimate corresponds to a smaller predicted survival time.

Julia Equivalent: IAI.predict_hazard

IAI Compatibility

Requires IAI version 1.2 or higher.

PrescriptionLearner

predict_outcomesMethod
lnr.predict_outcomes(X)

Return the the predicted outcome for each treatment made by the learner for each point in the features X.

Julia Equivalent: IAI.predict_outcomes

PolicyLearner

PolicyLearnerType

Abstract type encompassing all learners for policy tasks

predict_outcomesMethod
lnr.predict_outcomes(X, rewards)

Return the outcome from rewards for each point in the features X under the prescriptions made by the learner.

Julia Equivalent: IAI.predict_outcomes

IAI Compatibility

Requires IAI version 2.0 or higher.

predict_treatment_rankMethod
lnr.predict_treatment_rank(X)

Return the treatments in ranked order of effectiveness for each point in the features X as predicted by the learner.

Julia Equivalent: IAI.predict_treatment_rank

IAI Compatibility

Requires IAI version 2.1 or higher.

predict_treatment_outcomeMethod
lnr.predict_treatment_outcome(X)

Return the estimated quality of each treatment in the trained model of the learner for each point in the features X.

Julia Equivalent: IAI.predict_treatment_outcome

IAI Compatibility

Requires IAI version 2.1 or higher.

ImputationLearner

ImputationLearnerType
iai.ImputationLearner(method='opt_knn', **kwargs)

Abstract type containing all imputation learners.

Julia Equivalent: IAI.ImputationLearner

Parameters

Can be used to construct instances of imputation learners using the method keyword argument.

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

transformMethod
lnr.transform(X)

Impute missing values in X using the fitted imputation model in lnr.

Julia Equivalent: IAI.transform

Parameters

Refer to the documentation on data preparation for information on how to format and supply the data.

fit_transformMethod
lnr.fit_transform(X, **kwargs)

Fit the imputation learner using the training data X and impute the missing values in the training data.

Similar to calling fit followed by transform .

Julia Equivalent: IAI.fit_transform!

Parameters

Refer to the documentation on data preparation for information on how to format and supply the data.

GridSearch

GridSearchType
iai.GridSearch(lnr, params)

Controls grid search over parameter combinations in params for lnr.

Julia Equivalent: IAI.GridSearch

fit_cvMethod
grid.fit_cv(X, *y, **kwargs)

Fit a grid with data X and y using k-fold cross-validation.

Julia Equivalent: IAI.fit_cv!

Parameters

Refer to the documentation on data preparation for information on how to format and supply the data.

fit_transform_cvMethod
grid.fit_transform_cv(X, **kwargs)

For imputation learners, fit a grid with features X using k-fold cross-validation and impute missing values in X.

Julia Equivalent: IAI.fit_transform_cv!

Parameters

Refer to the documentation on data preparation for information on how to format and supply the data.

get_learnerMethod
grid.get_learner()

Return the fitted learner using the best parameter combination from the grid.

Julia Equivalent: IAI.get_learner

Tree Learners

TreeLearner

TreeLearnerType

Abstract type encompassing all tree-based learners.

applyMethod
lnr.apply(X)

Return the leaf index in the learner into which each point in the features X falls.

Julia Equivalent: IAI.apply

apply_nodesMethod
lnr.apply_nodes(X)

Return the indices of the points in the features X that fall into each node in the learner.

Julia Equivalent: IAI.apply_nodes

decision_pathMethod
lnr.decision_path(X)

Return a matrix where entry (i, j) is True if the ith point in the features X passes through the jth node in the learner.

Julia Equivalent: IAI.decision_path

print_pathMethod
lnr.print_path(X)

Print the decision path through the learner for each sample in the features X.

Julia Equivalent: IAI.print_path

get_depthMethod
lnr.get_depth(node_index)

Return the depth of node node_index in the trained learner.

Julia Equivalent: IAI.get_depth

get_parentMethod
lnr.get_parent(node_index)

Return the index of the parent node of node node_index in the trained learner.

Julia Equivalent: IAI.get_parent

get_lower_childMethod
lnr.get_lower_child(node_index)

Return the index of the lower child of node node_index in the trained learner.

Julia Equivalent: IAI.get_lower_child

get_upper_childMethod
lnr.get_upper_child(node_index)

Return the index of the upper child of node node_index in the trained learner.

Julia Equivalent: IAI.get_upper_child

get_num_samplesMethod
lnr.get_num_samples(node_index)

Return the number of training points contained in node node_index in the trained learner.

Julia Equivalent: IAI.get_num_samples

is_leafMethod
lnr.is_leaf(node_index)

Return True if node node_index in the trained learner is a leaf.

Julia Equivalent: IAI.is_leaf

get_split_weightsMethod
lnr.get_split_weights(node_index)

Return the weights for numeric and categoric features used in the hyperplane split at node node_index in the trained learner.

Julia Equivalent: IAI.get_split_weights

write_pngMethod
lnr.write_png(filename, **kwargs)

Write learner to filename as a PNG image.

Requires GraphViz be installed and on the system PATH.

Julia Equivalent: IAI.write_png

write_pdfMethod
lnr.write_pdf(filename, **kwargs)

Write learner to filename as a PDF image.

Requires GraphViz be installed and on the system PATH.

Julia Equivalent: IAI.write_pdf

IAI Compatibility

Requires IAI version 2.1 or higher.

write_svgMethod
lnr.write_svg(filename, **kwargs)

Write learner to filename as an SVG image.

Requires GraphViz be installed and on the system PATH.

Julia Equivalent: IAI.write_svg

IAI Compatibility

Requires IAI version 2.1 or higher.

write_htmlMethod
lnr.write_html(filename, **kwargs)

Write interactive browser visualization of learner to filename as HTML.

Julia Equivalent: IAI.write_html

ClassificationTreeLearner

set_thresholdMethod
lnr.set_threshold(label, threshold, simplify=False)

For a binary classification problem, update the the predicted labels in the leaves of the learner to predict label only if the predicted probability is at least threshold. If simplify is True, the tree will be simplified after all changes have been made.

Julia Equivalent: IAI.set_threshold!

RegressionTreeLearner

SurvivalTreeLearner

SurvivalTreeLearnerType

Abstract type encompassing all tree-based learners with survival leaves.

get_survival_hazardMethod
lnr.get_survival_hazard(node_index)

Return the predicted hazard ratio at node node_index in the trained learner.

Julia Equivalent: IAI.get_survival_hazard

IAI Compatibility

Requires IAI version 2.1 or higher.

PrescriptionTreeLearner

get_regression_weightsMethod
lnr.get_regression_weights(node_index, treatment)

Return the weights for each feature in the regression prediction for treatment at node node_index in the trained learner.

Julia Equivalent: IAI.get_regression_weights

PolicyTreeLearner

PolicyTreeLearnerType

Abstract type encompassing all tree-based learners with policy leaves.

get_policy_treatment_rankMethod
lnr.get_policy_treatment_rank(node_index)

Return the treatments ordered from most effective to least effective at node node_index in the trained learner.

Julia Equivalent: IAI.get_policy_treatment_rank

IAI Compatibility

Requires IAI version 2.0 or higher.

Tree learner visualization

write_htmlMethod
treeplot.write_html(filename, **kwargs)

Write interactive browser visualization to filename as HTML.

Julia Equivalent: IAI.write_html

MultiTreePlotType

Specify an interactive tree visualization of multiple tree learners

Julia Equivalent: IAI.MultiTreePlot

IAI Compatibility

Requires IAI version 1.1 or higher.


iai.MultiTreePlot(questions)

Constructs an interactive tree visualization using multiple tree learners from specified questions. Refer to the documentation on advanced tree visualization for more information.


iai.MultiTreePlot(grid)

Constructs an interactive tree visualization containing the final fitted learner from trained grid search as well as the learner found for each parameter combination.

MultiQuestionnaireType

Specify an interactive questionnaire of multiple tree learners

Julia Equivalent: IAI.MultiQuestionnaire

IAI Compatibility

Requires IAI version 1.1 or higher.


iai.MultiQuestionnaire(questions)

Constructs an interactive questionnaire using multiple tree learners from specified questions. Refer to the documentation on advanced tree visualization for more information.


iai.MultiQuestionnaire(grid)

Constructs an interactive questionnaire containing the final fitted learner from trained grid search as well as the learner found for each parameter combination.

Tree Stability

get_treeFunction
lnr.get_tree(index)

Return a copy of the learner that uses the tree at index rather than the tree with the best training objective.

Julia Equivalent: IAI.get_tree

IAI Compatibility

Requires IAI version 2.2 or higher.

Stability Analysis

StabilityAnalysisType

Conduct a stability analysis of the trees in a tree learner.

Refer to the documentation on tree stability for more information.

Julia Equivalent: IAI.StabilityAnalysis

IAI Compatibility

Requires IAI version 2.2 or higher.


iai.StabilityAnalysis(lnr)

Conduct a stability analysis of the trees in lnr, using similarity scores calculated during training


iai.StabilityAnalysis(lnr, X, y, criterion='default')

Conduct a stability analysis of the trees in lnr, using similarity scores calculated with the data X, y and criterion

get_stability_resultsFunction
stability.get_stability_results()

Return the trained trees in order of increasing objective value, along with their variable importance scores for each feature.

Julia Equivalent: IAI.get_stability_results

IAI Compatibility

Requires IAI version 2.2 or higher.

get_cluster_distancesFunction
stability.get_cluster_distances(num_trees)

Return the distances between the centroids of each pair of clusters, under the clustering of the best num_trees trees.

Julia Equivalent: IAI.get_cluster_distances

IAI Compatibility

Requires IAI version 2.2 or higher.

get_cluster_assignmentsFunction
stability.get_cluster_assignments(num_trees)

Return the indices of the trees assigned to each cluster, under the clustering of the best num_trees trees.

Julia Equivalent: IAI.get_cluster_assignments

IAI Compatibility

Requires IAI version 2.2 or higher.

get_cluster_detailsFunction
stability.get_cluster_details(num_trees)

Return the centroid information for each cluster, under the clustering of the best num_trees trees.

Julia Equivalent: IAI.get_cluster_details

IAI Compatibility

Requires IAI version 2.2 or higher.

plotMethod
stability.plot()

Plot the stability analysis results.

Returns a matplotlib.figure.Figure containing the plotted results.

In a Jupyter Notebook, the plot will be shown automatically. In a terminal, you can show the plot with stability.plot().show().

IAI Compatibility

Requires IAI version 2.2 or higher.

Similarity Comparison

variable_importance_similarityFunction

Calculate similarity between this learner and another tree learner using variable importance scores.

Julia Equivalent: IAI.variable_importance_similarity

IAI Compatibility

Requires IAI version 2.2 or higher.


lnr.variable_importance_similarity(new_lnr)

Calculate similarity scores between the final tree in this learner and all trees in new_lnr


lnr.variable_importance_similarity(new_lnr, X, y,

Calculate similarity scores between the final tree in this learner and all trees in new_lnr using the data X and y with criterion

SimilarityComparisonType
iai.SimilarityComparison(orig_lnr, new_lnr, deviations)

Conduct a similarity comparison between the final tree in orig_lnr and all trees in new_lnr to consider the tradeoff between training performance and similarity to the original tree as measured by deviations.

Refer to the documentation on tree stability for more information.

Julia Equivalent: IAI.SimilarityComparison

IAI Compatibility

Requires IAI version 2.2 or higher.

get_train_errorsFunction
lnr.get_train_errors()

Extract the training objective value for each candidate tree in the comparison, where a lower value indicates a better solution.

Julia Equivalent: IAI.get_train_errors

IAI Compatibility

Requires IAI version 2.2 or higher.

plotMethod
similarity.plot()

Plot the similarity comparison results.

Returns a matplotlib.figure.Figure containing the plotted results.

In a Jupyter Notebook, the plot will be shown automatically. In a terminal, you can show the plot with similarity.plot().show().

IAI Compatibility

Requires IAI version 2.2 or higher.

Optimal Trees

OptimalTreeClassifierType
iai.OptimalTreeClassifier(**kwargs)

Learner for training Optimal Classification Trees.

Julia Equivalent: IAI.OptimalTreeClassifier

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptimalTreeRegressorType
iai.OptimalTreeRegressor(**kwargs)

Learner for training Optimal Regression Trees.

Julia Equivalent: IAI.OptimalTreeRegressor

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptimalTreeSurvivalLearnerType
iai.OptimalTreeSurvivalLearner(**kwargs)

Learner for training Optimal Survival Trees.

Julia Equivalent: IAI.OptimalTreeSurvivalLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptimalTreePrescriptionMinimizerType
iai.OptimalTreePrescriptionMinimizer(**kwargs)

Learner for training Optimal Prescriptive Trees where the prescriptions should aim to minimize outcomes.

Julia Equivalent: IAI.OptimalTreePrescriptionMinimizer

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptimalTreePrescriptionMaximizerType
iai.OptimalTreePrescriptionMaximizer(**kwargs)

Learner for training Optimal Prescriptive Trees where the prescriptions should aim to maximize outcomes.

Julia Equivalent: IAI.OptimalTreePrescriptionMaximizer

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptimalTreePolicyMinimizerType
iai.OptimalTreePolicyMinimizer(**kwargs)

Learner for training Optimal Policy Trees where the policy should aim to minimize outcomes.

Julia Equivalent: IAI.OptimalTreePolicyMinimizer

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.0 or higher.

OptimalTreePolicyMaximizerType
iai.OptimalTreePolicyMaximizer(**kwargs)

Learner for training Optimal Policy Trees where the policy should aim to maximize outcomes.

Julia Equivalent: IAI.OptimalTreePolicyMaximizer

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.0 or higher.

OptImpute

imputeFunction
iai.impute(X, *args, **kwargs)

Impute the missing values in X using either a specified method or through grid search validation.

Julia Equivalent: IAI.impute

Parameters

Refer to the Julia documentation for available parameters.

impute_cvFunction
iai.impute_cv(X, *args, **kwargs)

Impute the missing values in X using cross validation.

Julia Equivalent: IAI.impute_cv

Parameters

Refer to the Julia documentation for available parameters.

OptKNNImputationLearnerType
iai.OptKNNImputationLearner(**kwargs)

Learner for conducting optimal k-NN imputation.

Julia Equivalent: IAI.OptKNNImputationLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptSVMImputationLearnerType
iai.OptSVMImputationLearner(**kwargs)

Learner for conducting optimal SVM imputation.

Julia Equivalent: IAI.OptSVMImputationLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

OptTreeImputationLearnerType
iai.OptTreeImputationLearner(**kwargs)

Learner for conducting optimal tree-based imputation.

Julia Equivalent: IAI.OptTreeImputationLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

SingleKNNImputationLearnerType
iai.SingleKNNImputationLearner(**kwargs)

Learner for conducting heuristic k-NN imputation.

Julia Equivalent: IAI.SingleKNNImputationLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

MeanImputationLearnerType
iai.MeanImputationLearner(**kwargs)

Learner for conducting mean imputation.

Julia Equivalent: IAI.MeanImputationLearnerer

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

RandImputationLearnerType
iai.RandImputationLearner(**kwargs)

Learner for conducting random imputation.

Julia Equivalent: IAI.RandImputationLearnerer

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

Optimal Feature Selection

OptimalFeatureSelectionClassifierType
iai.OptimalFeatureSelectionClassifier(**kwargs)

Learner for conducting Optimal Feature Selection on classification problems.

Julia Equivalent: IAI.OptimalFeatureSelectionClassifier

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 1.1 or higher.

OptimalFeatureSelectionRegressorType
iai.OptimalFeatureSelectionRegressor(**kwargs)

Learner for conducting Optimal Feature Selection on regression problems.

Julia Equivalent: IAI.OptimalFeatureSelectionRegressor

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 1.1 or higher.

get_prediction_weightsMethod
lnr.get_prediction_weights()

Return the weights for numeric and categoric features used for prediction in the trained learner.

Julia Equivalent: IAI.get_prediction_weights

IAI Compatibility

Requires IAI version 1.1 or higher.

plotMethod
grid.plot(type)

Plot the grid search results for Optimal Feature Selection learners.

Returns a matplotlib.figure.Figure containing the plotted results.

In a Jupyter Notebook, the plot will be shown automatically. In a terminal, you can show the plot with grid.plot().show().

Parameters

IAI Compatibility

Requires IAI version 2.2 or higher.

Reward Estimation

Categorical Treatments

fit_predictMethod

Fit a reward estimation model and return predicted counterfactual rewards for each observation along with the scores of the internal estimators during training.

Julia Equivalent: IAI.fit_predict!

IAI Compatibility

Requires IAI version 2.0 or higher.


lnr.fit_predict(X, treatments, outcomes)

For problems with classification or regression outcomes, fit reward estimation model on features X, treatments treatments, and outcomes outcomes and predict rewards for each observation.


lnr.fit_predict(X, treatments, deaths, times)

For problems with survival outcomes, fit reward estimation model on features X, treatments treatments, death indicator deaths and event times times and predict rewards for each observation.

predictMethod

Return counterfactual rewards estimated by the learner for each observation in the supplied data.

Julia Equivalent: IAI.predict

IAI Compatibility

Requires IAI version 2.0 or higher.


lnr.predict(X, treatments, outcomes)

For problems with classification or regression outcomes, predict rewards for each observation in the data given by X, treatments and outcomes. If using the direct method, treatments and outcomes can be omitted.


lnr.predict(X, treatments, deaths, times)

For problems with survival outcomes, predict rewards for each observation in the data given by X, treatments, deaths and times. If using the direct method, treatments, deaths and times can be omitted.

scoreMethod

Calculate the scores of the internal estimators in the learner on the supplied data.

Returns a dict with the following entries:

  • 'propensity': the score for the propensity estimator
  • ':outcome': a dict where the keys are the possible treatments, and the values are the scores of the outcome estimator corresponding to each treatment

Julia Equivalent: IAI.score

IAI Compatibility

Requires IAI version 2.1 or higher.


lnr.score(X, treatments, outcomes)

For problems with classification or regression outcomes, calculate the scores of the internal estimators using the data given by X, treatments and outcomes.


lnr.score(X, treatments, deaths, times)

For problems with survival outcomes, calculate the scores of the internal estimators using the data given by X, treatments, deaths and times.

CategoricalClassificationRewardEstimatorType
iai.CategoricalClassificationRewardEstimator(**kwargs)

Learner for reward estimation with categorical treatments and classification outcomes.

Julia Equivalent: IAI.CategoricalClassificationRewardEstimator

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

CategoricalRegressionRewardEstimatorType
iai.CategoricalRegressionRewardEstimator(**kwargs)

Learner for reward estimation with categorical treatments and regression outcomes.

Julia Equivalent: IAI.CategoricalRegressionRewardEstimator

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

CategoricalSurvivalRewardEstimatorType
iai.CategoricalSurvivalRewardEstimator(**kwargs)

Learner for reward estimation with categorical treatments and survival outcomes.

Julia Equivalent: IAI.CategoricalSurvivalRewardEstimator

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

EqualPropensityEstimatorType
iai.EqualPropensityEstimator(**kwargs)

Learner that estimates equal propensity for all treatments.

For use with data from randomized experiments where treatments are known to be randomly assigned.

Julia Equivalent: IAI.EqualPropensityEstimator

IAI Compatibility

Requires IAI version 2.1 or higher.

Numeric Treatments

fit_predictMethod

Fit a reward estimation model and return predicted counterfactual rewards for each observation under each treatment option in treatment_candidates, as well as the score of the internal outcome estimator.

Julia Equivalent: IAI.fit_predict!

IAI Compatibility

Requires IAI version 2.1 or higher.


lnr.fit_predict(X, treatments, outcomes, treatment_candidates)

For problems with classification or regression outcomes, fit reward estimation model on features X, treatments treatments, and outcomes outcomes and predict rewards for each observation under each treatment option in treatment_candidates.


lnr.fit_predict(X, treatments, deaths, times, treatment_candidates)

For problems with survival outcomes, fit reward estimation model on features X, treatments treatments, death indicator deaths and event times times and predict rewards for each observation under each treatment option in treatment_candidates.

predictMethod

Return counterfactual rewards estimated by the learner for each observation in the supplied data.

Julia Equivalent: IAI.predict

IAI Compatibility

Requires IAI version 2.1 or higher.


lnr.predict(X, treatments, outcomes)

IAI versions 2.2 and greater: For problems with classification or regression outcomes, predict rewards for each observation in the data given by X, treatments and outcomes. If using the direct method, treatments and outcomes can be omitted.


lnr.predict(X, treatments, deaths, times)

IAI versions 2.2 and greater: For problems with survival outcomes, predict rewards for each observation in the data given by X, treatments, deaths and times. If using the direct method, treatments, deaths and times can be omitted.


lnr.predict(X, treatments, outcomes, treatment_candidates)

IAI version 2.1: Predicted reward for each observation in the data given by X, treatments and outcomes under each treatment option in treatment_candidates. If using the direct method, treatments, deaths and times can be omitted.

scoreMethod

Calculate the scores of the internal estimator in the learner on the supplied data.

Julia Equivalent: IAI.score

On IAI versions 2.2 and greater, returns a dict with the following entries:

  • 'propensity': a dict where the keys are the treatment candidates, and the values are the scores of the propensity estimator corresponding to each candidate
  • ':outcome': a dict where the keys are the treatment candidates, and the values are the scores of the outcome estimator corresponding to each candidate

On IAI version 2.1, returns a float giving the score of the outcome estimator.

IAI Compatibility

Requires IAI version 2.1 or higher.


lnr.score(X, treatments, outcomes)

For problems with classification or regression outcomes, calculate the scores of the internal estimators using the data given by X, treatments and outcomes.


lnr.score(X, treatments, deaths, times)

For problems with survival outcomes, calculate the scores of the internal estimators using the data given by X, treatments, deaths and times.

NumericClassificationRewardEstimatorType
iai.NumericClassificationRewardEstimator(**kwargs)

Learner for reward estimation with numeric treatments and classification outcomes.

Julia Equivalent: IAI.NumericClassificationRewardEstimator

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

NumericRegressionRewardEstimatorType
iai.NumericRegressionRewardEstimator(**kwargs)

Learner for reward estimation with numeric treatments and regression outcomes.

Julia Equivalent: IAI.NumericRegressionRewardEstimator

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

NumericSurvivalRewardEstimatorType
iai.NumericSurvivalRewardEstimator(**kwargs)

Learner for reward estimation with numeric treatments and survival outcomes.

Julia Equivalent: IAI.NumericSurvivalRewardEstimator

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

get_estimation_densitiesFunction
lnr.get_estimation_densities()

Return the total kernel density surrounding each treatment candidate for the propensity/outcome estimation problems in the fitted learner.

Julia Equivalent: IAI.get_estimation_densities

IAI Compatibility

Requires IAI version 2.2 or higher.

tune_reward_kernel_bandwidthFunction
lnr.tune_reward_kernel_bandwidth(input_bandwidths)

Conduct the reward kernel bandwidth tuning procedure using the learner for each starting value in input_bandwidths and return the final tuned values.

Julia Equivalent: IAI.tune_reward_kernel_bandwidth

IAI Compatibility

Requires IAI version 2.2 or higher.

set_reward_kernel_bandwidthFunction
lnr.set_reward_kernel_bandwidth(bandwidth)

Save the new value of bandwidth as the reward kernel bandwidth inside the learner, and return new reward predictions generated using this bandwidth for the original data used to train the learner.

Julia Equivalent: IAI.set_reward_kernel_bandwidth!

IAI Compatibility

Requires IAI version 2.2 or higher.

all_treatment_combinationsFunction
iai.all_treatment_combinations(*args, **kwargs)

Return a pandas.DataFrame containing all treatment combinations of one or more treatment vectors, ready for use as treatment_candidates in fit_predict! or predict.

IAI Compatibility

Requires IAI version 2.1 or higher.

convert_treatments_to_numericFunction
iai.convert_treatments_to_numeric(treatments)

Convert treatments from symbol/string format into numeric values.

IAI Compatibility

Requires IAI version 2.1 or higher.

Heuristics

Random Forests

RandomForestClassifierType
iai.RandomForestClassifier(**kwargs)

Learner for training random forests for classification problems.

Julia Equivalent: IAI.RandomForestClassifier

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.1 or higher.

RandomForestRegressorType
iai.RandomForestRegressor(**kwargs)

Learner for training random forests for regression problems.

Julia Equivalent: IAI.RandomForestRegressor

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.1 or higher.

RandomForestSurvivalLearnerType
iai.RandomForestSurvivalLearner(**kwargs)

Learner for training random forests for survival problems.

Julia Equivalent: IAI.RandomForestSurvivalLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

XGBoost

XGBoostLearnerType

Abstract type encompassing all XGBoost learners.

XGBoostClassifierType
iai.XGBoostClassifier(**kwargs)

Learner for training XGBoost models for classification problems.

Julia Equivalent: IAI.XGBoostClassifier

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.1 or higher.

XGBoostRegressorType
iai.XGBoostRegressor(**kwargs)

Learner for training XGBoost models for regression problems.

Julia Equivalent: IAI.XGBoostRegressor

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.1 or higher.

XGBoostSurvivalLearnerType
iai.XGBoostSurvivalLearner(**kwargs)

Learner for training XGBoost models for survival problems.

Julia Equivalent: IAI.XGBoostSurvivalLearner

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.2 or higher.

predict_shapMethod
lnr.predict_shap(X)

Calculate SHAP values for all points in the features X using lnr.

Julia Equivalent: IAI.predict_shap

IAI Compatibility

Requires IAI version 2.2 or higher.

write_boosterMethod
lnr.write_booster(filename)

Write the internal booster saved in the learner to filename.

Julia Equivalent: IAI.write_booster

IAI Compatibility

Requires IAI version 2.1 or higher.

GLMNet

GLMNetLearnerType

Abstract type encompassing all GLMNet learners.

get_num_fitsMethod
lnr.get_num_fits()

Return the number of fits along the path in the trained learner.

Julia Equivalent: IAI.get_num_fits

IAI Compatibility

Requires IAI version 2.1 or higher.

get_prediction_weightsMethod

Return the weights for numeric and categoric features used for prediction in the trained learner.

Julia Equivalent: IAI.get_prediction_weights

IAI Compatibility

Requires IAI version 2.1 or higher.


lnr.get_prediction_weights()

Return the weights for each feature in the prediction made by the best fit on the path in the learner.


lnr.get_prediction_weights(fit_index)

Return the weights for each feature in the prediction made by the fit at fit_index on the path in the learner.

get_prediction_constantMethod

Return the constant term in the prediction in the trained learner.

Julia Equivalent: IAI.get_prediction_constant

IAI Compatibility

Requires IAI version 2.1 or higher.


lnr.get_prediction_constant()

Return the constant term in the prediction made by the best fit on the path in the learner.


lnr.get_prediction_constant(fit_index)

Return the constant term in the prediction made by the fit at fit_index on the path in the learner.

GLMNetCVRegressorType
iai.GLMNetCVRegressor(**kwargs)

Learner for training GLMNet models for regression problems with cross-validation.

Julia Equivalent: IAI.GLMNetCVRegressor

Parameters

Use keyword arguments to set parameters on the resulting learner. Refer to the Julia documentation for available parameters.

IAI Compatibility

Requires IAI version 2.1 or higher.

Miscellaneous Types

ROCCurve

ROCCurveType

Container for ROC curve information.

Julia Equivalent: IAI.ROCCurve


iai.ROCCurve(lnr, X, y)

Construct an ROCCurve using trained lnr on the features X and labels y.


iai.ROCCurve(probs, y, positive_label=positive_label)

Construct an ROCCurve using predicted probabilities probs and true labels y, with probabilities indicating chance of predicting positive_label.

get_dataMethod
curve.get_data()

Extract the underlying data from the curve as a dict with two keys:

  • coords: a dict for each point on the curve with the following keys:
    • 'fpr': false positive rate at the given threshold
    • 'tpr': true positive rate at the given threshold
    • 'threshold': the threshold
  • auc: the area-under-the-curve (AUC)

Julia Equivalent: IAI.get_roc_curve_data

IAI Compatibility

Requires IAI version 2.1 or higher.

plotMethod
curve.plot()

Plot the ROC curve using matplotlib.

Returns a matplotlib.figure.Figure containing the ROC curve.

In a Jupyter Notebook, the plot will be shown automatically. In a terminal, you can show the plot with curve.plot().show().

IAI Compatibility

Requires IAI version 2.1 or higher.

SurvivalCurve

SurvivalCurveType

Container for survival curve information.

Use curve[t] to get the survival probability prediction from curve at time t.

Julia Equivalent: IAI.SurvivalCurve

get_dataMethod
curve.get_data()

Extract the underlying data from the curve as a dict with two keys:

  • 'times': the time for each breakpoint on the curve
  • 'coefs': the probablility for each breakpoint on the curve

Julia Equivalent: IAI.get_survival_curve_data