class_docstr: This is a class for detecting one-dimensional outliers.
  This uses the celebrated outlier definition of John Tukey (and named here as such in his recognition):
  Reference: Tukey, J.W., Exploratory data analysis. Addison-Wesley, Reading, 1977
  
  Note: In Tukey's work:
  
      - `iqr_lower = 0.25` which is the first quartile
      - `iqr_upper = 0.75` which is the third quartile
  
  Here we let user specify them and defaults are different.
  Therefore the naming IQR (inter-quartile range)
  is an imperfect naming. However, we think this naming is very widely used and
  it is not worth to come up with new naming.
  
  For this method:
  
  - `DetectionResult.scores` are defined as:
  
      - score is zero if the value is within the IQR
      - score is postive if the value is above the IQR.
          It is the difference from the IQR upper bound devided by IQR length.
      - score is negative if the value is below the IQR.
          It is the difference from the IQR lower bound devided by IQR length.
  
      Exception: when IQR = 0, we need to handle it.
  
          - If there is no diff with the corresponding quantile, we set: `score = 0`
          - If there is a diff with corresponding quantile, we set: `score = 2 * tukey_cutoff`
              multiplied by the sign of the difference.
  
  - `DetectionResult.is_outlier` are defined as: scores which are off by more than `tukey_cutoff`.
  
  This is a child of `~greykite.common.features.outlier.BaseOutlierDetector`,
  which already implements a few processing steps which are useful across
  various outlier detection methods:
  
      - `remove_na`: removing NAs
      - `trim`: trimming the data. This is useful for example when using z-score
      - `diff_from_baseline`: fitting a simple baseline and differencing the input from baseline.
  
  Parameters:
  ----------
  tukey_cutoff : `float`, default `TUKEY_CUTOFF`
      The Tukey cutoff for deciding what is an anomaly.
  iqr_lower : float`, default `IQR_LOWER`
      The smaller quantile used in IQR calculation.
  iqr_upper : float, default `IQR_UPPER`
      The larger quantile used in IQR calculation.
  
  Attribute
  ---------
  fitted_param: `dict` or None, default None
      This is updated after `self.fit` is run on data.
      This dictionary stores:
  
          - "quantile_value_lower": `float` or None, default None
              The lower bound of Tukey IQR.
          - "quantile_value_upper": `float` or None, default None
              The upper bound of Tukey IQR.
          - "iqr": `float` or None, default None
              The Tukey IQR (inter-quartile range).
  
  Other Parameters and Attributes:
      See `~greykite.common.features.outlier.BaseOutlierDetector` docstring.
class_docstr_tok: ["This","is","a","class","for","detecting","one-dimensional","outliers",".","This","uses","the","celebrated","outlier","definition","of","John","Tukey","(","and","named","here","as","such","in","his","recognition",")",":","Reference",":","Tukey",",","J.W.",",","Exploratory","data","analysis",".","Addison-Wesley",",","Reading",",","1977","Note",":","In","Tukey","'s","work",":","-","`","iqr_lower","=","0.25","`","which","is","the","first","quartile","-","`","iqr_upper","=","0.75","`","which","is","the","third","quartile","Here","we","let","user","specify","them","and","defaults","are","different",".","Therefore","the","naming","IQR","(","inter-quartile","range",")","is","an","imperfect","naming",".","However",",","we","think","this","naming","is","very","widely","used","and","it","is","not","worth","to","come","up","with","new","naming",".","For","this","method",":","-","`","DetectionResult.scores","`","are","defined","as",":","-","score","is","zero","if","the","value","is","within","the","IQR","-","score","is","postive","if","the","value","is","above","the","IQR",".","It","is","the","difference","from","the","IQR","upper","bound","devided","by","IQR","length",".","-","score","is","negative","if","the","value","is","below","the","IQR",".","It","is","the","difference","from","the","IQR","lower","bound","devided","by","IQR","length",".","Exception",":","when","IQR","=","0",",","we","need","to","handle","it",".","-","If","there","is","no","diff","with","the","corresponding","quantile",",","we","set",":","`","score","=","0","`","-","If","there","is","a","diff","with","corresponding","quantile",",","we","set",":","`","score","=","2","*","tukey_cutoff","`","multiplied","by","the","sign","of","the","difference",".","-","`","DetectionResult.is_outlier","`","are","defined","as",":","scores","which","are","off","by","more","than","`","tukey_cutoff","`",".","This","is","a","child","of","`","~greykite.common.features.outlier.BaseOutlierDetector","`",",","which","already","implements","a","few","processing","steps","which","are","useful","across","various","outlier","detection","methods",":","-","`","remove_na","`",":","removing","NAs","-","`","trim","`",":","trimming","the","data",".","This","is","useful","for","example","when","using","z-score","-","`","diff_from_baseline","`",":","fitting","a","simple","baseline","and","differencing","the","input","from","baseline",".","Parameters",":","--","--","--","--","--","tukey_cutoff",":","`","float","`",",","default","`","TUKEY_CUTOFF","`","The","Tukey","cutoff","for","deciding","what","is","an","anomaly",".","iqr_lower",":","float","`",",","default","`","IQR_LOWER","`","The","smaller","quantile","used","in","IQR","calculation",".","iqr_upper",":","float",",","default","`","IQR_UPPER","`","The","larger","quantile","used","in","IQR","calculation",".","Attribute","--","--","--","--","-","fitted_param",":","`","dict","`","or","None",",","default","None","This","is","updated","after","`","self.fit","`","is","run","on","data",".","This","dictionary","stores",":","-","``","quantile_value_lower","''",":","`","float","`","or","None",",","default","None","The","lower","bound","of","Tukey","IQR",".","-","``","quantile_value_upper","''",":","`","float","`","or","None",",","default","None","The","upper","bound","of","Tukey","IQR",".","-","``","iqr","''",":","`","float","`","or","None",",","default","None","The","Tukey","IQR","(","inter-quartile","range",")",".","Other","Parameters","and","Attributes",":","See","`","~greykite.common.features.outlier.BaseOutlierDetector","`","docstring","."]
docstr: The logic of outlier detection, after `fit` is done.
  This method uses the fit information to decide which points are
  outliers and what should be their score.
  
  This is an abstract method of the base class:
  `~greykite.common.features.outlier.BaseOutlierDetector`
  and it is implemented for Tukey method here.
  
  For this method:
      - `DetectionResult.scores` are defined as:
  
          - score is zero if the value is within the IQR
          - score is postive if the value is above the IQR.
              It is the difference from the IQR upper bound devided by IQR length.
          - score is negative id the value is below the IQR.
              It is the difference from the IQR lower bound devided by IQR length.
  
      - `DetectionResult.is_outlier` are defined as: scores which are off by more than `tukey_cutoff`.
  
  Parameters
  ----------
  y_new : `pandas.series`
      A series of floats. This is the input series to be labeled.
  
  Returns
  -------
  result : `~greykite.common.features.outlier.DetectionResult`
      Includes the outlier detection results (see the data class attributes).
