code: def _check_stacked_overfitting_for_models(
      best_non_affected_model: str,
      best_affected_model: str,
      leaderboard: pd.DataFrame,
  ) -> bool:
      """
      Determine whether stacked overfitting occurred for the given two models and a leaderboard containing their scores.
  
      Stacked overfitting occurred, if the validation score of the `best_non_affected_model` is lower than the validation score of the `best_affected_model`
      while the test score of the `best_affected_model` is lower or equal to the test score of `best_non_affected_model`.
  
      Parameters
      ----------
      best_non_affected_model : str
          Name of the best model, based on validation score, that is not affected by stacked overfitting in principle.
      best_affected_model : str
          Name of the best model, based on validation score, that is affected by stacked overfitting in principle.
      leaderboard : pd.DataFrame
          A leaderboard produced by `predictor.leaderboard(test_data)`.
          The leaderboard needs to contain `score_val` and `model` as columns.
  
      Returns
      -------
      Bool that is True if stacked overfitting occurred, otherwise False.
      """
      score_non_affected_val = leaderboard.loc[
          leaderboard["model"] == best_non_affected_model, "score_val"
      ].iloc[0]
      score_non_affected_test = leaderboard.loc[
          leaderboard["model"] == best_non_affected_model, "score_test"
      ].iloc[0]
  
      score_affected_val = leaderboard.loc[
          leaderboard["model"] == best_affected_model, "score_val"
      ].iloc[0]
      score_affected_test = leaderboard.loc[
          leaderboard["model"] == best_affected_model, "score_test"
      ].iloc[0]
  
      # l1 worse val score than l2+
      stacked_overfitting = score_non_affected_val < score_affected_val
      # l2+ worse test score than L1
      stacked_overfitting = stacked_overfitting and (
          score_non_affected_test >= score_affected_test
      )
  
      return stacked_overfitting
  
imports: import logging
  from typing import List, Tuple
  import pandas
label_desc: Use image node_id 3 for calling a global function with example usage: _check_stacked_overfitting_for_models(best_non_affected_model, best_affected_model, leaderboard) and returns: stacked_overfitting