code: def test_explain_regression_hashing_vectorizer(
      newsgroups_train_binary,
  ):
      docs, y, target_names = newsgroups_train_binary
      vec = HashingVectorizer(norm=None)
      clf = LinearRegression()
      clf.fit(vec.fit_transform(docs), y)
  
      # Setting large "top" in order to compare it with CountVectorizer below
      # (due to small differences in the coefficients they might have cutoffs
      # at different points).
      res = explain_prediction(
          clf,
          docs[0],
          vec=vec,
          target_names=[target_names[1]],
          top=1000,
      )
      expl, _ = format_as_all(res, clf)
      assert len(res.targets) == 1
      e = res.targets[0]
      assert e.target == "comp.graphics"
      neg = get_all_features(e.feature_weights.neg)
      assert "objective" in neg
      assert "that" in neg
      assert "comp.graphics" in expl
      assert "objective" in expl
      assert "that" in expl
  
      # HashingVectorizer with norm=None is "the same" as CountVectorizer,
      # so we can compare it and check that explanation is almost the same.
      count_vec = CountVectorizer()
      count_clf = LinearRegression()
      count_clf.fit(count_vec.fit_transform(docs), y)
      count_res = explain_prediction(
          count_clf,
          docs[0],
          vec=count_vec,
          target_names=[target_names[1]],
          top=1000,
      )
      pprint(count_res)
      count_expl, _ = format_as_all(count_res, count_clf)
      print(count_expl)
  
      for key in ["pos", "neg"]:
          values, count_values = [
              sorted(
                  get_names_coefs(
                      getattr(r.targets[0].feature_weights, key)
                  )
              )
              for r in [res, count_res]
          ]
          assert len(values) == len(count_values)
          for (name, coef), (count_name, count_coef) in zip(
              values, count_values
          ):
              assert name == count_name
              assert abs(coef - count_coef) < 0.05
  
imports: from __future__ import absolute_import
  from pprint import pprint
  import attr
  import pytest
  from sklearn.base import BaseEstimator
  from sklearn.feature_extraction import DictVectorizer
  from sklearn.feature_extraction.text import CountVectorizer, HashingVectorizer
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model import LogisticRegression
  from sklearn.pipeline import FeatureUnion
  from eli5 import explain_prediction, explain_weights
  from eli5.formatters import format_as_html
  from eli5.sklearn import invert_hashing_and_fit, InvertableHashingVectorizer
  from .utils import format_as_all, get_all_features, get_names_coefs, write_html
label_desc: Use image node_id 7 for calling a global function with example usage: test_explain_regression_hashing_vectorizer(newsgroups_train_binary) without return types