code: def assert_attention_over_area(expl, area):
      """
      Check that the explanation 'expl' lights up the most over 'area',
      a tuple of (x1, x2, y1, y2), starting and ending points of the bounding rectangle
      in the original image.
      We make two assumptions in this test:
      1. The model can classify the example image correctly.
      2. The area specified by the tester over the example image covers the predicted class correctly.
      """
      image = expl.image
      heatmap = expl.targets[0].heatmap
  
      # fit heatmap over image
      heatmap = expand_heatmap(heatmap, image, Image.LANCZOS)
      heatmap = np.array(heatmap)
  
      # get a slice of the area
      x1, x2, y1, y2 = area
      crop = heatmap[y1:y2, x1:x2]  # row-first ordering
      # TODO: instead of hard-coding the height and width offsets
      # it might be a better idea to use percentages
      # this makes the tests independent of any resizing done on the image
      # and the heatmap doesn't have to be resized
      # however, it might be harder for the user to determine percentages
  
      # check intensity
      total_intensity = np.sum(heatmap)
      crop_intensity = np.sum(crop)
      p = total_intensity / 100  # -> 1% of total_intensity
      crop_p = crop_intensity / p  # -> intensity %
      # at least 50% (need to experiment with this number)
      assert 50 < crop_p
  
file_path: eli5/tests/test_keras_integration.py
imports: from __future__ import print_function
  import pytest
  import numpy
  from PIL import Image
  from keras.applications import mobilenet_v2
  from keras.models import Sequential
  import eli5
  from eli5.base import Explanation
  from eli5 import format_as_image
  from eli5.formatters.image import expand_heatmap
  from .utils_image import assert_pixel_by_pixel_equal
label_desc: Use image node_id 4 for calling a global function with example usage: assert_attention_over_area(expl, area) without return types