code: def _counterfactual_samples(
      scm: StructuralCausalModel,
      interventions: Dict[
          Any, Callable[[np.ndarray], Union[float, np.ndarray]]
      ],
      noise_data: pd.DataFrame,
  ) -> pd.DataFrame:
      topologically_sorted_nodes = list(nx.topological_sort(scm.graph))
      samples = pd.DataFrame(
          np.empty(
              (noise_data.shape[0], len(topologically_sorted_nodes))
          ),
          columns=topologically_sorted_nodes,
      )
  
      for node in topologically_sorted_nodes:
          if is_root_node(scm.graph, node):
              node_data = noise_data[node].to_numpy()
          else:
              node_data = scm.causal_mechanism(node).evaluate(
                  _parent_samples_of(node, scm, samples),
                  noise_data[node].to_numpy(),
              )
  
          samples[node] = _evaluate_intervention(
              node, interventions, node_data.reshape(-1)
          )
  
      return samples
  
file_path: dowhy/dowhy/gcm/whatif.py
imports: from typing import Any, Callable, Dict, Iterable, List, Optional, Union
  import networkx
  import numpy
  import pandas
  from dowhy.gcm._noise import compute_noise_from_data
  from dowhy.gcm.causal_mechanisms import ClassifierFCM
  from dowhy.gcm.causal_models import InvertibleStructuralCausalModel, ProbabilisticCausalModel, StructuralCausalModel, validate_causal_dag
  from dowhy.gcm.fitting_sampling import draw_samples
  from dowhy.graph import DirectedGraph, get_ordered_predecessors, is_root_node, node_connected_subgraph_view, validate_node_in_graph
label_desc: Use image node_id 5 for calling a global function with example usage: _counterfactual_samples(scm, interventions, noise_data) and returns: samples