code: def test_iqr_detector():
      """Tests `TukeyDetector` class.
      This test is to demonstrate the usage of the `Detector` class."""
  
      def reward_func(data):
          f1 = f1_score(y_true=data.y_true, y_pred=data.y_pred)
          return f1[True]
  
      reward = Reward(reward_func=reward_func)
  
      np.random.seed(seed=1317)
      normal_size = 300
      anomaly_size = 10
      anomalies = np.random.normal(loc=0, scale=5, size=anomaly_size)
      df = pd.DataFrame(
          {
              "y": list(anomalies)
              + list(np.random.normal(size=normal_size)),
              "is_anomaly": [True] * anomaly_size
              + [False] * normal_size,
          }
      )
  
      new_df = pd.DataFrame(
          {"y": [500, -10, -100, 0, 0.1, -0.2, 0.3, 200, 8]}
      )
  
      detector = TukeyDetector(
          is_anomaly_col="is_anomaly", value_col="y", reward=reward
      )
  
      detector.fit(data=Data(df=df))
  
      param_full = detector.fit_info["param_full"]
      assert round(param_full["iqr"], 2) == 1.37
      assert round(param_full["iqr_coef"], 2) == 1.8
      assert round(param_full["q1"], 3) == -0.627
      assert round(param_full["q3"], 3) == 0.739
      assert round(param_full["lower"], 2) == -3.09
      assert round(param_full["upper"], 2) == 3.20
  
      param_obj_list = detector.fit_info["param_obj_list"]
      param_obj_df = pd.DataFrame.from_records(param_obj_list)
      fig = plot_lines_markers(
          df=param_obj_df, x_col="iqr_coef", line_cols=["obj_value"]
      )
      fig.layout.update(
          title="'TukeyDetector' parameter search for iqr_coef"
      )
      assert fig is not None
      # fig.show()
  
      assert detector.fit_info is not None
      assert detector.fitted_df is not None
      pred_data = detector.predict(data=Data(df=new_df))
      y_pred = pred_data.y_pred
  
      assert np.allclose(
          y_pred, np.array([True] * 3 + [False] * 4 + [True] * 2)
      )
  
imports: import numpy
  import pandas
  import pytest
  from scipy import stats
  from greykite.common.constants import PREDICTED_ANOMALY_COL
  from greykite.common.viz.timeseries_annotate import plot_lines_markers
  from greykite.detection.common.ad_evaluation import f1_score
  from greykite.detection.detector.data import DetectorData
  from greykite.detection.detector.detector import Detector
  from greykite.detection.detector.detector import build_anomaly_percent_reward
  from greykite.detection.detector.optimizer import CalcResult
  from greykite.detection.detector.reward import Reward
label_desc: Use image node_id 4 for calling a global function with example usage: test_iqr_detector() and returns: f1