class_docstr: Search class for learning tree related graph structure. The algorithms
  supported are Chow-Liu and Tree-augmented naive bayes (TAN).
  
  Chow-Liu constructs the maximum-weight spanning tree with mutual information
  score as edge weights.
  
  TAN is an extension of Naive Bayes classifier to allow a tree structure over
  the independent variables to account for interaction.
  
  Parameters
  ----------
  data: pandas.DataFrame object
      dataframe object where each column represents one variable.
  
  root_node: str, int, or any hashable python object, default is None.
      The root node of the tree structure. If None then root node is auto-picked
      as the node with the highest sum of edge weights.
  
  n_jobs: int (default: -1)
      Number of jobs to run in parallel. `-1` means use all processors.
  
  References
  ----------
  [1] Chow, C. K.; Liu, C.N. (1968), "Approximating discrete probability
      distributions with dependence trees", IEEE Transactions on Information
      Theory, IT-14 (3): 462–467
  
  [2] Friedman N, Geiger D and Goldszmidt M (1997). Bayesian network classifiers.
      Machine Learning 29: 131–163
class_docstr_tok: ["Search","class","for","learning","tree","related","graph","structure",".","The","algorithms","supported","are","Chow-Liu","and","Tree-augmented","naive","bayes","(","TAN",")",".","Chow-Liu","constructs","the","maximum-weight","spanning","tree","with","mutual","information","score","as","edge","weights",".","TAN","is","an","extension","of","Naive","Bayes","classifier","to","allow","a","tree","structure","over","the","independent","variables","to","account","for","interaction",".","Parameters","--","--","--","--","--","data",":","pandas.DataFrame","object","dataframe","object","where","each","column","represents","one","variable",".","root_node",":","str",",","int",",","or","any","hashable","python","object",",","default","is","None",".","The","root","node","of","the","tree","structure",".","If","None","then","root","node","is","auto-picked","as","the","node","with","the","highest","sum","of","edge","weights",".","n_jobs",":","int","(","default",":","-1",")","Number","of","jobs","to","run","in","parallel",".","`","-1","`","means","use","all","processors",".","References","--","--","--","--","--","[","1","]","Chow",",","C.","K.",";","Liu",",","C.N",".","(","1968",")",",","``","Approximating","discrete","probability","distributions","with","dependence","trees","''",",","IEEE","Transactions","on","Information","Theory",",","IT-14","(","3",")",":","462\u2013467","[","2","]","Friedman","N",",","Geiger","D","and","Goldszmidt","M","(","1997",")",".","Bayesian","network","classifiers",".","Machine","Learning","29",":","131\u2013163"]
docstr: Helper function to Chow-Liu algorithm for estimating tree structure from given data. Refer to
  pgmpy.estimators.TreeSearch for more details. This function returns the DAG based on the edge weights matrix.
  
  Parameters
  ----------
  weights: numpy 2D array, shape = (n_columns, n_columns)
      symmetric matrix where each element represents an edge weight.
  
  columns: list or array
      Names of the columns (& rows) of the weights matrix.
  
  root_node: str, int, or any hashable python object.
      The root node of the tree structure.
  
  Returns
  -------
  model: pgmpy.base.DAG
      The estimated model structure.
  
  Examples
  --------
  >>> import numpy as np
  >>> import pandas as pd
  >>> from pgmpy.estimators import TreeSearch
  >>> values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
  ...                       columns=['A', 'B', 'C', 'D', 'E'])
  >>> est = TreeSearch(values, root_node='B')
  >>> model = est.estimate(estimator_type='chow-liu')
docstr_tok: ["Helper","function","to","Chow-Liu","algorithm","for","estimating","tree","structure","from","given","data",".","Refer","to","pgmpy.estimators.TreeSearch","for","more","details",".","This","function","returns","the","DAG","based","on","the","edge","weights","matrix",".","Parameters","--","--","--","--","--","weights",":","numpy","2D","array",",","shape","=","(","n_columns",",","n_columns",")","symmetric","matrix","where","each","element","represents","an","edge","weight",".","columns",":","list","or","array","Names","of","the","columns","(","&","rows",")","of","the","weights","matrix",".","root_node",":","str",",","int",",","or","any","hashable","python","object",".","The","root","node","of","the","tree","structure",".","Returns","--","--","--","-","model",":","pgmpy.base.DAG","The","estimated","model","structure",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","import","pandas","as","pd",">",">",">","from","pgmpy.estimators","import","TreeSearch",">",">",">","values","=","pd.DataFrame","(","np.random.randint","(","low=0",",","high=2",",","size=","(","1000",",","5",")",")",",","...","columns=","[","'","A","'",",","'","B","'",",","'","C","'",",","'D","'",",","'","E","'","]",")",">",">",">","est","=","TreeSearch","(","values",",","root_node=","'","B","'",")",">",">",">","model","=","est.estimate","(","estimator_type='chow-liu","'",")"]
code: def _create_tree_and_dag(weights, columns, root_node):
      """
      Helper function to Chow-Liu algorithm for estimating tree structure from given data. Refer to
      pgmpy.estimators.TreeSearch for more details. This function returns the DAG based on the edge weights matrix.
  
      Parameters
      ----------
      weights: numpy 2D array, shape = (n_columns, n_columns)
          symmetric matrix where each element represents an edge weight.
  
      columns: list or array
          Names of the columns (& rows) of the weights matrix.
  
      root_node: str, int, or any hashable python object.
          The root node of the tree structure.
  
      Returns
      -------
      model: pgmpy.base.DAG
          The estimated model structure.
  
      Examples
      --------
      >>> import numpy as np
      >>> import pandas as pd
      >>> from pgmpy.estimators import TreeSearch
      >>> values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
      ...                       columns=['A', 'B', 'C', 'D', 'E'])
      >>> est = TreeSearch(values, root_node='B')
      >>> model = est.estimate(estimator_type='chow-liu')
      """
      # Step 2: Compute the maximum spanning tree using the weights.
      T = nx.maximum_spanning_tree(
          nx.from_pandas_adjacency(
              pd.DataFrame(weights, index=columns, columns=columns),
              create_using=nx.Graph,
          )
      )
  
      # Step 3: Create DAG by directing edges away from root node and return
      D = nx.bfs_tree(T, root_node)
      return DAG(D)
  
file_path: pgmpy/pgmpy/estimators/TreeSearch.py
imports: from itertools import combinations
  import networkx
  import numpy
  import pandas
  from joblib import Parallel, delayed
  from sklearn.metrics import adjusted_mutual_info_score, mutual_info_score, normalized_mutual_info_score
  from tqdm.auto import tqdm
  from pgmpy import config
  from pgmpy.base import DAG
  from pgmpy.estimators import StructureEstimator
label_desc: Use image node_id 5 for calling the TreeSearch obj's underlying member method code with example usage: obj._create_tree_and_dag(weights, columns, root_node) and returns: DAG