robustx.generators package

Subpackages

Submodules

robustx.generators.CEGenerator module

class robustx.generators.CEGenerator.CEGenerator(ct, custom_distance_func=None)[source]

Bases: ABC

Abstract class for generating counterfactual explanations for a given task.

This class provides a framework for generating counterfactuals based on a distance function and a given task. It supports default distance functions such as Euclidean and Manhattan, and allows for custom distance functions.

_task

The task to solve.

Type:

Task

__customFunc

A custom distance function.

Type:

callable, optional

property custom_distance_func

Returns custom distance function passed at instantiation @return: distance Function, (DataFrame, DataFrame) -> Int

generate(instances, neg_value=0, column_name='target', **kwargs)[source]

Generates counterfactuals for a given DataFrame of instances.

@param instances: A DataFrame of instances for which you want to generate counterfactuals explanations. @param distance_func: The method to calculate the distance between two points. Options are ‘l1’ / ‘manhattan’, ‘l2’ / ‘euclidean’, and ‘custom’. @param column_name: The name of the target column. @param neg_value: The value considered negative in the target variable. @return: A DataFrame of the counterfactual explanations for the provided instances.

Return type:

DataFrame

generate_for_all(neg_value=0, column_name='target', **kwargs)[source]

Generates counterfactuals for all instances with a given negative value in their target column.

@param neg_value: The value in the target column which counts as a negative instance. @param column_name: The name of the target variable. @param distance_func: The method to calculate the distance between two points. Options are ‘l1’ / ‘manhattan’, ‘l2’ / ‘euclidean’, and ‘custom’. @return: A DataFrame of the counterfactuals for all negative values.

Return type:

DataFrame

generate_for_instance(instance, neg_value=0, column_name='target', **kwargs)[source]

Generates a counterfactual for a provided instance.

@param instance: The instance for which you would like to generate a counterfactual. @param distance_func: The method to calculate the distance between two points. Options are ‘l1’ / ‘manhattan’, ‘l2’ / ‘euclidean’, and ‘custom’. @param column_name: The name of the target column. @param neg_value: The value considered negative in the target variable. @return: A DataFrame containing the counterfactual explanations for the instance.

Return type:

DataFrame

property task

Module contents