docstr_tok: ["The","logic","of","outlier","detection",",","after","`","fit","`","is","done",".","This","method","uses","the","fit","information","to","decide","which","points","are","outliers","and","what","should","be","their","score",".","This","is","an","abstract","method","of","the","base","class",":","`","~greykite.common.features.outlier.BaseOutlierDetector","`","and","it","is","implemented","for","Tukey","method","here",".","For","this","method",":","-","`","DetectionResult.scores","`","are","defined","as",":","-","score","is","zero","if","the","value","is","within","the","IQR","-","score","is","postive","if","the","value","is","above","the","IQR",".","It","is","the","difference","from","the","IQR","upper","bound","devided","by","IQR","length",".","-","score","is","negative","id","the","value","is","below","the","IQR",".","It","is","the","difference","from","the","IQR","lower","bound","devided","by","IQR","length",".","-","`","DetectionResult.is_outlier","`","are","defined","as",":","scores","which","are","off","by","more","than","`","tukey_cutoff","`",".","Parameters","--","--","--","--","--","y_new",":","`","pandas.series","`","A","series","of","floats",".","This","is","the","input","series","to","be","labeled",".","Returns","--","--","--","-","result",":","`","~greykite.common.features.outlier.DetectionResult","`","Includes","the","outlier","detection","results","(","see","the","data","class","attributes",")","."]
code: def detect_logic(self, y_new):
      """The logic of outlier detection, after `fit` is done.
      This method uses the fit information to decide which points are
      outliers and what should be their score.
  
      This is an abstract method of the base class:
      `~greykite.common.features.outlier.BaseOutlierDetector`
      and it is implemented for Tukey method here.
  
      For this method:
          - `DetectionResult.scores` are defined as:
  
              - score is zero if the value is within the IQR
              - score is postive if the value is above the IQR.
                  It is the difference from the IQR upper bound devided by IQR length.
              - score is negative id the value is below the IQR.
                  It is the difference from the IQR lower bound devided by IQR length.
  
          - `DetectionResult.is_outlier` are defined as: scores which are off by more than `tukey_cutoff`.
  
      Parameters
      ----------
      y_new : `pandas.series`
          A series of floats. This is the input series to be labeled.
  
      Returns
      -------
      result : `~greykite.common.features.outlier.DetectionResult`
          Includes the outlier detection results (see the data class attributes).
      """
      scores = pd.Series([0.0] * len(y_new), dtype=float)
      is_outlier = pd.Series([False] * len(y_new))
  
      # if IQR is zero, we will not detect any outlier and return.
      if self.fitted_param["iqr"] == 0:
          return DetectionResult(scores=scores, is_outlier=is_outlier)
  
      # First, we find the anchor point for calculating the score.
      # If the point is too large then the upper quantile will be the anchor point.
      # If the point is too small then the lower quantole will be the anchor point.
      for i in range(len(y_new)):
          if y_new[i] < self.fitted_param["quantile_value_lower"]:
              anchor = self.fitted_param["quantile_value_lower"]
              score = y_new[i] - anchor
          elif y_new[i] > self.fitted_param["quantile_value_upper"]:
              anchor = self.fitted_param["quantile_value_upper"]
              score = y_new[i] - anchor
          else:
              anchor = None
              score = 0
  
          scores[i] = float(score) / float(self.fitted_param["iqr"])
  
      is_outlier = np.abs(scores) > self.tukey_cutoff
      return DetectionResult(scores=scores, is_outlier=is_outlier)
  
imports: import warnings
  from abc import abstractmethod
  from dataclasses import dataclass
  from dataclasses import field
  from typing import Optional
  import numpy
  import pandas
label_desc: Use image node_id 3 for calling the TukeyOutlierDetector obj's underlying member method code with example usage: obj.detect_logic(y_new) and returns: DetectionResult, DetectionResult