fatf.transparency.predictions.counterfactuals.textualise_counterfactuals

fatf.transparency.predictions.counterfactuals.textualise_counterfactuals(instance: Union[numpy.ndarray, numpy.void], counterfactuals: numpy.ndarray, instance_class: Union[int, str, None] = None, counterfactuals_distances: Optional[numpy.ndarray] = None, counterfactuals_predictions: Optional[numpy.ndarray] = None) → str[source]

Translates a counterfactuals array into a textual description.

Parameters
instancenumpy.ndarray or numpy.void

A 1-dimensional numpy array representing a data point for which counterfactuals were calculated.

counterfactualsnumpy.ndarray

A 2-dimensional numpy array with the counterfactual data points.

instance_classstring or integer, optional (default=None)

The class of the input instance.

counterfactuals_distancesnumpy.ndarray, optional (default=None)

A 1-dimensional numpy array with distances from the input instance to every counterfactual data point.

counterfactuals_predictionsnumpy.ndarray, optional (default=None)

A 1-dimensional numpy array with predictions for every counterfactual data point.

Returns
textualisationstring

A string representation of the counterfactuals.

Raises
IncorrectShapeError

instance is not a 1-dimensional numpy array or any of counterfactuals, counterfactuals_distances or counterfactuals_predictions is not a 2-dimensional numpy array.

IndexError

The counterfactuals and the instance column indices disagree.

TypeError

The instance_class parameter is neither an integer nor a string. The types of the instance and the counterfactuals arrays are different.

ValueError

The instance is not of a base type (strings and/or numbers); the counterfactuals is not of a base type; the counterfactuals_distances is not a purely numerical array; or counterfactuals_predictions is not a base array. Either the length of the counterfactuals_distances array or of the counterfactuals_predictions array is not the same as the number of rows in the counterfactuals array. The type of the instance_class is different than the type of the counterfactuals_predictions array.

Examples using fatf.transparency.predictions.counterfactuals.textualise_counterfactuals