code: def run_klasso(
      featurization,
      loglikelihoods,
      weights,
      max_features=3,
      model_regressor=None,
      random_state=1,
  ):
      """
      Run the lime-style feature attribution with K-Lasso + locally-weighted linear models.
      featurization: Representations of the perturbed inputs.
      loglikelihoods: Log-likelihood of the output we are trying to explain.
      weights: The weight of each perturbed instance. More perturbed implies lower weight.
      """
      weighted_featurization = (
          featurization
          - np.average(featurization, axis=0, weights=weights)
      ) * np.sqrt(weights[:, np.newaxis])
      weighted_labels = (
          loglikelihoods - np.average(loglikelihoods, weights=weights)
      ) * np.sqrt(weights)
  
      nonzero = range(weighted_featurization.shape[1])
      x_vector = weighted_featurization
      alphas, _, coefs = lars_path(
          x_vector, weighted_labels, method="lasso", verbose=False
      )
  
      for i in range(len(coefs.T) - 1, 0, -1):
          nonzero = coefs.T[i].nonzero()[0]
          if len(nonzero) <= max_features:
              break
      used_features = nonzero
  
      if model_regressor is None:
          # model_regressor = ElasticNet(alpha=0.25, l1_ratio=0.5, fit_intercept=True,
          #                        random_state=random_state)
          model_regressor = Ridge(
              alpha=1.0, fit_intercept=True, random_state=random_state
          )
  
      model_regressor.fit(
          featurization[:, used_features],
          loglikelihoods,
          sample_weight=weights,
      )
  
      explanation = list(
          sorted(
              zip(used_features, model_regressor.coef_),
              key=lambda x: np.abs(x[1]),
              reverse=True,
          )
      )
      return explanation
  
imports: import torch
  import numpy
  from abc import ABC, abstractmethod
  from sklearn.linear_model import Ridge, lars_path
  from .text_utils import *
  from .perturbation_tools import RemovalPerturbation
label_desc: Use image node_id 1 for calling a global function with example usage: run_klasso(featurization, loglikelihoods, weights, max_features, model_regressor, random_state) and returns: explanation