code: def assert_trained_linear_regression_explained(
      x,
      feature_names,
      reg,
      explain_prediction,
      atol=1e-8,
      reg_has_intercept=None,
  ):
      res = explain_prediction(reg, x, feature_names=feature_names)
      expl_text, expl_html = expls = format_as_all(res, reg)
  
      assert len(res.targets) == 1
      target = res.targets[0]
      assert target.target == "y"
      get_pos_neg_features = lambda fw: (
          get_all_features(fw.pos, with_weights=True),
          get_all_features(fw.neg, with_weights=True),
      )
      pos, neg = get_pos_neg_features(target.feature_weights)
      assert "LSTAT" in pos or "LSTAT" in neg
  
      if reg_has_intercept is None:
          reg_has_intercept = has_intercept(reg)
      if reg_has_intercept:
          assert "<BIAS>" in pos or "<BIAS>" in neg
          assert "<BIAS>" in expl_text
          assert "&lt;BIAS&gt;" in expl_html
      else:
          assert "<BIAS>" not in pos and "<BIAS>" not in neg
          assert "<BIAS>" not in expl_text
          assert "BIAS" not in expl_html
  
      for expl in [expl_text, expl_html]:
          assert "LSTAT" in expl
          assert "(score" in expl
      assert "'y'" in expl_text
      assert "<b>y</b>" in strip_blanks(expl_html)
  
      for expl in expls:
          assert_feature_values_present(expl, feature_names, x)
  
      assert res == explain_prediction(
          reg, x, feature_names=feature_names
      )
      check_targets_scores(res, atol=atol)
  
      flt_res = explain_prediction(
          reg,
          x,
          feature_names=feature_names,
          feature_filter=lambda name, v: name != "LSTAT",
      )
      format_as_all(flt_res, reg)
      flt_target = flt_res.targets[0]
      flt_pos, flt_neg = get_pos_neg_features(
          flt_target.feature_weights
      )
      assert "LSTAT" not in flt_pos and "LSTAT" not in flt_neg
      flt_all = dict(flt_pos, **flt_neg)
      expected = dict(pos, **neg)
      expected.pop("LSTAT")
      assert flt_all == expected
  
imports: from __future__ import absolute_import
  from functools import partial
  from pprint import pprint
  import re
  from typing import List
  import pytest
  import numpy
  from sklearn.base import BaseEstimator
  from sklearn.datasets import make_regression
  from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
  from sklearn.ensemble import ExtraTreesClassifier, ExtraTreesRegressor, GradientBoostingClassifier, GradientBoostingRegressor, RandomForestClassifier, RandomForestRegressor
  from sklearn.linear_model import ElasticNet, ElasticNetCV, HuberRegressor, Lars, LarsCV, Lasso, LassoCV, LassoLars, LassoLarsCV, LassoLarsIC, LinearRegression, LogisticRegression, LogisticRegressionCV, OrthogonalMatchingPursuit, OrthogonalMatchingPursuitCV, PassiveAggressiveClassifier, PassiveAggressiveRegressor, Perceptron, Ridge, RidgeClassifier, RidgeClassifierCV, RidgeCV, SGDClassifier, SGDRegressor, TheilSenRegressor
  from sklearn.svm import LinearSVC, LinearSVR, SVC, SVR, NuSVC, NuSVR, OneClassSVM
  from sklearn.multiclass import OneVsRestClassifier
  from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
  from eli5 import explain_prediction, explain_prediction_sklearn
  from eli5.base import Explanation
  from eli5.formatters import format_as_text, fields
  from eli5.sklearn.utils import has_intercept
  from .utils import format_as_all, strip_blanks, get_all_features, check_targets_scores, SGD_KWARGS
label_desc: Use image node_id 4 for calling a global function with example usage: assert_trained_linear_regression_explained(x, feature_names, reg, explain_prediction, atol, reg_has_intercept) without return types