code: def testPredict(backend):
      # Test that ensemble prediction applies weights correctly to given
      # predictions. There are two possible cases:
      # 1) predictions.shape[0] == len(self.weights_). In this case,
      # predictions include those made by zero-weighted models. Therefore,
      # we simply apply each weights to the corresponding model preds.
      # 2) predictions.shape[0] < len(self.weights_). In this case,
      # predictions exclude those made by zero-weighted models. Therefore,
      # we first exclude all occurrences of zero in self.weights_, and then
      # apply the weights.
      # If none of the above is the case, predict() raises Error.
      ensemble = EnsembleSelection(
          ensemble_size=3,
          task_type=BINARY_CLASSIFICATION,
          random_state=0,
          backend=backend,
          metrics=[accuracy],
      )
      # Test for case 1. Create (3, 2, 2) predictions.
      per_model_pred = np.array(
          [
              [[0.9, 0.1], [0.4, 0.6]],
              [[0.8, 0.2], [0.3, 0.7]],
              [[1.0, 0.0], [0.1, 0.9]],
          ]
      )
      # Weights of 3 hypothetical models
      ensemble.weights_ = [0.7, 0.2, 0.1]
      pred = ensemble.predict(per_model_pred)
      truth = np.array(
          [
              [0.89, 0.11],
              [0.35, 0.65],
          ]  # This should be the true prediction.
      )
      assert np.allclose(pred, truth)
  
      # Test for case 2.
      per_model_pred = np.array(
          [
              [[0.9, 0.1], [0.4, 0.6]],
              [[0.8, 0.2], [0.3, 0.7]],
              [[1.0, 0.0], [0.1, 0.9]],
          ]
      )
      # The third model now has weight of zero.
      ensemble.weights_ = [0.7, 0.2, 0.0, 0.1]
      pred = ensemble.predict(per_model_pred)
      truth = np.array([[0.89, 0.11], [0.35, 0.65]])
      assert np.allclose(pred, truth)
  
      # Test for error case.
      per_model_pred = np.array(
          [
              [[0.9, 0.1], [0.4, 0.6]],
              [[0.8, 0.2], [0.3, 0.7]],
              [[1.0, 0.0], [0.1, 0.9]],
          ]
      )
      # Now the weights have 2 zero weights and 2 non-zero weights,
      # which is incompatible.
      ensemble.weights_ = [0.6, 0.0, 0.0, 0.4]
  
      with pytest.raises(ValueError):
          ensemble.predict(per_model_pred)
  
imports: import numpy
  from autosklearn.constants import BINARY_CLASSIFICATION, REGRESSION
  from autosklearn.ensembles.ensemble_selection import EnsembleSelection
  from autosklearn.metrics import accuracy, root_mean_squared_error
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: testPredict(backend) without return types