class_docstr: Transformer for binarizing categorical and ordinal features.
  
  For use with BooleanRuleCG, LogisticRuleRegression, and LinearRuleRegression. This transformer generates binary
  features using splits in decision trees. Compared to `FeatureBinarizer`, this approach reduces the number of
  features required to produce an accurate model. The smaller feature space shortens training time and often
  simplifies rule sets.
class_docstr_tok: ["Transformer","for","binarizing","categorical","and","ordinal","features",".","For","use","with","BooleanRuleCG",",","LogisticRuleRegression",",","and","LinearRuleRegression",".","This","transformer","generates","binary","features","using","splits","in","decision","trees",".","Compared","to","`","FeatureBinarizer","`",",","this","approach","reduces","the","number","of","features","required","to","produce","an","accurate","model",".","The","smaller","feature","space","shortens","training","time","and","often","simplifies","rule","sets","."]
docstr: Fit transformer. NaN/None values are not permitted for X or y.
  
  Args:
      X (DataFrame): Original features
      y (Iterable): Target
  Returns:
      FeatureBinarizerFromTrees: Self
      self.enc (dict): OneHotEncoders for categorical columns
      self.features (MultiIndex): Pandas MultiIndex of feature names, operations, and values
      self.maps (dict): Mappings for unary/binary columns
      self.ordinal (list): Ordinal columns
      self.scaler (StandardScaler): StandardScaler for ordinal columns
      self.thresh (dict(array)): Thresholds for ordinal columns
docstr_tok: ["Fit","transformer",".","NaN\/None","values","are","not","permitted","for","X","or","y.","Args",":","X","(","DataFrame",")",":","Original","features","y","(","Iterable",")",":","Target","Returns",":","FeatureBinarizerFromTrees",":","Self","self.enc","(","dict",")",":","OneHotEncoders","for","categorical","columns","self.features","(","MultiIndex",")",":","Pandas","MultiIndex","of","feature","names",",","operations",",","and","values","self.maps","(","dict",")",":","Mappings","for","unary\/binary","columns","self.ordinal","(","list",")",":","Ordinal","columns","self.scaler","(","StandardScaler",")",":","StandardScaler","for","ordinal","columns","self.thresh","(","dict","(","array",")",")",":","Thresholds","for","ordinal","columns"]
code: def fit(
      self,
      X: DataFrame,
      y: Union[ndarray, DataFrame, Series, list] = None,
  ):
      """Fit transformer. NaN/None values are not permitted for X or y.
  
      Args:
          X (DataFrame): Original features
          y (Iterable): Target
      Returns:
          FeatureBinarizerFromTrees: Self
          self.enc (dict): OneHotEncoders for categorical columns
          self.features (MultiIndex): Pandas MultiIndex of feature names, operations, and values
          self.maps (dict): Mappings for unary/binary columns
          self.ordinal (list): Ordinal columns
          self.scaler (StandardScaler): StandardScaler for ordinal columns
          self.thresh (dict(array)): Thresholds for ordinal columns
      """
  
      # The decision tree will also throw an exception, but it is cryptic.
      if y is None:
          raise ValueError("The parameter 'y' is required.")
  
      # Binarize unary/binary/categorical features according to the FeatureBinarizer style. Ordinal columns
      # are not binarized: i.e., they are included as-is in the data frame with '<=' operations in the index.
      # They will be binarized by extracting splits from the decision tree.
      Xfb = self._fit_transform_like_feature_binarizer(X)
  
      # Save resulting MultiIndex separately and reset columns. scikit-learn will not support them in version 1.2
      # during fit().
      XfbMultiIndex = Xfb.columns.copy()
      Xfb.columns = range(0, Xfb.shape[1])
  
      # Fit decision trees.
      featuresIdx = np.empty((0,), int)
      thresholds = np.empty((0,), int)
  
      randomState = self.randomState
      for i in range(self.treeNum):
          if randomState is not None:
              randomState += i
          tree = DecisionTreeClassifier(
              random_state=randomState, **self.treeKwargs
          )
          tree.fit(Xfb, y)
          featuresIdx = np.hstack((featuresIdx, tree.tree_.feature))
          thresholds = np.hstack((thresholds, tree.tree_.threshold))
  
      # See `Understanding the decision tree structure`
      # https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html
      select = featuresIdx != -2  # Indicates leaf nodes
      featuresIdx = featuresIdx[select]
      thresholds = thresholds[select]
  
      # Important to do rounding before dropping duplicates because rounding can create duplicates.
      if (self.threshRound is not None) and len(self.ordinal):
          thresholds = thresholds.round(self.threshRound)
  
      # Create frame from column index which contains the relevant features
      features: DataFrame = XfbMultiIndex[featuresIdx].to_frame(False)
  
      # Set thresholds for ordinal values
      if len(self.ordinal):
          select = (features["operation"] == "<=").to_numpy()
          features.loc[select, "value"] = thresholds[select]
  
      # Drop duplicate features.
      features.drop_duplicates(inplace=True)
  
      # Create rule pairs for each feature
      temp: DataFrame = features.copy(True)
      temp["operation"].replace(
          {"<=": ">", "==": "!=", "": "not"}, inplace=True
      )
      features = pd.concat((features, temp))
  
      # Create/sort multi-index that will be used during transformation.
      self.features = pd.MultiIndex.from_frame(features)
      self.features = self.features.sortlevel((0, 1, 2))[0]
  
      # Update respective self attributes based on the selected features.
      if "==" in self.features.levels[1]:
          names = (
              self.features.get_loc_level("==", "operation")[1]
              .get_level_values("feature")
              .unique()
          )
          self.enc = {k: self.enc[k] for k in names}
      else:
          self.enc = {}
  
      if "" in self.features.levels[1]:
          names = (
              self.features.get_loc_level("", "operation")[1]
              .get_level_values("feature")
              .unique()
          )
          self.maps = {k: self.maps[k] for k in names}
      else:
          self.maps = {}
  
      if "<=" in self.features.levels[1]:
          names = (
              self.features.get_loc_level("<=", "operation")[1]
              .get_level_values("feature")
              .unique()
          )
          self.thresh = {
              k: self.features.get_loc_level(
                  [k, "<="], ["feature", "operation"]
              )[1]
              .get_level_values("value")
              .to_numpy(dtype=float)
              for k in names
          }
          self.ordinal = names.to_list()
          if self.returnOrd:
              self.scaler = StandardScaler().fit(X[names])
      else:
          self.thresh = {}
          self.ordinal = []
          self.scaler = None
  
      return self
  
file_path: AIX360/aix360/algorithms/rbm/features.py
imports: from typing import Optional, Tuple, Union
  import numpy
  import pandas
  from numpy import ndarray
  from pandas import DataFrame, Series
  from sklearn.base import TransformerMixin
  from sklearn.preprocessing import OneHotEncoder, StandardScaler
  from sklearn.tree import DecisionTreeClassifier
label_desc: Use image node_id 3 for calling the FeatureBinarizerFromTrees obj's underlying member method code with example usage: obj.fit(X, y) and returns: self