causalnex.evaluation.roc_auc¶
-
causalnex.evaluation.
roc_auc
(bn, data, node)[source]¶ Build a report of the micro-average Receiver-Operating Characteristics (ROC), and the Area Under the ROC curve Micro-average computes roc_auc over all predictions for all states of node.
- Parameters
bn (BayesianNetwork) – model to compute roc_auc.
data (pd.DataFrame) – test data that will be used to calculate ROC.
node (str) – name of the variable to generate the report for.
- Return type
Tuple
[List
[Tuple
[float
,float
]],float
]- Returns
- roc - auc tuple
roc (List[Tuple[float, float]]): list of [(fpr, tpr)] observations.
auc float: auc for the node predictions.
Example:
from causalnex.structure import StructureModel from causalnex.network import BayesianNetwork sm = StructureModel() sm.add_edges_from([ ('rush_hour', 'traffic'), ('weather', 'traffic') ]) bn = BayesianNetwork(sm) import pandas as pd data = pd.DataFrame({ 'rush_hour': [True, False, False, False, True, False, True], 'weather': ['Terrible', 'Good', 'Bad', 'Good', 'Bad', 'Bad', 'Good'], 'traffic': ['heavy', 'light', 'heavy', 'light', 'heavy', 'heavy', 'heavy'] } bn = bn.fit_node_states_and_cpds(data) test_data = pd.DataFrame({ 'rush_hour': [False, False, True, True], 'weather': ['Good', 'Bad', 'Good', 'Bad'], 'traffic': ['light', 'heavy', 'heavy', 'light'] }) from causalnex.evaluation import roc_auc roc, auc = roc_auc(bn, test_data, "traffic") print(auc) 0.75