CausalShallValues.compute
- CausalShallValues.compute(data, N=100)
Computes the SHALL values for all rows in the provided data.
Notes
Since this is a partial explanation, all rows in
datamust contain all variables present in the initialized Bayesian Network.All rows containing NaN values in columns corresponding to variables in the Bayesian Network will be dropped.
- Parameters:
data (
pandas.DataFrame | pandas.Series | dict | tuple | None) – Data to explain. A plain DataFrame/Series/dict is treated as (data, True) (labels assumed). A tuple allows explicit control: (data, with_labels). If None, a random sample of size N is generated.N (
int) – The number of samples to generate if data is None.
- Returns:
An Explanation object containing the SHALL values and variable importances for each row in the data, after rows with NaN values have been dropped.
- Return type:
- Raises:
TypeError – If the first element of data is not a pd.DataFrame, pd.Series or dict, or if N is not an integer when data is None.
ValueError – If N is less than 2 when data is None, or if the provided data does not contain all variables present in the initialized Bayesian Network.
Example
import pyagrum as gum
import pyagrum.explain as expl
gum.initRandom(42)
bn = gum.fastBN("A->B->Y;C->Y")
df, _ = gum.generateSample(bn, 200)
explainer = expl.CausalShallValues(bn, (df, True)) # df as background data
explanation = explainer.compute(df.head(5)) # explains the log-likelihood of the first 5 rows
explanation.values_type
# 'SHALL'
{v: round(imp, 4) for v, imp in sorted(explanation.importances.items())}
# {'A': 0.3722, 'B': 0.2692, 'C': 0.4759, 'Y': 0.5549}
Class