code: def f1_score(
      y_true: Union[
          pd.Series,
          pd.DataFrame,
          List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]],
          Dict[
              str,
              List[
                  Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]
              ],
          ],
      ],
      y_pred: Union[
          pd.Series,
          pd.DataFrame,
          List[Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]],
          Dict[
              str,
              List[
                  Union[Tuple[pd.Timestamp, pd.Timestamp], pd.Timestamp]
              ],
          ],
      ],
      recall_thresh: float = 0.5,
      precision_thresh: float = 0.5,
  ) -> Union[float, Dict[str, float]]:
      """F1 score of prediction.
  
      F1 score is the harmonic mean of precision and recall. For more details
      about precision and recall, please refer to function `precision` and
      `recall`.
  
      Parameters
      ----------
      y_true: pandas Series or DataFrame, list, or dict
          Labels or lists of true anomalies.
  
          - If pandas Series, it is treated as binary labels along time index.
          - If pandas DataFrame, each column is a binary series and is treated as
            an independent type of anomaly.
          - If list, a list of events where an event is a pandas Timestamp if it
            is instantaneous or a 2-tuple of pandas Timestamps if it is a closed
            time interval.
          - If dict, each key-value pair is a list of events and is treated as an
            independent type of anomaly.
  
      y_pred: pandas Series or DataFrame, list, or dict
          Labels or lists of predicted anomalies.
  
          - If pandas Series, it is treated as binary labels along time index.
          - If pandas DataFrame, each column is a binary series and is treated as
            an independent type of anomaly.
          - If list, a list of events where an event is a pandas Timestamp if it
            is instantaneous or a 2-tuple of pandas Timestamps if it is a closed
            time interval.
          - If dict, each key-value pair is a list of events and is treated as an
            independent type of anomaly.
  
      recall_thresh: float, optional
          Threshold of recall calculation. Only used if input is list or dict.
          For more details, please refer to function `recall`. Default: 0.5.
  
      precision_thresh: float, optional
          Threshold of precision calculation. Only used if input is list or dict.
          For more details, please refer to function `precision`. Default: 0.5.
  
      Returns
      -------
      float or dict
          Score(s) for each type of anomaly.
  
      """
      recall_score = recall(y_true, y_pred, recall_thresh)
      precision_score = precision(y_true, y_pred, precision_thresh)
      if isinstance(recall_score, float) and isinstance(
          precision_score, float
      ):
          if recall_score + precision_score != 0:
              return (
                  2
                  * recall_score
                  * precision_score
                  / (recall_score + precision_score)
              )
          else:
              return float("nan")
      elif isinstance(recall_score, dict) and isinstance(
          precision_score, dict
      ):
          return {
              key: (
                  (
                      2
                      * recall_score[key]
                      * precision_score[key]
                      / (recall_score[key] + precision_score[key])
                  )
                  if (recall_score[key] + precision_score[key] != 0)
                  else float("nan")
              )
              for key in recall_score.keys()
          }
      else:
          raise RuntimeError("This error is not supposed to be hit.")
  
imports: from typing import Dict, List, Tuple, Union, overload
  import pandas
  from ..aggregator import AndAggregator, OrAggregator
  from ..data import validate_events
label_desc: Use image node_id 15 for calling a global function with example usage: f1_score(y_true, y_pred, recall_thresh, precision_thresh) and returns: unknown, float, unknown