class_docstr: Extract model data and port a DecisionTreeClassifier classifier.
class_docstr_tok: ["Extract","model","data","and","port","a","DecisionTreeClassifier","classifier","."]
docstr: The ported single tree as function or method.
  
  Parameters
  ----------
  tpls : Environment
      All relevant templates.
  language
      The required language.
  converter
      The number converter.
  left_nodes : list
      The left children node.
  right_nodes : list
      The left children node.
  threshold : list
      The decision thresholds.
  value : list
      The label or class.
  features : list
      The feature values.
  node : list
      The current node.
  depth : list
      The tree depth.
  
  Returns
  -------
  A single branch of a DecisionTreeClassifier.
docstr_tok: ["The","ported","single","tree","as","function","or","method",".","Parameters","--","--","--","--","--","tpls",":","Environment","All","relevant","templates",".","language","The","required","language",".","converter","The","number","converter",".","left_nodes",":","list","The","left","children","node",".","right_nodes",":","list","The","left","children","node",".","threshold",":","list","The","decision","thresholds",".","value",":","list","The","label","or","class",".","features",":","list","The","feature","values",".","node",":","list","The","current","node",".","depth",":","list","The","tree","depth",".","Returns","--","--","--","-","A","single","branch","of","a","DecisionTreeClassifier","."]
code: def _create_branch(
      self,
      tpls: Environment,
      language: enum.Language,
      converter: Callable[[object], str],
      left_nodes: list,
      right_nodes: list,
      threshold: list,
      value: list,
      features: list,
      node: int,
      depth: int,
  ):
      """
      The ported single tree as function or method.
  
      Parameters
      ----------
      tpls : Environment
          All relevant templates.
      language
          The required language.
      converter
          The number converter.
      left_nodes : list
          The left children node.
      right_nodes : list
          The left children node.
      threshold : list
          The decision thresholds.
      value : list
          The label or class.
      features : list
          The feature values.
      node : list
          The current node.
      depth : list
          The tree depth.
  
      Returns
      -------
      A single branch of a DecisionTreeClassifier.
      """
      out = ""
      out_indent = tpls.get_template("indent").render()
      if threshold[node] != -2.0:
          out += "\n"
          val_a = "features[{}]".format(features[node])
          if language is enum.Language.PHP:
              val_a = "$" + val_a
          val_b = converter(threshold[node])
          tpl_if = tpls.get_template("if")
          out_if = tpl_if.render(a=val_a, op="<=", b=val_b)
          out_if = indent(out_if, depth * out_indent)
          out += out_if
  
          if left_nodes[node] != -1.0:
              out += self._create_branch(
                  tpls,
                  language,
                  converter,
                  left_nodes,
                  right_nodes,
                  threshold,
                  value,
                  features,
                  left_nodes[node],
                  depth + 1,
              )
  
          out += "\n"
          out_else = tpls.get_template("else").render()
          out_else = indent(out_else, depth * out_indent)
          out += out_else
  
          if right_nodes[node] != -1.0:
              out += self._create_branch(
                  tpls,
                  language,
                  converter,
                  left_nodes,
                  right_nodes,
                  threshold,
                  value,
                  features,
                  right_nodes[node],
                  depth + 1,
              )
  
          out += "\n"
          out_endif = tpls.get_template("endif").render()
          out_endif = indent(out_endif, depth * out_indent)
          out += out_endif
      else:
          clazzes = []
          tpl = "classes[{0}] = {1}"
          if language is enum.Language.PHP:
              tpl = "$" + tpl
          tpl = indent(tpl, depth * out_indent)
  
          for i, rate in enumerate(value[node]):
              if int(rate) > 0:
                  clazz = tpl.format(i, rate)
                  clazz = "\n" + clazz
                  clazzes.append(clazz)
  
          out_join = tpls.get_template("join").render()
          out += out_join.join(clazzes) + out_join
      return out
  
file_path: sklearn-porter/sklearn_porter/estimator/DecisionTreeClassifier/__init__.py
imports: from copy import deepcopy
  from json import dumps, encoder
  from textwrap import indent
  from typing import Callable, Tuple, Union
  from jinja2 import Environment
  from loguru import logger
  from sklearn.tree.tree import DecisionTreeClassifier
  from sklearn_porter import enums
  from sklearn_porter import exceptions
  from sklearn_porter.estimator.EstimatorApiABC import EstimatorApiABC
  from sklearn_porter.estimator.EstimatorBase import EstimatorBase
label_desc: Use image node_id 4 for calling the DecisionTreeClassifier obj's underlying member method code with example usage: obj._create_branch(tpls, language, converter, left_nodes, right_nodes, threshold, value, features, node, depth) and returns: out