code: def test_temperature_scaling_binary(uncalibrated_logits_and_labels):
      logits, labels = uncalibrated_logits_and_labels
      # Selects one category of the 3-class test fixture to treat as a binary classifier.
      binary_logits = logits[:, 1]
      binary_labels = labels == 1
      temperature_scaling = calibration.TemperatureScaling(binary=True)
      calibration_result = temperature_scaling.train_calibration(
          binary_logits, binary_labels
      )
      # Checks that we got close to optimal temperature
      assert temperature_scaling.temperature.item() == pytest.approx(
          8.3, EPSILON
      )
      # Checks that negative log-likelhood and expected calibration error are the same or lower post-calibration.
      assert (
          calibration_result.after_calibration_nll
          <= calibration_result.before_calibration_nll
      )
      assert (
          calibration_result.after_calibration_ece
          <= calibration_result.before_calibration_ece
      )
  
imports: import numpy
  import pytest
  from ludwig.utils import calibration
label_desc: Use image node_id 2 for calling a global function with example usage: test_temperature_scaling_binary(uncalibrated_logits_and_labels) without return types