class_docstr: 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.01,
              fit_intercept=True,
              random_state=self.random_state,
          )
          clf.fit(data, labels, sample_weight=weights)
  
          coef = clf.coef_
          if sp.sparse.issparse(data):
              coef = sp.sparse.csr_matrix(clf.coef_)
              weighted_data = coef.multiply(data[0])
              # Note: most efficient to slice the data before reversing
              sdata = len(weighted_data.data)
              argsort_data = np.abs(weighted_data.data).argsort()
              # Edge case where data is more sparse than requested number of feature importances
              # In that case, we just pad with zero-valued features
              if sdata < num_features:
                  nnz_indexes = argsort_data[::-1]
                  indices = weighted_data.indices[nnz_indexes]
                  num_to_pad = num_features - sdata
                  indices = np.concatenate(
                      (
                          indices,
                          np.zeros(num_to_pad, dtype=indices.dtype),
                      )
                  )
                  indices_set = set(indices)
                  pad_counter = 0
                  for i in range(data.shape[1]):
                      if i not in indices_set:
                          indices[pad_counter + sdata] = i
                          pad_counter += 1
                          if pad_counter >= num_to_pad:
                              break
              else:
                  nnz_indexes = argsort_data[
                      sdata - num_features : sdata
                  ][::-1]
                  indices = weighted_data.indices[nnz_indexes]
              return indices
          else:
              weighted_data = coef * data[0]
              feature_weights = sorted(
                  zip(range(data.shape[1]), weighted_data),
                  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: lime/lime/lime_base.py
imports: import numpy
  import scipy
  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, indices, np, used_features, self