class_docstr: Computes SHAP values for a linear model, optionally accounting for inter-feature correlations.
  
  This computes the SHAP values for a linear model and can account for the correlations among
  the input features. Assuming features are independent leads to interventional SHAP values which
  for a linear model are coef[i] * (x[i] - X.mean(0)[i]) for the ith feature. If instead we account
  for correlations then we prevent any problems arising from collinearity and share credit among
  correlated features. Accounting for correlations can be computationally challenging, but
  LinearExplainer uses sampling to estimate a transform that can then be applied to explain
  any prediction of the model.
  
  Parameters
  ----------
  model : (coef, intercept) or sklearn.linear_model.*
      User supplied linear model either as either a parameter pair or sklearn object.
  
  data : (mean, cov), numpy.array, pandas.DataFrame, iml.DenseData or scipy.csr_matrix
      The background dataset to use for computing conditional expectations. Note that only the
      mean and covariance of the dataset are used. This means passing a raw data matrix is just
      a convenient alternative to passing the mean and covariance directly.
  nsamples : int
      Number of samples to use when estimating the transformation matrix used to account for
      feature correlations.
  feature_perturbation : "interventional" (default) or "correlation_dependent"
      There are two ways we might want to compute SHAP values, either the full conditional SHAP
      values or the interventional SHAP values. For interventional SHAP values we break any
      dependence structure between features in the model and so uncover how the model would behave if we
      intervened and changed some of the inputs. For the full conditional SHAP values we respect
      the correlations among the input features, so if the model depends on one input but that
      input is correlated with another input, then both get some credit for the model's behavior. The
      interventional option stays "true to the model" meaning it will only give credit to features that are
      actually used by the model, while the correlation option stays "true to the data" in the sense that
      it only considers how the model would behave when respecting the correlations in the input data.
      For sparse case only interventional option is supported.
  
  Examples
  --------
  See `Linear explainer examples <https://shap.readthedocs.io/en/latest/api_examples/explainers/LinearExplainer.html>`_
class_docstr_tok: ["Computes","SHAP","values","for","a","linear","model",",","optionally","accounting","for","inter-feature","correlations",".","This","computes","the","SHAP","values","for","a","linear","model","and","can","account","for","the","correlations","among","the","input","features",".","Assuming","features","are","independent","leads","to","interventional","SHAP","values","which","for","a","linear","model","are","coef","[","i","]","*","(","x","[","i","]","-","X.mean","(","0",")","[","i","]",")","for","the","ith","feature",".","If","instead","we","account","for","correlations","then","we","prevent","any","problems","arising","from","collinearity","and","share","credit","among","correlated","features",".","Accounting","for","correlations","can","be","computationally","challenging",",","but","LinearExplainer","uses","sampling","to","estimate","a","transform","that","can","then","be","applied","to","explain","any","prediction","of","the","model",".","Parameters","--","--","--","--","--","model",":","(","coef",",","intercept",")","or","sklearn.linear_model",".","*","User","supplied","linear","model","either","as","either","a","parameter","pair","or","sklearn","object",".","data",":","(","mean",",","cov",")",",","numpy.array",",","pandas.DataFrame",",","iml.DenseData","or","scipy.csr_matrix","The","background","dataset","to","use","for","computing","conditional","expectations",".","Note","that","only","the","mean","and","covariance","of","the","dataset","are","used",".","This","means","passing","a","raw","data","matrix","is","just","a","convenient","alternative","to","passing","the","mean","and","covariance","directly",".","nsamples",":","int","Number","of","samples","to","use","when","estimating","the","transformation","matrix","used","to","account","for","feature","correlations",".","feature_perturbation",":","``","interventional","''","(","default",")","or","``","correlation_dependent","''","There","are","two","ways","we","might","want","to","compute","SHAP","values",",","either","the","full","conditional","SHAP","values","or","the","interventional","SHAP","values",".","For","interventional","SHAP","values","we","break","any","dependence","structure","between","features","in","the","model","and","so","uncover","how","the","model","would","behave","if","we","intervened","and","changed","some","of","the","inputs",".","For","the","full","conditional","SHAP","values","we","respect","the","correlations","among","the","input","features",",","so","if","the","model","depends","on","one","input","but","that","input","is","correlated","with","another","input",",","then","both","get","some","credit","for","the","model","'s","behavior",".","The","interventional","option","stays","``","true","to","the","model","''","meaning","it","will","only","give","credit","to","features","that","are","actually","used","by","the","model",",","while","the","correlation","option","stays","``","true","to","the","data","''","in","the","sense","that","it","only","considers","how","the","model","would","behave","when","respecting","the","correlations","in","the","input","data",".","For","sparse","case","only","interventional","option","is","supported",".","Examples","--","--","--","--","See","`","Linear","explainer","examples","<","https",":","\/\/shap.readthedocs.io\/en\/latest\/api_examples\/explainers\/LinearExplainer.html",">","`","_"]
docstr: Attempt to pull out the coefficients and intercept from the given model object.
          
docstr_tok: ["Attempt","to","pull","out","the","coefficients","and","intercept","from","the","given","model","object","."]
code: def _parse_model(model):
      """Attempt to pull out the coefficients and intercept from the given model object."""
      # raw coefficients
      if type(model) == tuple and len(model) == 2:
          coef = model[0]
          intercept = model[1]
  
      # sklearn style model
      elif hasattr(model, "coef_") and hasattr(model, "intercept_"):
          # work around for multi-class with a single class
          if len(model.coef_.shape) > 1 and model.coef_.shape[0] == 1:
              coef = model.coef_[0]
              try:
                  intercept = model.intercept_[0]
              except TypeError:
                  intercept = model.intercept_
          else:
              coef = model.coef_
              intercept = model.intercept_
      else:
          raise InvalidModelError(
              "An unknown model type was passed: " + str(type(model))
          )
  
      return coef, intercept
  
file_path: shap/shap/explainers/_linear.py
imports: import warnings
  import numpy
  import pandas
  from scipy.sparse import issparse
  from tqdm.auto import tqdm
  from ..None import links, maskers
  from ..utils._exceptions import DimensionError, InvalidFeaturePerturbationError, InvalidModelError
  from ._explainer import Explainer
label_desc: Use image node_id 3 for calling the LinearExplainer obj's underlying member method code with example usage: obj._parse_model(model) and returns: coef,  intercept