{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# [EDA] Investigate ts features😪🌟\n---\n## [Objective]\n### In order to investigate feature engineering, make features & Visualize time series data.","metadata":{}},{"cell_type":"markdown","source":"# 1. 📚 Import Libraries","metadata":{}},{"cell_type":"code","source":"# ====================================================\n# Library\n# ====================================================\n# general\nimport os, gc, re, ast, sys, copy, json, math\nimport time, string, pickle, random, joblib, itertools\nfrom pathlib import Path\nfrom typing import List\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n# matrix calc\nimport scipy as sp\nimport numpy as np\nimport pandas as pd\nimport polars as pl\npd.set_option('display.max_rows', 500)\npd.set_option('display.max_columns', 500)\npd.set_option('display.width', 1000)\nfrom tqdm.auto import tqdm\n\n# visualization\nimport matplotlib.pyplot as plt\nplt.style.use('ggplot')\n%matplotlib inline\nimport seaborn as sns\n\n# get date\nimport datetime\ndate = datetime.datetime.now().strftime(\"%Y%m%d\")\nprint(date)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-02T12:06:16.481900Z","iopub.execute_input":"2023-11-02T12:06:16.482271Z","iopub.status.idle":"2023-11-02T12:06:19.132897Z","shell.execute_reply.started":"2023-11-02T12:06:16.482240Z","shell.execute_reply":"2023-11-02T12:06:19.131411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ====================================================\n# Directory settings\n# ====================================================\nINPUT_DIR = f'../input/child-mind-institute-detect-sleep-states/'\nOUTPUT_DIR = f'../working/'\nif not os.path.exists(OUTPUT_DIR):\n    os.makedirs(OUTPUT_DIR, exist_ok=True)\n\nLOG_DIR = f'./log/'\nif not os.path.exists(LOG_DIR):\n    os.makedirs(LOG_DIR, exist_ok=True)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:19.135283Z","iopub.execute_input":"2023-11-02T12:06:19.136365Z","iopub.status.idle":"2023-11-02T12:06:19.146048Z","shell.execute_reply.started":"2023-11-02T12:06:19.136273Z","shell.execute_reply":"2023-11-02T12:06:19.143888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ================================\n# logger\n# ================================\nimport logging\nfrom logging import Formatter, StreamHandler, getLogger\n\n# loggerオブジェクトの宣言\nlogger = getLogger(__name__)\n# loggerのログレベル設定(ハンドラに渡すエラーメッセージのレベル)\nlogger.setLevel(logging.DEBUG)\n# handlerの生成\nfilehandler = logging.FileHandler((Path(LOG_DIR)/f\"{date}_log.txt\"))\nstream_handler = StreamHandler()\n# handlerのログレベル設定(ハンドラが出力するエラーメッセージのレベル)\nfilehandler.setLevel(logging.DEBUG)\nstream_handler.setLevel(logging.DEBUG)\n# ログ出力フォーマット設定\nhandler_format = Formatter(\"[%(asctime)s][%(name)s][%(levelname)s][%(message)s]\")\nfilehandler.setFormatter(handler_format)\nstream_handler.setFormatter(handler_format)\n# loggerにhandlerをセット\nlogger.addHandler(filehandler)\nlogger.addHandler(stream_handler)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:19.147604Z","iopub.execute_input":"2023-11-02T12:06:19.148404Z","iopub.status.idle":"2023-11-02T12:06:19.173159Z","shell.execute_reply.started":"2023-11-02T12:06:19.148373Z","shell.execute_reply":"2023-11-02T12:06:19.171254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Utils","metadata":{}},{"cell_type":"code","source":"def seed_everything(seed: int):\n    \"\"\"Set random seeds for reproducibility.\n\n    Args:\n        seed (int): Seed value.\n\n    Returns:\n        None\n    \"\"\"    \n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n#     torch.manual_seed(seed)\n#     torch.cuda.manual_seed(seed)\n#     torch.backends.cudnn.deterministic = True\n#     torch.backends.cudnn.benchmark = True\n    \nseed_everything(seed=42)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:19.176172Z","iopub.execute_input":"2023-11-02T12:06:19.176589Z","iopub.status.idle":"2023-11-02T12:06:19.200770Z","shell.execute_reply.started":"2023-11-02T12:06:19.176555Z","shell.execute_reply":"2023-11-02T12:06:19.199562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_df(df:pd.DataFrame, num:int=3, tail:bool=False)-> None:\n    \"\"\"show shape and head of df \n\n    Args:\n        df (pd.DataFrame): data\n        num (int, optional): length of raws. Defaults to 3:int.\n        tail (bool, optional): if True show tail. Defaults to False:bool.\n    \"\"\"\n    print(df.shape)\n    display(df.head(num))\n    if tail: \n        display(df.tail(num))","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:19.202971Z","iopub.execute_input":"2023-11-02T12:06:19.203347Z","iopub.status.idle":"2023-11-02T12:06:19.220425Z","shell.execute_reply.started":"2023-11-02T12:06:19.203317Z","shell.execute_reply":"2023-11-02T12:06:19.218308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def reduce_memory_usage_pl(df, name):\n    \"\"\" Reduce memory usage by polars dataframe {df} with name {name} by changing its data types.\n        Original pandas version of this function: https://www.kaggle.com/code/arjanso/reducing-dataframe-memory-size-by-65 \"\"\"\n    print(f\"Memory usage of dataframe {name} is {round(df.estimated_size('mb'), 2)} MB\")\n    Numeric_Int_types = [pl.Int8,pl.Int16,pl.Int32,pl.Int64]\n    Numeric_Float_types = [pl.Float32,pl.Float64]    \n    for col in df.columns:\n        col_type = df[col].dtype\n        c_min = df[col].min()\n        c_max = df[col].max()\n        if col_type in Numeric_Int_types:\n            if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n                df = df.with_columns(df[col].cast(pl.Int8))\n            elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n                df = df.with_columns(df[col].cast(pl.Int16))\n            elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n                df = df.with_columns(df[col].cast(pl.Int32))\n            elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n                df = df.with_columns(df[col].cast(pl.Int64))\n        elif col_type in Numeric_Float_types:\n            if c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n                df = df.with_columns(df[col].cast(pl.Float32))\n            else:\n                pass\n        elif col_type == pl.Utf8:\n            df = df.with_columns(df[col].cast(pl.Categorical))\n        else:\n            pass\n    print(f\"Memory usage of dataframe {name} became {round(df.estimated_size('mb'), 2)} MB\")\n    return df","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:19.221892Z","iopub.execute_input":"2023-11-02T12:06:19.222313Z","iopub.status.idle":"2023-11-02T12:06:19.239967Z","shell.execute_reply.started":"2023-11-02T12:06:19.222279Z","shell.execute_reply":"2023-11-02T12:06:19.239146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2. 💿 Load Data","metadata":{}},{"cell_type":"code","source":"# ===========================\n# Load data\n# ===========================\ntrain = pl.read_parquet(Path(INPUT_DIR)/\"train_series.parquet\")\nprint(\"=\"*80); print(\"train_series.parquet\"); print(\"=\"*80); show_df(train)\ntest = pl.read_parquet(Path(INPUT_DIR)/\"test_series.parquet\")\nprint(\"=\"*80); print(\"test_series.parquet\"); print(\"=\"*80); show_df(test)\nevents = pl.read_csv(Path(INPUT_DIR)/\"train_events.csv\")\nprint(\"=\"*80); print(\"train_events.csv\"); print(\"=\"*80); show_df(events)\nsub = pl.read_csv(Path(INPUT_DIR)/\"sample_submission.csv\")\nprint(\"=\"*80); print(\"sample_submission.csv\"); print(\"=\"*80); show_df(sub)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:19.241934Z","iopub.execute_input":"2023-11-02T12:06:19.243405Z","iopub.status.idle":"2023-11-02T12:06:34.267692Z","shell.execute_reply.started":"2023-11-02T12:06:19.243348Z","shell.execute_reply":"2023-11-02T12:06:34.266187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cast_before_merge\nevents = events.with_columns(\n    events.get_column(\"step\").cast(pl.UInt32).alias(\"step\")\n)\nshow_df(events)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:34.269694Z","iopub.execute_input":"2023-11-02T12:06:34.270060Z","iopub.status.idle":"2023-11-02T12:06:34.303401Z","shell.execute_reply.started":"2023-11-02T12:06:34.270026Z","shell.execute_reply":"2023-11-02T12:06:34.302253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ==================\n# join\n# ==================\n# train = train.join(events, how=\"left\", on=[\"series_id\", \"step\", \"timestamp\"])\n# show_df(train)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:34.304530Z","iopub.execute_input":"2023-11-02T12:06:34.304857Z","iopub.status.idle":"2023-11-02T12:06:34.310627Z","shell.execute_reply.started":"2023-11-02T12:06:34.304828Z","shell.execute_reply":"2023-11-02T12:06:34.308818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# unique_id_list\nunique_id_list = train[\"series_id\"].unique()\nprint(f\"series_id num: {len(unique_id_list)}\")\nprint(f\"series_id example:\\n {unique_id_list[:3]}\")","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:34.313503Z","iopub.execute_input":"2023-11-02T12:06:34.313829Z","iopub.status.idle":"2023-11-02T12:06:35.850493Z","shell.execute_reply.started":"2023-11-02T12:06:34.313802Z","shell.execute_reply":"2023-11-02T12:06:35.849187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4. 🌌 Visualization of Each Series_id","metadata":{}},{"cell_type":"code","source":"import plotly.graph_objs as go\nimport plotly.subplots\n\ndef show_ts(train:pl.DataFrame, events:pl.DataFrame, idx:int=0, st=0, length=10)->None:\n    \"\"\"show time series data\n    Args:\n        train(pl.DataFrame):train_series\n        events(pl.DataFrame):train_event\n        idx(int):number of unique series_id\n        st(int): percentile, start of data\n        length(int): percentile, length of data\n    Returns:\n        None\n    \"\"\"\n    _train = train.filter(pl.col(\"series_id\")==unique_id_list[idx])\n    st  = int(len(_train)*st/100)\n    length = int(len(_train)*length/100)\n    _train = _train[st:st+length]\n    \n    # merge\n    df = _train.join(events, how=\"left\", on=[\"series_id\", \"step\", \"timestamp\"])\n    # cast datetime\n    df = df.with_columns(\n        df.get_column(\"timestamp\").str.strptime(pl.Datetime, \"%Y-%m-%dT%H:%M:%S%z\").dt.replace_time_zone(None).alias(\"timestamp\"),\n    )\n    # cal_time \n    df = df.with_columns(\n        df.get_column('timestamp').apply(lambda x: x.year).alias(\"year\"),\n        df.get_column('timestamp').apply(lambda x: x.month).alias(\"month\"),\n        df.get_column('timestamp').apply(lambda x: x.day).alias(\"day\"),\n        df.get_column('timestamp').apply(lambda x: x.hour).alias(\"hour\"),\n        df.get_column('timestamp').apply(lambda x: x.minute).alias(\"minute\"),\n        df.get_column('timestamp').apply(lambda x: x.second).alias(\"second\"),\n    )\n    # get dummies\n    df = df.with_columns(\n        df.get_column(\"event\").to_dummies()\n    )\n    # cal_time \n    df = df.with_columns(\n        (df.get_column('hour') * df.get_column('event_onset')).alias(\"event_onset\"),\n        (df.get_column('hour') * df.get_column('event_wakeup')).alias(\"event_wakeup\"),\n    )\n    # rename\n    df = df.rename({\"event_onset\": \"onset[h]\", \"event_wakeup\": \"wakeup[h]\"})\n    # show_df\n    show_df(df)\n\n    # select cols\n    unuse_cols = [\"series_id\", \"step\", \"timestamp\", \"year\", \"month\", \"day\", \"month\", \"hour\", \"minute\", \"second\", \"night\", \"event\", \"event_null\"]\n    cols = [col for col in df.columns if col not in unuse_cols]\n    \n    # Create a subplot with n rows and 1 column\n    fig = plotly.subplots.make_subplots(rows=len(cols), cols=1, shared_xaxes=True, vertical_spacing=0.03)\n    \n    for i, col in enumerate(cols, start=1):\n        # Create a scatter plot for each column\n        scatter = go.Scatter(x=df[\"timestamp\"], y=df[col], mode='lines', name=col)\n\n        # Add the trace to the subplot\n        fig.add_trace(scatter, row=i, col=1)\n\n        # Customize the y-axis label\n        fig.update_yaxes(title_text=col, row=i, col=1)\n\n    # Customize the x-axis label and title\n    fig.update_xaxes(title_text=\"Timestamp\", row=len(cols), col=1)\n    fig.update_layout(title=\"Time Series Data\")\n\n    # Show the plot\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:35.852268Z","iopub.execute_input":"2023-11-02T12:06:35.852633Z","iopub.status.idle":"2023-11-02T12:06:35.989661Z","shell.execute_reply.started":"2023-11-02T12:06:35.852600Z","shell.execute_reply":"2023-11-02T12:06:35.988373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"idx = 0\n\nprint(\"=\"*80); print(f\"index: {idx}\"); print(\"=\"*80); \nshow_ts(train, events, idx, st=0, length=10)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:06:35.991034Z","iopub.execute_input":"2023-11-02T12:06:35.991343Z","iopub.status.idle":"2023-11-02T12:06:37.591399Z","shell.execute_reply.started":"2023-11-02T12:06:35.991321Z","shell.execute_reply":"2023-11-02T12:06:37.590042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Moving Average","metadata":{}},{"cell_type":"code","source":"import plotly.graph_objs as go\nimport plotly.subplots\n\ndef show_ts_with_MA(train:pl.DataFrame, events:pl.DataFrame, idx:int=0, st=0, length=10, flag=\"mean\", period=\"1m\")->None:\n    \"\"\"show time series data\n    Args:\n        train(pl.DataFrame):train_series\n        events(pl.DataFrame):train_event\n        idx(int):number of unique series_id\n        st(int): percentile, start of data\n        length(int): percentile, length of data\n        period(str): moving_window\n    Returns:\n        None\n    \"\"\"\n    _train = train.filter(pl.col(\"series_id\")==unique_id_list[idx])\n    \n    st  = int(len(_train)*st/100)\n    length = int(len(_train)*length/100)\n    _train = _train[st:st+length]\n    \n    # merge\n    df = _train.join(events, how=\"left\", on=[\"series_id\", \"step\", \"timestamp\"])\n    # cast datetime\n    df = df.with_columns(\n        df.get_column(\"timestamp\").str.strptime(pl.Datetime, \"%Y-%m-%dT%H:%M:%S%z\").dt.replace_time_zone(None).alias(\"timestamp\"),\n    )\n    # moving_average\n    df = df.sort(\"timestamp\")\n    if flag == \"mean\":\n        dfma = df.groupby_rolling(\"timestamp\", period=period).agg(pl.mean(\"anglez\").suffix(\"'\"),pl.mean(\"enmo\").suffix(\"'\"))\n    elif flag == \"sum\":\n        dfma = df.groupby_rolling(\"timestamp\", period=period).agg(pl.sum(\"anglez\").suffix(\"'\"),pl.sum(\"enmo\").suffix(\"'\"))\n    elif flag == \"max\":\n        dfma = df.groupby_rolling(\"timestamp\", period=period).agg(pl.max(\"anglez\").suffix(\"'\"),pl.max(\"enmo\").suffix(\"'\"))\n    elif flag == \"min\":\n        dfma = df.groupby_rolling(\"timestamp\", period=period).agg(pl.min(\"anglez\").suffix(\"'\"),pl.min(\"enmo\").suffix(\"'\"))\n    elif flag == \"std\":\n        dfma = df.groupby_rolling(\"timestamp\", period=period).agg(pl.std(\"anglez\").suffix(\"'\"),pl.std(\"enmo\").suffix(\"'\"))\n    \n    df = df.join(dfma, how=\"left\", on=[\"timestamp\"])\n    \n    # cal_time \n    df = df.with_columns(\n        df.get_column('timestamp').apply(lambda x: x.year).alias(\"year\"),\n        df.get_column('timestamp').apply(lambda x: x.month).alias(\"month\"),\n        df.get_column('timestamp').apply(lambda x: x.day).alias(\"day\"),\n        df.get_column('timestamp').apply(lambda x: x.hour).alias(\"hour\"),\n        df.get_column('timestamp').apply(lambda x: x.minute).alias(\"minute\"),\n        df.get_column('timestamp').apply(lambda x: x.second).alias(\"second\"),\n    )\n    # get dummies\n    df = df.with_columns(\n        df.get_column(\"event\").to_dummies()\n    )\n    # cal_time \n    df = df.with_columns(\n        (df.get_column('hour') * df.get_column('event_onset')).alias(\"event_onset\"),\n        (df.get_column('hour') * df.get_column('event_wakeup')).alias(\"event_wakeup\"),\n    )\n    # rename\n    df = df.rename({\"event_onset\": \"onset[h]\", \"event_wakeup\": \"wakeup[h]\"})\n    # show_df\n    show_df(df)\n\n    # select cols\n    unuse_cols = [\"series_id\", \"step\", \"timestamp\", \"year\", \"month\", \"day\", \"month\", \"hour\", \"minute\", \"second\", \"night\", \"event\", \"event_null\"]\n    cols = [col for col in df.columns if col not in unuse_cols]\n    \n    # Create a subplot with n rows and 1 column\n    fig = plotly.subplots.make_subplots(rows=len(cols), cols=1, shared_xaxes=True, vertical_spacing=0.03)\n    \n    for i, col in enumerate(cols, start=1):\n        # Create a scatter plot for each column\n        scatter = go.Scatter(x=df[\"timestamp\"], y=df[col], mode='lines', name=col)\n\n        # Add the trace to the subplot\n        fig.add_trace(scatter, row=i, col=1)\n\n        # Customize the y-axis label\n        fig.update_yaxes(title_text=col, row=i, col=1)\n\n    # Customize the x-axis label and title\n    fig.update_xaxes(title_text=\"Timestamp\", row=len(cols), col=1)\n    fig.update_layout(title=\"Time Series Data\")\n\n    # Show the plot\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:35:55.918887Z","iopub.execute_input":"2023-11-02T12:35:55.919307Z","iopub.status.idle":"2023-11-02T12:35:55.944435Z","shell.execute_reply.started":"2023-11-02T12:35:55.919274Z","shell.execute_reply":"2023-11-02T12:35:55.943049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"idx = 2\nperiod = \"60m\"","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:49:16.855772Z","iopub.execute_input":"2023-11-02T12:49:16.856155Z","iopub.status.idle":"2023-11-02T12:49:16.861996Z","shell.execute_reply.started":"2023-11-02T12:49:16.856123Z","shell.execute_reply":"2023-11-02T12:49:16.860754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================\n# moving_average\n# =====================\nprint(\"=\"*80); print(f\"index: {idx}, moving_average\"); print(\"=\"*80); \nshow_ts_with_MA(train, events, idx, st=0, length=20, flag=\"mean\", period=period)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:49:17.499711Z","iopub.execute_input":"2023-11-02T12:49:17.500145Z","iopub.status.idle":"2023-11-02T12:49:18.848277Z","shell.execute_reply.started":"2023-11-02T12:49:17.500111Z","shell.execute_reply":"2023-11-02T12:49:18.845898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================\n# moving_sum\n# =====================\nprint(\"=\"*80); print(f\"index: {idx}, moving_sum\"); print(\"=\"*80); \nshow_ts_with_MA(train, events, idx, st=0, length=20, flag=\"sum\", period=period)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:49:46.837341Z","iopub.execute_input":"2023-11-02T12:49:46.837723Z","iopub.status.idle":"2023-11-02T12:49:48.172766Z","shell.execute_reply.started":"2023-11-02T12:49:46.837693Z","shell.execute_reply":"2023-11-02T12:49:48.171244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================\n# moving_max\n# =====================\nprint(\"=\"*80); print(f\"index: {idx}, moving_max\"); print(\"=\"*80); \nshow_ts_with_MA(train, events, idx, st=0, length=20, flag=\"max\", period=period)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:50:01.759005Z","iopub.execute_input":"2023-11-02T12:50:01.759466Z","iopub.status.idle":"2023-11-02T12:50:03.161499Z","shell.execute_reply.started":"2023-11-02T12:50:01.759439Z","shell.execute_reply":"2023-11-02T12:50:03.150473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================\n# moving_min\n# =====================\nprint(\"=\"*80); print(f\"index: {idx}, moving_min\"); print(\"=\"*80); \nshow_ts_with_MA(train, events, idx, st=0, length=20, flag=\"min\", period=period)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:50:19.899402Z","iopub.execute_input":"2023-11-02T12:50:19.899744Z","iopub.status.idle":"2023-11-02T12:50:21.302285Z","shell.execute_reply.started":"2023-11-02T12:50:19.899718Z","shell.execute_reply":"2023-11-02T12:50:21.301157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# =====================\n# moving_std\n# =====================\nprint(\"=\"*80); print(f\"index: {idx}, moving_std\"); print(\"=\"*80); \nshow_ts_with_MA(train, events, idx, st=0, length=20, flag=\"std\", period=period)","metadata":{"execution":{"iopub.status.busy":"2023-11-02T12:50:26.656128Z","iopub.execute_input":"2023-11-02T12:50:26.656476Z","iopub.status.idle":"2023-11-02T12:50:28.049507Z","shell.execute_reply.started":"2023-11-02T12:50:26.656453Z","shell.execute_reply":"2023-11-02T12:50:28.046377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}