code: def test_kernel_shap_with_a1a_sparse_nonzero_background():
      """Check with a sparse non zero background matrix."""
      np.set_printoptions(threshold=100000)
  
      X, y = shap.datasets.a1a()
      (
          x_train,
          x_test,
          y_train,
          _,
      ) = sklearn.model_selection.train_test_split(
          X, y, test_size=0.01, random_state=0
      )
      linear_model = sklearn.linear_model.LinearRegression()
      linear_model.fit(x_train, y_train)
      # Calculate median of background data
      median_dense = sklearn.utils.sparsefuncs.csc_median_axis_0(
          x_train.tocsc()
      )
      median = scipy.sparse.csr_matrix(median_dense)
      explainer = shap.KernelExplainer(linear_model.predict, median)
      shap_values = explainer.shap_values(x_test)
  
      def dense_to_sparse_predict(data):
          sparse_data = scipy.sparse.csr_matrix(data)
          return linear_model.predict(sparse_data)
  
      explainer_dense = shap.KernelExplainer(
          dense_to_sparse_predict,
          median_dense.reshape((1, len(median_dense))),
      )
      x_test_dense = x_test.toarray()
      shap_values_dense = explainer_dense.shap_values(x_test_dense)
      # Validate sparse and dense result is the same
      assert np.allclose(
          shap_values, shap_values_dense, rtol=1e-02, atol=1e-01
      )
  
file_path: shap/tests/explainers/test_kernel.py
imports: import numpy
  import pandas
  import scipy.sparse
  import sklearn
  import shap
label_desc: Use image node_id 9 for calling a global function with example usage: test_kernel_shap_with_a1a_sparse_nonzero_background() and returns: linear_model