class_docstr: Extract model data and port a DecisionTreeClassifier classifier.
class_docstr_tok: ["Extract","model","data","and","port","a","DecisionTreeClassifier","classifier","."]
docstr: Port an estimator.
  
  Parameters
  ----------
  language : Language
      The required language.
  template : Template
      The required template.
  class_name : str
      Change the default class name which will be used in the generated
      output. By default the class name of the passed estimator will be
      used, e.g. `DecisionTreeClassifier`.
  converter : Callable
      Change the default converter of all floating numbers from the model
      data. By default a simple string cast `str(value)` will be used.
  to_json : bool (default: False)
      Return the result as JSON string.
  
  Returns
  -------
  out_class : str
      The ported estimator.
docstr_tok: ["Port","an","estimator",".","Parameters","--","--","--","--","--","language",":","Language","The","required","language",".","template",":","Template","The","required","template",".","class_name",":","str","Change","the","default","class","name","which","will","be","used","in","the","generated","output",".","By","default","the","class","name","of","the","passed","estimator","will","be","used",",","e.g",".","`","DecisionTreeClassifier","`",".","converter",":","Callable","Change","the","default","converter","of","all","floating","numbers","from","the","model","data",".","By","default","a","simple","string","cast","`","str","(","value",")","`","will","be","used",".","to_json",":","bool","(","default",":","False",")","Return","the","result","as","JSON","string",".","Returns","--","--","--","-","out_class",":","str","The","ported","estimator","."]
code: def port(
      self,
      language: enum.Language,
      template: enum.Template,
      class_name: str,
      converter: Callable[[object], str],
      to_json: bool = False,
  ) -> Union[str, Tuple[str, str]]:
      """
      Port an estimator.
  
      Parameters
      ----------
      language : Language
          The required language.
      template : Template
          The required template.
      class_name : str
          Change the default class name which will be used in the generated
          output. By default the class name of the passed estimator will be
          used, e.g. `DecisionTreeClassifier`.
      converter : Callable
          Change the default converter of all floating numbers from the model
          data. By default a simple string cast `str(value)` will be used.
      to_json : bool (default: False)
          Return the result as JSON string.
  
      Returns
      -------
      out_class : str
          The ported estimator.
      """
      # Placeholders:
      plas = deepcopy(self.placeholders)  # alias
      plas.update(
          dict(
              class_name=class_name,
              to_json=to_json,
          )
      )
      plas.update(self.meta_info)
  
      # Templates:
      tpls = self._load_templates(language.value.KEY)
  
      # Make 'exported' variant:
      if template == enum.Template.EXPORTED:
          tpl_class = tpls.get_template("exported.class")
          out_class = tpl_class.render(**plas)
          # converter = kwargs.get('converter')
          encoder.FLOAT_REPR = lambda o: converter(o)
          model_data = dumps(self.model_data, separators=(",", ":"))
          return out_class, model_data
  
      # Make 'atatched' or 'combined' variant:
      # Pick templates:
      tpl_int = tpls.get_template("int").render()
      tpl_double = tpls.get_template("double").render()
      tpl_arr_1 = tpls.get_template("arr[]")
      tpl_arr_2 = tpls.get_template("arr[][]")
      tpl_in_brackets = tpls.get_template("in_brackets")
  
      # Make contents:
      lefts_val = list(map(str, self.model_data.get("lefts")))
      lefts_str = tpl_arr_1.render(
          type=tpl_int,
          name="lefts",
          values=", ".join(lefts_val),
          n=len(lefts_val),
      )
  
      rights_val = list(map(str, self.model_data.get("rights")))
      rights_str = tpl_arr_1.render(
          type=tpl_int,
          name="rights",
          values=", ".join(rights_val),
          n=len(rights_val),
      )
  
      thresholds_val = list(
          map(converter, self.model_data.get("thresholds"))
      )
      thresholds_str = tpl_arr_1.render(
          type=tpl_double,
          name="thresholds",
          values=", ".join(thresholds_val),
          n=len(thresholds_val),
      )
  
      indices_val = list(map(str, self.model_data.get("indices")))
      indices_str = tpl_arr_1.render(
          type=tpl_int,
          name="indices",
          values=", ".join(indices_val),
          n=len(indices_val),
      )
  
      classes_val = [
          list(map(str, e)) for e in self.model_data.get("classes")
      ]
      classes_str = [", ".join(e) for e in classes_val]
      classes_str = ", ".join(
          [tpl_in_brackets.render(value=e) for e in classes_str]
      )
      classes_str = tpl_arr_2.render(
          type=tpl_int,
          name="classes",
          values=classes_str,
          n=len(classes_val),
          m=len(classes_val[0]),
      )
  
      plas.update(
          dict(
              lefts=lefts_str,
              rights=rights_str,
              thresholds=thresholds_str,
              indices=indices_str,
              classes=classes_str,
          )
      )
  
      # Make 'attached' variant:
      if template == enum.Template.ATTACHED:
          tpl_class = tpls.get_template("attached.class")
          out_class = tpl_class.render(**plas)
          return out_class
  
      # Make 'combined' variant:
      if template == enum.Template.COMBINED:
          tpl_class = tpls.get_template("combined.class")
          out_tree = self._create_tree(tpls, language, converter)
          plas.update(dict(tree=out_tree))
          out_class = tpl_class.render(**plas)
          return out_class
  
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 2 for calling the DecisionTreeClassifier obj's underlying member method code with example usage: obj.port(language, template, class_name, converter, to_json) and returns: out_class,  model_data, out_class, out_class