code: def test_lightgbm_binary_with_calibrate_decision_threshold(
      fit_helper,
  ):
      """Tests that calibrate_decision_threshold works and does not make the validation score worse on the given metric"""
      fit_args = dict(
          hyperparameters={LGBModel: {}},
      )
      dataset_name = "adult"
  
      predictor = fit_helper.fit_and_validate_dataset(
          dataset_name=dataset_name,
          fit_args=fit_args,
          delete_directory=False,
          refit_full=False,
      )
  
      for metric in [
          None,
          "f1",
          "balanced_accuracy",
          "mcc",
          "recall",
          "precision",
      ]:
          decision_threshold = predictor.calibrate_decision_threshold(
              metric=metric
          )
          if metric is None:
              metric = predictor.eval_metric.name
          assert decision_threshold >= 0
          assert decision_threshold <= 1
  
          X_val, y_val = predictor.load_data_internal(
              data="val", return_X=True, return_y=True
          )
          y_val = predictor.transform_labels(labels=y_val, inverse=True)
  
          y_pred_val = predictor.predict(
              data=X_val, transform_features=False
          )
          y_pred_val_w_decision_threshold = predictor.predict(
              data=X_val,
              decision_threshold=decision_threshold,
              transform_features=False,
          )
          y_pred_multi_val_w_decision_threshold = (
              predictor.predict_multi(
                  data=X_val,
                  decision_threshold=decision_threshold,
                  transform_features=False,
              )
          )
          y_pred_multi_val_w_decision_threshold_cache = (
              predictor.predict_multi(
                  decision_threshold=decision_threshold
              )
          )
  
          y_pred_proba_val = predictor.predict_proba(
              data=X_val, transform_features=False
          )
          y_pred_val_w_decision_threshold_from_proba = (
              predictor.predict_from_proba(
                  y_pred_proba=y_pred_proba_val,
                  decision_threshold=decision_threshold,
              )
          )
  
          assert y_pred_val_w_decision_threshold.equals(
              y_pred_multi_val_w_decision_threshold[
                  predictor.model_best
              ]
          )
          assert y_pred_val_w_decision_threshold.equals(
              y_pred_multi_val_w_decision_threshold_cache[
                  predictor.model_best
              ]
          )
          assert y_pred_val_w_decision_threshold.equals(
              y_pred_val_w_decision_threshold_from_proba
          )
  
          result = predictor.evaluate_predictions(
              y_true=y_val, y_pred=y_pred_val
          )
          result_calibrated = predictor.evaluate_predictions(
              y_true=y_val, y_pred=y_pred_val_w_decision_threshold
          )
  
          # Ensure validation score never becomes worse on the calibrated metric
          assert result[metric] <= result_calibrated[metric]
          if metric in ["recall"]:
              # recall should always be able to achieve a perfect validation score
              assert result_calibrated[metric] == 1.0
  
      assert (
          predictor.calibrate_decision_threshold(metric="roc_auc")
          == 0.5
      )
  
file_path: autogluon/tabular/tests/unittests/models/test_lightgbm.py
imports: from autogluon.core.constants import BINARY, MULTICLASS, REGRESSION
  from autogluon.core.metrics import METRICS
  from autogluon.tabular.models.lgb.lgb_model import LGBModel
label_desc: Use image node_id 8 for calling a global function with example usage: test_lightgbm_binary_with_calibrate_decision_threshold(fit_helper) without return types