acfx.evaluation.ccfs
- acfx.evaluation.ccfs.generate_cfs(query_instance: ndarray, desired_class: int, adjacency_matrix: ndarray, causal_order: Sequence[int], proximity_weight: float, sparsity_weight: float, plausibility_weight: float, diversity_weight: float, bounds: Dict[str, Tuple[float, float]], model: ClassifierMixin, features_order: List[str] | None = None, masked_features: List[str] | None = None, categorical_indicator: List[bool] | None = None, X: DataFrame | None = None, num_cfs: int = 1, init_points: int = 10, n_iter: int = 1000, sampling_from_model: bool = False, optimizer_type: OptimizerType = OptimizerType.EBM, optimizer: ModelBasedCounterOptimizer = None) ndarray
Generate multiple counterfactuals that minimize the loss function using Bayesian Optimization.
- Parameters:
- query_instance:
The instance to generate counterfactuals for.
- desired_class:
The target class for the counterfactuals.
- adjacency_matrix:
The adjacency matrix representing the causal structure.
- causal_order:
The order of variables in the causal graph.
- proximity_weight:
Weight for proximity loss component
- sparsity_weight:
Weight for sparsity loss component
- plausibility_weight:
Weight for plausibility loss component
- diversity_weight:
Weight for diversity loss component
- bounds:
The bounds for each feature to search over (dict with feature names as keys and tuple (min, max) as values).
- model:
The predictive model used to predict class labels.
- features_order:
order of features in query instance
- masked_features:
List of interchangeable features
- categorical_indicator:
True at the index where the variable should be treated as categorical
- num_cfs:
The number of counterfactual instances to generate.
- init_points:
Number of initial points for Bayesian Optimization.
- n_iter:
Number of iterations for Bayesian Optimization.
- X:
training dataset to sample from.
- sampling_from_model:
true if you want to generate samples from model after sampling from data
- optimizer_type:
type of optimizer used on model to generate counterfactuals. If you use OptimizerType.Custom, you need to provide optimizer instance
- optimizer:
instance of optimizer (use for optimizer_type = OptimizerType.Custom)
Returns
- np.ndarray:
The generated counterfactuals that minimize the loss function.
- acfx.evaluation.ccfs.generate_cfs_bayesian(query_instance: ndarray, desired_class: int, bayesian_model: DiscreteBayesianNetwork, categorical_bins_num: int, proximity_weight: float, sparsity_weight: float, plausibility_weight: float, diversity_weight: float, bounds: Dict[str, Tuple[float, float]], model: ClassifierMixin, features_order: List[str] | None = None, masked_features: List[str] | None = None, categorical_indicator: List[bool] | None = None, X: DataFrame | None = None, num_cfs: int = 1, init_points: int = 10, n_iter: int = 1000, sampling_from_model: bool = False, optimizer_type: OptimizerType = OptimizerType.EBM, optimizer: ModelBasedCounterOptimizer = None) ndarray
Generate multiple counterfactuals that minimize the loss function using Bayesian Optimization and bayesian network to calculate causal loss.
- Parameters:
- query_instance:
The instance to generate counterfactuals for.
- desired_class:
The target class for the counterfactuals.
- bayesian_model:
Fitted bayesian network
- categorical_bins_num:
Number of bins that were used to discretize continuous features.
- proximity_weight:
Weight for proximity loss component
- sparsity_weight:
Weight for sparsity loss component
- plausibility_weight:
Weight for plausibility loss component
- diversity_weight:
Weight for diversity loss component
- bounds:
The bounds for each feature to search over (dict with feature names as keys and tuple (min, max) as values).
- model:
The predictive model used to predict class labels.
- features_order:
order of features in query instance
- masked_features:
List of interchangeable features
- categorical_indicator:
True at the index where the variable should be treated as categorical
- num_cfs:
The number of counterfactual instances to generate.
- init_points:
Number of initial points for Bayesian Optimization.
- n_iter:
Number of iterations for Bayesian Optimization.
- X:
training dataset to sample from.
- sampling_from_model:
true if you want to generate samples from model after sampling from data
- optimizer_type:
type of optimizer used on model to generate counterfactuals. If you use OptimizerType.Custom, you need to provide optimizer instance
- optimizer:
instance of optimizer (use for optimizer_type = OptimizerType.Custom)
Returns
- np.ndarray:
The generated counterfactuals that minimize the loss function.