class_docstr: The level shifts are handled with regressors in the Silverkite forecasting model.
  This class can generate corresponding regressors to the input dataframe that can be fed into the Silverkite model.
  For every level shift, we create a regressor that has values 0 before it and 1 after it,
  so the model is able to shift at those dates.
  
  The main method to run level shift detection is `detect`.
  The level shift algorithm takes the first order differencing of the data.
  It will calculate the z score on the differenced values.
  If the z score is larger than the predefined threshold,
  the dates will be marked as level shift and corresponding regressors are created.
  For example, if it detects a sudden increase during
  [2020-01-01, 2020-01-03], it will create a regressor column named "ctp_2020_01_02"
  by taking middle of the start and end date of the level shift period.
  for dates before 2020_01_02, values will be set to 0 while after this date, values are 1.
  
  Attributes
  ----------
  df : `pandas.DataFrame`
      The dataframe used for level shift detection.
      It must have two columns:
      ``time_col`` indicating the column of time
      (the format should be able to be parsed by pd.to_datetime),
      and ``value_col`` indicating the column of observed time series values.
  time_col : `str`
      The column name for time column.
  value_col : `str`
      The column name for value column.
  forecast_horizon: `int`
      The number of datapoints to forecast.
      This is used to generate dataframe after adding regressors for level shift.
  freq : `str`
      Frequency of the dataframe such as "D" for daily and "W" for weekly.
      The allowed values can be found in the TimeSeriesFrequency Enum object.
  z_score_cutoff : `int`
      The z score cutoff value to define the level shift.
      By default is 3.
  df_shift : `pandas.DataFrame`
      Dataframe with additional columns calculated by levelshift algorithm:
      column "actual_diff" represents the abs of the first order differencing,
      column "zscore" of actual_diff of the two adjacent dates.
      This dataframe will be used for function `plot_level_shift`.
  shift_dates : `list`
      The shift start and end date. below is an example:
      [(Timestamp("2020-01-11 00:00:00"), Timestamp("2020-01-12 00:00:00")),
          (Timestamp("2020-01-21 00:00:00"), Timestamp("2020-01-21 00:00:00"))].
  regressor_col : `list`
      List of names of the regressor columns which will start with `LEVELSHIFT_COL_PREFIX_SHORT`
      E.g. ["ctp_2020_01_11"]
  final_df : `pandas.DataFrame`
      Dataframe with regressor columns which is expanded to future dates based on ``forecast_horizon``.
      For example, if the input has 2 rows and forecast_horizon = 1,
      it will create a new row with ``value_col`` = NaN and a few regressor columns of the level shift detected.
  
  Methods
  -------
  detect : callable
      Runs shift detection algorithm and create dataframe with levelshift
      regressor columns for a given time series df.
  plot_level_shift : callable
      Plots the results after running fucntion `find_shifts` or `detect`.
  find_shifts : callable
      Finds the start and end dates of the level shift for a given time series df.
  create_df_with_regressor : callable
      Appends level shift regressor column to a given time series df.
  create_regressor_for_future_dates : callable
      Creates future dates with level shift regressor columns
      to a given time series df.
