code: def fit(
      causal_model: ProbabilisticCausalModel,
      data: pd.DataFrame,
      return_evaluation_summary: bool = False,
  ):
      """Fits the causal mechanism of each node to the data. This is done by iterating over the nodes in the graph and
      fitting their assigned causal mechanisms individually to the data by calling the corresponding fit function. Due to
      the modularity assumption, we can fit each mechanism in the graph independently of the other mechanisms. For root
      nodes, the training data is the corresponding column in the provided data. For non-root nodes, the data is based on
      a node's parents and the node itself. Before a node is fitted, this function first validates whether the assigned
      mechanism is valid, i.e., whether a root node follows a StochasticModel and whether a non-root node follows a
      ConditionalStochasticModel.
  
      The details of fitting a causal mechanism depend on their implementation. For example, if a node follows an additive
      noise model X_i = f_i(PA_i) + N_i, where N_i is unobserved noise, the fitting involves fitting the function f_i
      (which could be any scikit-learn regressor) to the data and modeling the distribution N_i based on the residuals
      X_i - f_i(PA_i). For more details on how each individual mechanism is fitted, refer to the corresponding
      documentation, since these are individual implementation details.
  
      This function optionally, returns a summary of different metrics of the causal mechanisms evaluated via
      cross-validation. Note, this will use the evaluate_causal_model method. For more detailed and extensive evaluations,
      consider using the evaluate_causal_model method directly.
  
      :param causal_model: The causal model containing the mechanisms of the node that will be fitted.
      :param data: Observations of nodes in the causal model.
      :param return_evaluation_summary: If True, returns a summary of the performances of the fitted mechanisms using the
                                        evaluate_causal_model method. If False, nothing is returned.
      :return: Optionally, a CausalModelEvaluationResult summarizing the performances of the causal mechanisms via
               cross-validation.
      """
      progress_bar = tqdm(
          causal_model.graph.nodes,
          desc="Fitting causal models",
          position=0,
          leave=True,
          disable=not config.show_progress_bars,
      )
      for node in progress_bar:
          if node not in data:
              raise RuntimeError(
                  "Could not find data for node %s in the given training data! There should be a column "
                  "containing samples for node %s." % (node, node)
              )
  
          progress_bar.set_description(
              "Fitting causal mechanism of node %s" % node
          )
  
          fit_causal_model_of_target(causal_model, node, data)
  
      if return_evaluation_summary:
          from dowhy.gcm import evaluate_causal_model
  
          return evaluate_causal_model(
              causal_model,
              data,
              evaluate_causal_mechanisms=True,
              compare_mechanism_baselines=False,
              evaluate_invertibility_assumptions=False,
              evaluate_overall_kl_divergence=False,
              evaluate_causal_structure=False,
          )
  
file_path: dowhy/dowhy/gcm/fitting_sampling.py
imports: from typing import Any
  import networkx
  import numpy
  import pandas
  from tqdm import tqdm
  from dowhy.gcm import config
  from dowhy.gcm.causal_models import PARENTS_DURING_FIT, ProbabilisticCausalModel, validate_causal_dag, validate_causal_model_assignment
  from dowhy.graph import get_ordered_predecessors, is_root_node
label_desc: Use image node_id 1 for calling a global function with example usage: fit(causal_model, data, return_evaluation_summary) and returns: evaluate_causal_model