code: def test_temperature_scaling_fit_predict():
      x_train = np.array([[1, 1], [2, 3.5]])
      y_train = np.array([[0.9, 0.1], [0.2, 0.8]])
  
      x_val = np.array([[0, 2]])
      y_val = np.array([[0.8, 0.2]])
  
      ts = TemperatureCalibration(epochs=2000)
  
      assert ts.epochs == 2000
      assert ts.temperature == 1.0
      assert len(ts.history) == 0
      assert ts.n_classes is None
  
      ts.fit(x_train=x_train, y_train=y_train)
  
      assert ts.temperature != 1.0
      assert len(ts.history) == 2000
      assert ts.n_classes == 2
  
      ts = TemperatureCalibration(epochs=5000)
  
      assert ts.epochs == 5000
  
      # This will cause early stopping
      ts.fit(x_train=x_train, y_train=y_train, x_val=x_val, y_val=y_val)
  
      assert ts.temperature > 0.0  # temperature should be positive
      assert len(ts.history) < 5000
      assert ts.n_classes == 2
  
      # Check that predict returns data of the same dimensionality as
      # the training data.
      x_test = np.array([[0, 1]])
      y_pred = ts.predict(x=x_test)
  
      assert y_pred.shape == (1, 2)
      assert np.sum(y_pred) == pytest.approx(1.0)
      # Temperature scaling does not change the predicted class
      assert y_pred[0, 1] > y_pred[0, 0]
  
      #
      # Test for binary classification
      #
      x_train = np.array([1, 3.5])
      y_train = np.array([1, 0])
  
      ts = TemperatureCalibration()
  
      #
      ts.fit(x_train=x_train, y_train=y_train)
  
      assert ts.n_classes == 1
  
      # Check that predict returns data of the same dimensionality as
      # the training data.
      x_test = np.array([[0.7]])
      y_pred = ts.predict(x=x_test)
  
      assert y_pred.shape == (1, 1)
  
file_path: stellargraph/tests/test_calibration.py
imports: import pytest
  import numpy
  from stellargraph.calibration import *
label_desc: Use image node_id 2 for calling a global function with example usage: test_temperature_scaling_fit_predict() without return types