class_docstr_tok: ["The","level","shifts","are","handled","with","regressors","in","the","Silverkite","forecasting","model",".","This","class","can","generate","corresponding","regressors","to","the","input","dataframe","that","can","be","fed","into","the","Silverkite","model",".","For","every","level","shift",",","we","create","a","regressor","that","has","values","0","before","it","and","1","after","it",",","so","the","model","is","able","to","shift","at","those","dates",".","The","main","method","to","run","level","shift","detection","is","`","detect","`",".","The","level","shift","algorithm","takes","the","first","order","differencing","of","the","data",".","It","will","calculate","the","z","score","on","the","differenced","values",".","If","the","z","score","is","larger","than","the","predefined","threshold",",","the","dates","will","be","marked","as","level","shift","and","corresponding","regressors","are","created",".","For","example",",","if","it","detects","a","sudden","increase","during","[","2020-01-01",",","2020-01-03","]",",","it","will","create","a","regressor","column","named","``","ctp_2020_01_02","''","by","taking","middle","of","the","start","and","end","date","of","the","level","shift","period",".","for","dates","before","2020_01_02",",","values","will","be","set","to","0","while","after","this","date",",","values","are","1",".","Attributes","--","--","--","--","--","df",":","`","pandas.DataFrame","`","The","dataframe","used","for","level","shift","detection",".","It","must","have","two","columns",":","``","time_col","``","indicating","the","column","of","time","(","the","format","should","be","able","to","be","parsed","by","pd.to_datetime",")",",","and","``","value_col","``","indicating","the","column","of","observed","time","series","values",".","time_col",":","`","str","`","The","column","name","for","time","column",".","value_col",":","`","str","`","The","column","name","for","value","column",".","forecast_horizon",":","`","int","`","The","number","of","datapoints","to","forecast",".","This","is","used","to","generate","dataframe","after","adding","regressors","for","level","shift",".","freq",":","`","str","`","Frequency","of","the","dataframe","such","as","``","D","''","for","daily","and","``","W","''","for","weekly",".","The","allowed","values","can","be","found","in","the","TimeSeriesFrequency","Enum","object",".","z_score_cutoff",":","`","int","`","The","z","score","cutoff","value","to","define","the","level","shift",".","By","default","is","3.","df_shift",":","`","pandas.DataFrame","`","Dataframe","with","additional","columns","calculated","by","levelshift","algorithm",":","column","``","actual_diff","''","represents","the","abs","of","the","first","order","differencing",",","column","``","zscore","''","of","actual_diff","of","the","two","adjacent","dates",".","This","dataframe","will","be","used","for","function","`","plot_level_shift","`",".","shift_dates",":","`","list","`","The","shift","start","and","end","date",".","below","is","an","example",":","[","(","Timestamp","(","``","2020-01-11","00:00:00","''",")",",","Timestamp","(","``","2020-01-12","00:00:00","''",")",")",",","(","Timestamp","(","``","2020-01-21","00:00:00","''",")",",","Timestamp","(","``","2020-01-21","00:00:00","''",")",")","]",".","regressor_col",":","`","list","`","List","of","names","of","the","regressor","columns","which","will","start","with","`","LEVELSHIFT_COL_PREFIX_SHORT","`","E.g",".","[","``","ctp_2020_01_11","''","]","final_df",":","`","pandas.DataFrame","`","Dataframe","with","regressor","columns","which","is","expanded","to","future","dates","based","on","``","forecast_horizon","``",".","For","example",",","if","the","input","has","2","rows","and","forecast_horizon","=","1",",","it","will","create","a","new","row","with","``","value_col","``","=","NaN","and","a","few","regressor","columns","of","the","level","shift","detected",".","Methods","--","--","--","-","detect",":","callable","Runs","shift","detection","algorithm","and","create","dataframe","with","levelshift","regressor","columns","for","a","given","time","series","df",".","plot_level_shift",":","callable","Plots","the","results","after","running","fucntion","`","find_shifts","`","or","`","detect","`",".","find_shifts",":","callable","Finds","the","start","and","end","dates","of","the","level","shift","for","a","given","time","series","df",".","create_df_with_regressor",":","callable","Appends","level","shift","regressor","column","to","a","given","time","series","df",".","create_regressor_for_future_dates",":","callable","Creates","future","dates","with","level","shift","regressor","columns","to","a","given","time","series","df","."]
docstr: Makes a plot to show the observations with level shifts.
  
  Attributes
  ----------
  None
  
  Returns
  ----------
  fig : `plotly.graph_objects.Figure` The plot object.
docstr_tok: ["Makes","a","plot","to","show","the","observations","with","level","shifts",".","Attributes","--","--","--","--","--","None","Returns","--","--","--","--","--","fig",":","`","plotly.graph_objects.Figure","`","The","plot","object","."]
code: def plot_level_shift(self):
      """Makes a plot to show the observations with level shifts.
  
      Attributes
      ----------
      None
  
      Returns
      ----------
      fig : `plotly.graph_objects.Figure` The plot object.
      """
      if self.df_shift is not None and self.time_col is not None:
          fig = plot_multivariate(self.df_shift, self.time_col)
          for pair in self.shift_dates:
              fig.add_vrect(
                  x0=pair[0], x1=pair[1], fillcolor="red", opacity=0.2
              )
          fig.show()
      else:
          warnings.warn(
              "please run either detect() or find_shifts() first."
          )
  
file_path: greykite/greykite/algo/changepoint/shift_detection/shift_detector.py
imports: import re
  import warnings
  from datetime import datetime
  from enum import Enum
  from typing import List
  from typing import Optional
  import pandas
  from greykite.common.constants import LEVELSHIFT_COL_PREFIX_SHORT
  from greykite.common.viz.timeseries_plotting import plot_multivariate
label_desc: Use image node_id 3 for calling the ShiftDetection obj's underlying member method code with example usage: obj.plot_level_shift() without return types