class_docstr: Linear Rule Regression is a directly interpretable supervised learning
  method that performs linear regression on rule-based features.
class_docstr_tok: ["Linear","Rule","Regression","is","a","directly","interpretable","supervised","learning","method","that","performs","linear","regression","on","rule-based","features","."]
docstr: Plot generalized additive model component, which includes first-degree rules 
  and linear functions of unbinarized ordinal features but excludes higher-degree rules.
  
  Args:
      Xorig (DataFrame): Original unbinarized features
      fb: FeatureBinarizer object used to binarize features
      features (list, optional): Subset of features to be plotted
docstr_tok: ["Plot","generalized","additive","model","component",",","which","includes","first-degree","rules","and","linear","functions","of","unbinarized","ordinal","features","but","excludes","higher-degree","rules",".","Args",":","Xorig","(","DataFrame",")",":","Original","unbinarized","features","fb",":","FeatureBinarizer","object","used","to","binarize","features","features","(","list",",","optional",")",":","Subset","of","features","to","be","plotted"]
code: def visualize(self, Xorig, fb, features=None):
      """Plot generalized additive model component, which includes first-degree rules
      and linear functions of unbinarized ordinal features but excludes higher-degree rules.
  
      Args:
          Xorig (DataFrame): Original unbinarized features
          fb: FeatureBinarizer object used to binarize features
          features (list, optional): Subset of features to be plotted
      """
      # Number of ordinal features used
      if self.useOrd:
          nnzOrd = len(self.idxNonzeroOrd)
      else:
          nnzOrd = 0
  
      # Initialize terms Series and x values for plots
      terms = pd.Series(
          index=pd.MultiIndex.from_arrays(
              [[], [], []], names=self.z.index.names
          )
      )
      xPlot = {}
  
      # Iterate over ordinal features
      for i in range(nnzOrd):
          # Restrict to specified features
          f = self.namesOrd[self.idxNonzeroOrd[i]]
          if (features is not None) and (f not in features):
              continue
          # Append term
          terms = terms.append(
              pd.Series(self.lr.coef_[i], index=[(f, "", "")])
          )
          # Initialize x values with min and max
          xPlot[f] = [Xorig[f].min(), Xorig[f].max()]
  
      # Iterate over first-degree rules
      for i in range(self.z.shape[1]):
          if self.z.iloc[:, i].sum() > 1:
              continue
          # MultiIndex of rule
          idxTerm = self.z.index[self.z.iloc[:, i] > 0]
          (f, o, v) = idxTerm[0]
          # Restrict to specified features
          if (features is not None) and (f not in features):
              continue
          # Append new term
          terms = terms.append(
              pd.Series(self.lr.coef_[i + nnzOrd], index=idxTerm)
          )
          # Update x values
          if f not in xPlot:
              if o in ["<=", ">"]:
                  # Ordinal feature, initialize with min and max
                  xPlot[f] = [Xorig[f].min(), Xorig[f].max()]
              else:
                  # Categorical feature, use all values
                  xPlot[f] = np.sort(Xorig[f].unique())
          if o in ["<=", ">"]:
              # Append values around threshold
              xPlot[f].extend([v - self.eps, v + self.eps])
  
      # Initialize y values for plots and variance calculation
      yPlot = {}
      yVar = pd.DataFrame(0.0, index=Xorig.index, columns=xPlot.keys())
      plotLine = pd.Series(False, index=xPlot.keys())
      # Iterate over GAM features
      for f in xPlot.keys():
          # Sort x values
          xPlot[f] = np.sort(np.array(xPlot[f]))
          yPlot[f] = np.zeros_like(xPlot[f], dtype=float)
          # Iterate over terms involving feature
          for (o, v), c in terms[f].iteritems():
              if o == "":
                  if self.useOrd and (f in fb.ordinal):
                      # Add linear function of standardized feature with same factor of 0.4
                      idxf = fb.ordinal.index(f)
                      yPlot[f] += (
                          0.4
                          * c
                          * (xPlot[f] - fb.scaler.mean_[idxf])
                          / fb.scaler.scale_[idxf]
                      )
                      yVar[f] += (
                          0.4
                          * c
                          * (Xorig[f] - fb.scaler.mean_[idxf])
                          / fb.scaler.scale_[idxf]
                      )
                      plotLine[f] = True
                  else:
                      # Binary feature, add indicator function
                      yPlot[f] += c * (xPlot[f] == fb.maps[f].index[1])
                      yVar[f] += c * (Xorig[f] == fb.maps[f].index[1])
              elif o == "<=":
                  # Add step function
                  yPlot[f] += c * (xPlot[f] <= v)
                  yVar[f] += c * (Xorig[f] <= v)
                  plotLine[f] = True
              elif o == ">":
                  # Add step function
                  yPlot[f] += c * (xPlot[f] > v)
                  yVar[f] += c * (Xorig[f] > v)
                  plotLine[f] = True
              elif o == "==":
                  # Add indicator function
                  yPlot[f] += c * (xPlot[f].astype(str) == v)
                  yVar[f] += c * (Xorig[f].astype(str) == v)
              elif o == "!=":
                  # Add indicator function
                  yPlot[f] += c * (xPlot[f].astype(str) != v)
                  yVar[f] += c * (Xorig[f].astype(str) != v)
              elif o == "not":
                  # Binary feature, add indicator function
                  yPlot[f] += c * (xPlot[f] == fb.maps[f].index[0])
                  yVar[f] += c * (Xorig[f] == fb.maps[f].index[0])
  
      # Plot in order of descending variance
      figs = {}
      yVar2 = yVar.var().sort_values(ascending=False)
      for f in yVar2.index:
          figs[f] = plt.figure()
          ax = figs[f].add_subplot(111)
          if plotLine[f]:
              ax.plot(xPlot[f], yPlot[f])
          else:
              ax.bar(xPlot[f], yPlot[f])
              ax.xaxis.set_ticks(xPlot[f])
          plt.xlabel(f)
          plt.ylabel("contribution to prediction")
      return figs, yVar2
  
file_path: AIX360/aix360/algorithms/rbm/linear_regression.py
imports: import numpy
  import pandas
  from sklearn.linear_model import Lasso, Ridge
  from sklearn.base import BaseEstimator, RegressorMixin
  import matplotlib.pyplot
  from .beam_search import beam_search_K1
label_desc: Use image node_id 6 for calling the LinearRuleRegression obj's underlying member method code with example usage: obj.visualize(Xorig, fb, features) and returns: figs,  yVar2