code: def test_matrix_scaling_category(uncalibrated_logits_and_labels):
      logits, labels = uncalibrated_logits_and_labels
      matrix_scaling = calibration.MatrixScaling(
          num_classes=logits.shape[-1]
      )
      calibration_result = matrix_scaling.train_calibration(
          logits, labels
      )
      # Matrix scaling may not have a single optimum, so multiple runs could give different results.
      # In this case we don't check any specific values
      # 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 4 for calling a global function with example usage: test_matrix_scaling_category(uncalibrated_logits_and_labels) without return types