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: See class docstring for details on parameters / attributes.
  
  Note that in this case, the default of `trim_percent` is None, rather than
  `TRIM_PERCENT` used in the base class.
  This is because in this method, trimming is not necessary as the logic
  uses quantiles (which are robust to outliers).
docstr_tok: ["See","class","docstring","for","details","on","parameters","\/","attributes",".","Note","that","in","this","case",",","the","default","of","`","trim_percent","`","is","None",",","rather","than","`","TRIM_PERCENT","`","used","in","the","base","class",".","This","is","because","in","this","method",",","trimming","is","not","necessary","as","the","logic","uses","quantiles","(","which","are","robust","to","outliers",")","."]
code: def __init__(
      self,
      tukey_cutoff=TUKEY_CUTOFF,
      iqr_lower=IQR_LOWER,
      iqr_upper=IQR_UPPER,
      trim_percent=None,
      diff_method=MOVING_MEDIAN,
  ):
      """See class docstring for details on parameters / attributes.
  
      Note that in this case, the default of `trim_percent` is None, rather than
      `TRIM_PERCENT` used in the base class.
      This is because in this method, trimming is not necessary as the logic
      uses quantiles (which are robust to outliers).
      """
      self.tukey_cutoff = tukey_cutoff
      self.iqr_lower = iqr_lower
      self.iqr_upper = iqr_upper
  
      super().__init__(
          trim_percent=trim_percent, diff_method=diff_method
      )
  
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 1 to create a new TukeyOutlierDetector object from inherited base classes: BaseOutlierDetector with example: obj = TukeyOutlierDetector(tukey_cutoff, iqr_lower, iqr_upper, trim_percent, diff_method)