class_docstr: Class for learning a locally linear sparse model from perturbed data
class_docstr_tok: ["Class","for","learning","a","locally","linear","sparse","model","from","perturbed","data"]
docstr: Selects features for the model. see explain_instance_with_data to
  understand the parameters.
docstr_tok: ["Selects","features","for","the","model",".","see","explain_instance_with_data","to","understand","the","parameters","."]
code: def feature_selection(
      self, data, labels, weights, num_features, method
  ):
      """Selects features for the model. see explain_instance_with_data to
      understand the parameters."""
      if method == "none":
          return np.array(range(data.shape[1]))
      elif method == "forward_selection":
          return self.forward_selection(
              data, labels, weights, num_features
          )
      elif method == "highest_weights":
          clf = Ridge(
              alpha=0,
              fit_intercept=True,
              random_state=self.random_state,
          )
          clf.fit(data, labels, sample_weight=weights)
          feature_weights = sorted(
              zip(range(data.shape[0]), clf.coef_ * data[0]),
              key=lambda x: np.abs(x[1]),
              reverse=True,
          )
          return np.array(
              [x[0] for x in feature_weights[:num_features]]
          )
      elif method == "lasso_path":
          weighted_data = (
              data - np.average(data, axis=0, weights=weights)
          ) * np.sqrt(weights[:, np.newaxis])
          weighted_labels = (
              labels - np.average(labels, weights=weights)
          ) * np.sqrt(weights)
          nonzero = range(weighted_data.shape[1])
          _, coefs = self.generate_lars_path(
              weighted_data, weighted_labels
          )
          for i in range(len(coefs.T) - 1, 0, -1):
              nonzero = coefs.T[i].nonzero()[0]
              if len(nonzero) <= num_features:
                  break
          used_features = nonzero
          return used_features
      elif method == "auto":
          if num_features <= 6:
              n_method = "forward_selection"
          else:
              n_method = "highest_weights"
          return self.feature_selection(
              data, labels, weights, num_features, n_method
          )
  
file_path: tensorwatch/tensorwatch/saliency/lime/lime_base.py
imports: from __future__ import print_function
  import numpy
  from sklearn.linear_model import Ridge, lars_path
  from sklearn.utils import check_random_state
label_desc: Use image node_id 4 for calling the LimeBase obj's underlying member method code with example usage: obj.feature_selection(data, labels, weights, num_features, method) and returns: np, self, np, used_features, self