{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":53666,"databundleVersionId":6589269,"sourceType":"competition"},{"sourceId":6897904,"sourceType":"datasetVersion","datasetId":3962378},{"sourceId":6898149,"sourceType":"datasetVersion","datasetId":3962499}],"dockerImageVersionId":30558,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n\nimport lightgbm as lgb\nimport gc\nimport plotly.express as px","metadata":{"_uuid":"686b6d59-3edb-42a2-a60e-3dc7c6d9f5ab","_cell_guid":"11a27c0e-ce3b-4ea8-80e9-aef25607846c","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:01.865539Z","iopub.execute_input":"2023-11-15T15:26:01.865935Z","iopub.status.idle":"2023-11-15T15:26:04.176564Z","shell.execute_reply.started":"2023-11-15T15:26:01.865904Z","shell.execute_reply":"2023-11-15T15:26:04.175210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_parquet('/kaggle/input/merged-data/merged_data.parquet')\n\ndata = data.iloc[::30]\n\ndata = data.rename(columns={'series_id': 'series_id_no'})\n\ndata['event'] = 1 - data['event'] # event column의 0과 1 바꿈","metadata":{"_uuid":"31f7dc84-6de7-4d23-80c4-d3f02770a0dc","_cell_guid":"19b95b4f-7738-4ada-b742-b961222cbac1","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:04.178610Z","iopub.execute_input":"2023-11-15T15:26:04.178954Z","iopub.status.idle":"2023-11-15T15:26:08.283569Z","shell.execute_reply.started":"2023-11-15T15:26:04.178917Z","shell.execute_reply":"2023-11-15T15:26:08.282292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DEV = False # 테스트시 True, 제출시 False\n\nif DEV:\n    unique_series_ids = data['series_id_no'].unique()\n    selected_series_ids = unique_series_ids[:10]\n    data = data[data['series_id_no'].isin(selected_series_ids)]","metadata":{"_uuid":"30580114-1805-46f7-9aa0-2a7b0cfe6129","_cell_guid":"3125dc62-c92a-4595-9d1a-02a961ca4ffa","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:08.310648Z","iopub.execute_input":"2023-11-15T15:26:08.311123Z","iopub.status.idle":"2023-11-15T15:26:08.365130Z","shell.execute_reply.started":"2023-11-15T15:26:08.311082Z","shell.execute_reply":"2023-11-15T15:26:08.363736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfs = [data.query(f'series_id_no=={i}') for i in range(len(data.series_id_no.unique()))]","metadata":{"_uuid":"0b462dee-124a-46c3-9ef9-8f7a6b264633","_cell_guid":"a2ec7970-9cb4-448d-ba6a-fd7667f40d40","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:08.369578Z","iopub.execute_input":"2023-11-15T15:26:08.370942Z","iopub.status.idle":"2023-11-15T15:26:08.417399Z","shell.execute_reply.started":"2023-11-15T15:26:08.370893Z","shell.execute_reply":"2023-11-15T15:26:08.415669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"windows = [np.lib.stride_tricks.sliding_window_view(df.iloc[:, -2:], 20, axis=0) for df in dfs if len(df) > 20]","metadata":{"_uuid":"3e608c68-45d7-4244-aad5-f1986a017aa0","_cell_guid":"314d35ee-4a6d-4ed5-920f-85b8da64e3da","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:08.419179Z","iopub.execute_input":"2023-11-15T15:26:08.419686Z","iopub.status.idle":"2023-11-15T15:26:08.435119Z","shell.execute_reply.started":"2023-11-15T15:26:08.419642Z","shell.execute_reply":"2023-11-15T15:26:08.433935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conc = np.concatenate(windows)","metadata":{"_uuid":"9cc7d4dd-64eb-4b47-a7f3-c5d1f264fbc0","_cell_guid":"76b7cc86-c729-43da-b2a3-2f4441d77dd7","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:08.436307Z","iopub.execute_input":"2023-11-15T15:26:08.436733Z","iopub.status.idle":"2023-11-15T15:26:08.454254Z","shell.execute_reply.started":"2023-11-15T15:26:08.436702Z","shell.execute_reply":"2023-11-15T15:26:08.453184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def extract_fft_features(conc):\n    # Prepare an empty list to store the extracted features\n    features = []\n\n    # Iterate through each window\n    for window in conc:\n        # Calculate FFT for 'enmo' and 'anglez'\n        fft_enmo = np.fft.fft(window[1])\n        fft_anglez = np.fft.fft(window[0])\n\n        # Calculate amplitudes and angles (frequencies)\n        amp_enmo = np.abs(fft_enmo)\n        angle_enmo = np.angle(fft_enmo)\n        amp_anglez = np.abs(fft_anglez)\n        angle_anglez = np.angle(fft_anglez)\n\n        # Find indices of the top 3 amplitudes for both 'enmo' and 'anglez'\n        indices_enmo = np.argsort(amp_enmo)[::-1][:3]\n        indices_anglez = np.argsort(amp_anglez)[::-1][:3]\n\n        # Extract the top 3 amplitude and angle values\n        top_amp_enmo = amp_enmo[indices_enmo]\n        top_angle_enmo = angle_enmo[indices_enmo]\n        top_amp_anglez = amp_anglez[indices_anglez]\n        top_angle_anglez = angle_anglez[indices_anglez]\n\n        # Append the extracted features to the list\n        features.append(np.concatenate((top_amp_enmo, top_angle_enmo, top_amp_anglez, top_angle_anglez)))\n\n    # Convert the list of features to a DataFrame\n    train = pd.DataFrame(features, columns=[\n        'enmo_amp_top1', 'enmo_amp_top2', 'enmo_amp_top3',\n        'enmo_angle_top1', 'enmo_angle_top2', 'enmo_angle_top3',\n        'anglez_amp_top1', 'anglez_amp_top2', 'anglez_amp_top3',\n        'anglez_angle_top1', 'anglez_angle_top2', 'anglez_angle_top3'\n    ])\n\n    return train\n\n# Use the function like this:\n# train = extract_fft_features(conc)\n","metadata":{"_uuid":"e5358b6d-a6b6-4a27-ba6e-fd563f6df9d3","_cell_guid":"9be5c1c0-4609-492d-ba49-7e5abe8aac5c","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:08.456314Z","iopub.execute_input":"2023-11-15T15:26:08.456885Z","iopub.status.idle":"2023-11-15T15:26:08.469185Z","shell.execute_reply.started":"2023-11-15T15:26:08.456842Z","shell.execute_reply":"2023-11-15T15:26:08.467811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = extract_fft_features(conc)","metadata":{"_uuid":"f454069a-2ecc-4cf8-81d3-38a23f83bfe3","_cell_guid":"2b6febbb-9ff1-4901-99ec-84cd46e6bad3","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:08.470700Z","iopub.execute_input":"2023-11-15T15:26:08.471072Z","iopub.status.idle":"2023-11-15T15:26:12.366678Z","shell.execute_reply.started":"2023-11-15T15:26:08.471042Z","shell.execute_reply":"2023-11-15T15:26:12.365418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"event_windows = [np.lib.stride_tricks.sliding_window_view(df.iloc[:, 3], 20, axis=0) for df in dfs if len(df) > 20]","metadata":{"_uuid":"d65cb9ad-11b9-4859-83fc-6fabea0a5b03","_cell_guid":"1aed7f4b-5989-488d-bf19-e7c19f78090c","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.369501Z","iopub.execute_input":"2023-11-15T15:26:12.370407Z","iopub.status.idle":"2023-11-15T15:26:12.379485Z","shell.execute_reply.started":"2023-11-15T15:26:12.370362Z","shell.execute_reply":"2023-11-15T15:26:12.378023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"event_conc = np.concatenate(event_windows)","metadata":{"_uuid":"2fdd51c9-006f-4e21-8772-c9b815e6e56d","_cell_guid":"e44a8ab4-ca24-4271-ad49-1102c4868ffc","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.381577Z","iopub.execute_input":"2023-11-15T15:26:12.382449Z","iopub.status.idle":"2023-11-15T15:26:12.395273Z","shell.execute_reply.started":"2023-11-15T15:26:12.382392Z","shell.execute_reply":"2023-11-15T15:26:12.394208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"first_values = event_conc[:, 0]\n\ntarget = pd.DataFrame(first_values, columns=['event'])","metadata":{"_uuid":"63ed9d9a-bd40-4eaf-abad-248851f1429d","_cell_guid":"1e4e3cf0-71cc-44fa-8c91-764ff3c39c7c","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.396761Z","iopub.execute_input":"2023-11-15T15:26:12.397229Z","iopub.status.idle":"2023-11-15T15:26:12.408949Z","shell.execute_reply.started":"2023-11-15T15:26:12.397165Z","shell.execute_reply":"2023-11-15T15:26:12.407983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = target.iloc[:,0] #y 그냥 넣으면 안되는지 확인 y = target['event'] 하면 안되는지 확인","metadata":{"_uuid":"d0a9db18-26ef-4ede-b3e7-494a5549823b","_cell_guid":"b34067a1-3df7-4ecd-9e6c-b7ed7a984994","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.410737Z","iopub.execute_input":"2023-11-15T15:26:12.411506Z","iopub.status.idle":"2023-11-15T15:26:12.432409Z","shell.execute_reply.started":"2023-11-15T15:26:12.411461Z","shell.execute_reply":"2023-11-15T15:26:12.430969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"_uuid":"95b13c0c-559e-4d82-9c23-65e9e897de04","_cell_guid":"59fb4c0f-6e78-41d3-b146-d07957b4cf8f","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.436934Z","iopub.execute_input":"2023-11-15T15:26:12.437928Z","iopub.status.idle":"2023-11-15T15:26:12.556044Z","shell.execute_reply.started":"2023-11-15T15:26:12.437884Z","shell.execute_reply":"2023-11-15T15:26:12.554869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgb_params1 = {    \n    'boosting_type':'gbdt',\n    'num_leaves':31,\n    'max_depth':6,\n    'learning_rate':0.02,\n    'n_estimators':100,\n    'subsample_for_bin':200000,\n    'min_child_weight':0.001,\n    'min_child_samples':20,\n    'subsample':0.9,\n#     'colsample_bytree':0.7,\n    'reg_alpha':0.05,\n    'reg_lambda':0.05,\n             }\nimport xgboost as xgb\n\n\n# Training classifier\n\n\nmodel = lgb.LGBMClassifier(random_state=42, **lgb_params1)\n\n\n'''\nformer parameter values\n\nlgb_params1 = {    \n    'boosting_type':'gbdt',\n    'num_leaves':40,\n    'max_depth':6,\n    'learning_rate':0.02,\n    'n_estimators':1000,\n    'subsample_for_bin':200000,\n    'min_child_weight':0.001,\n    'min_child_samples':20,\n    'subsample':0.9,\n#     'colsample_bytree':0.7,\n    'reg_alpha':0.05,\n    'reg_lambda':0.05,\n             }\nimport xgboost as xgb\n\n\ndefault parameter values\n    \n    'boosting_type': 'gbdt', # Gradient Boosting Decision Tree\n    'num_leaves': 31, # Max number of leaves in one tree\n    'max_depth': -1, # No limit, unless specified\n    'learning_rate': 0.1, # The efficiency of the model learning\n    'n_estimators': 100, # Number of boosted trees to fit\n    'subsample_for_bin': 200000, # Number of samples for constructing bins\n    'objective': None, # The loss to minimize during optimization\n    'class_weight': None, # Weights associated with classes\n    'min_split_gain': 0., # The minimum loss reduction required to make a further partition on a leaf node of the tree\n    'min_child_weight': 1e-3, # Minimum sum of instance weight (hessian) needed in a child (leaf)\n    'min_child_samples': 20, # Minimum number of data needed in a child (leaf)\n    'subsample': 1., # Subsample ratio of the training instance\n    'subsample_freq': 0, # Frequence of subsample, <=0 means no enable\n    'colsample_bytree': 1., # Subsample ratio of columns when constructing each tree\n    'reg_alpha': 0., # L1 regularization term on weights\n    'reg_lambda': 0., # L2 regularization term on weights\n    'random_state': None, # Random number seed\n    # ... there are other parameters as well which have default values\n    \n\n\nan advice from a team member\n\n추가로, lgb_params가 너무 깊습니다.\n먼저 lgb_params의 leaves와 estimators 를 좀 낮춘 후 진행하시는 걸 추천드립니다.\n파라미터에 대한 최적화는 일단 스코어링이 진행되고 나서 값을 조정해도 되니, 최대한 간단한 값으로 하시는 걸 추천드립니다.\n'''\n","metadata":{"_uuid":"f598095f-5162-4a98-90d0-4fe9f08a1e8b","_cell_guid":"301f5001-124e-4aa2-8ca5-7b80c75bb14a","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.557338Z","iopub.execute_input":"2023-11-15T15:26:12.558178Z","iopub.status.idle":"2023-11-15T15:26:12.600767Z","shell.execute_reply.started":"2023-11-15T15:26:12.558146Z","shell.execute_reply":"2023-11-15T15:26:12.599268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n\nmodel.fit(X, y)","metadata":{"_uuid":"ef230a84-a6a5-4b5f-ab03-a4aa94ab6f29","_cell_guid":"0c6c1dd7-e069-49a0-a340-01f9cc5730a6","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:12.602442Z","iopub.execute_input":"2023-11-15T15:26:12.602890Z","iopub.status.idle":"2023-11-15T15:26:14.002045Z","shell.execute_reply.started":"2023-11-15T15:26:12.602849Z","shell.execute_reply":"2023-11-15T15:26:14.000884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feats = []\n\nfeat_imp = pd.Series(model.booster_.feature_importance(importance_type='gain'), index=X.columns).sort_values()\nfeats.append(feat_imp)","metadata":{"_uuid":"23f3745f-aacc-410e-bfe6-1f9a6e67304a","_cell_guid":"ea5dfcee-cad4-4b5b-b748-7a5836242f7c","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.003599Z","iopub.execute_input":"2023-11-15T15:26:14.004058Z","iopub.status.idle":"2023-11-15T15:26:14.011349Z","shell.execute_reply.started":"2023-11-15T15:26:14.004016Z","shell.execute_reply":"2023-11-15T15:26:14.010072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feat_imp = pd.Series(pd.concat(feats, axis=1).mean(axis=1), index=feats[0].index).sort_values()\n# print('Columns with poor contribution', feat_imp[feat_imp<0.001].index, sep='\\n')\nfig = px.bar(x=feat_imp, y=feat_imp.index, orientation='h')\nfig.show()\n\n#according to this analysis, seems like 'amplitude' feature has more contribution than 'angle'","metadata":{"_uuid":"c280f03d-1d26-4288-a398-a4ff7798d321","_cell_guid":"99565f82-b9af-4c3a-8198-759a9e8f36aa","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.013193Z","iopub.execute_input":"2023-11-15T15:26:14.013948Z","iopub.status.idle":"2023-11-15T15:26:14.478877Z","shell.execute_reply.started":"2023-11-15T15:26:14.013904Z","shell.execute_reply":"2023-11-15T15:26:14.477467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feat_imp.sort_values().tail(12)","metadata":{"_uuid":"5b4c5867-c85f-43b0-b60c-99c73381d506","_cell_guid":"36272cc1-16c0-49e2-96bf-162ccf997d19","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.480525Z","iopub.execute_input":"2023-11-15T15:26:14.481171Z","iopub.status.idle":"2023-11-15T15:26:14.489794Z","shell.execute_reply.started":"2023-11-15T15:26:14.481138Z","shell.execute_reply":"2023-11-15T15:26:14.488940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# del X, y\ngc.collect()","metadata":{"_uuid":"69d7b97a-a3c8-4bc2-8bee-21005fd4121e","_cell_guid":"bbfbb946-105b-4003-be76-10b8ac046b49","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.491004Z","iopub.execute_input":"2023-11-15T15:26:14.492075Z","iopub.status.idle":"2023-11-15T15:26:14.638166Z","shell.execute_reply.started":"2023-11-15T15:26:14.492043Z","shell.execute_reply":"2023-11-15T15:26:14.636492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_events(idx, classifier, file='test_series.parquet') :\n    \n    test  = pd.read_parquet(f'/kaggle/input/child-mind-institute-detect-sleep-states/{file}',\n                    filters=[('series_id','=',idx)])\n    \n    \n    id = test['series_id'].iloc[0] ######################추가\n    codes, uniques = pd.factorize(test['series_id'])\n    test.insert(test.columns.get_loc('series_id') + 1, 'series_id_no', codes)\n    \n    dfs = [test.query(f'series_id_no=={i}') for i in range(len(test.series_id_no.unique()))]\n    windows = [np.lib.stride_tricks.sliding_window_view(df.iloc[:, -2:], 20, axis=0) for df in dfs if len(df) > 20]\n    conc = np.concatenate(windows)\n    \n    \n    X_test = extract_fft_features(conc)\n    preds, probs = classifier.predict(X_test), classifier.predict_proba(X_test)[:, 1]    \n    \n    \n        \n    windows = [np.lib.stride_tricks.sliding_window_view(df.iloc[:, :3], 20, axis=0) for df in dfs if len(df) > 20]\n\n    flattened_data = [(window[0][0], window[1][0], window[2][0]) for window in windows[0]]\n    \n    test = pd.DataFrame(flattened_data, columns=['series_id', 'step', 'timestamp'])\n    \n    if test['timestamp'].dtype != '<M8[ns]':  # '<M8[ns]' is numpy's datetime64\n        test['timestamp'] = pd.to_datetime(test['timestamp'])\n\n\n    test['series_id'] = id #################추가\n        \n    \n    test['prediction'] = preds\n    test['prediction'] = test['prediction'].rolling(360+1, center=True).median()\n    test['probability'] = probs\n    \n    test = test[test['prediction']!=2]\n    \n    test.loc[test['prediction']==0, 'probability'] = 1-test.loc[test['prediction']==0, 'probability']\n    test['score'] = test['probability'].rolling(60*12*5, center=True, min_periods=10).mean().bfill().ffill()\n\n    \n    test['pred_diff'] = test['prediction'].diff()\n    \n    test['event'] = test['pred_diff'].replace({1:'wakeup', -1:'onset', 0:np.nan})\n    \n    test_wakeup = test[test['event']=='wakeup'].groupby(test['timestamp'].dt.date).agg('first')\n    test_onset = test[test['event']=='onset'].groupby(test['timestamp'].dt.date).agg('last')\n    test = pd.concat([test_wakeup, test_onset], ignore_index=True).sort_values('timestamp')\n\n    return test","metadata":{"_uuid":"9a8d385c-77e4-410b-9985-7d83cb914f4e","_cell_guid":"5e863e37-674e-4ba2-a5ac-f614ab05f9b7","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.639890Z","iopub.execute_input":"2023-11-15T15:26:14.640295Z","iopub.status.idle":"2023-11-15T15:26:14.660936Z","shell.execute_reply.started":"2023-11-15T15:26:14.640253Z","shell.execute_reply":"2023-11-15T15:26:14.659641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols_sub = ['series_id','step','event','score']\n\nseries_id  = pd.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet', columns=['series_id'])\nseries_id = series_id.series_id.unique()\n\ntests = []\n\nfor idx in series_id: \n\n    test =  get_events(idx, model)\n    tests.append(test[cols_sub])","metadata":{"_uuid":"8edf989d-08d7-4ccf-afd2-17a6e9dbeb13","_cell_guid":"dad39ed9-8159-4d8a-9ecf-18362a6daa2e","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.662632Z","iopub.execute_input":"2023-11-15T15:26:14.663806Z","iopub.status.idle":"2023-11-15T15:26:14.802900Z","shell.execute_reply.started":"2023-11-15T15:26:14.663769Z","shell.execute_reply":"2023-11-15T15:26:14.801975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.concat(tests, ignore_index=True).reset_index(names='row_id')\nsubmission.to_csv('submission.csv', index=False)\nsubmission","metadata":{"_uuid":"e978c88f-3785-400f-b53b-12775dc93da6","_cell_guid":"136594b9-bac9-4749-ba5c-e1d30199f85a","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2023-11-15T15:26:14.804749Z","iopub.execute_input":"2023-11-15T15:26:14.805569Z","iopub.status.idle":"2023-11-15T15:26:14.820506Z","shell.execute_reply.started":"2023-11-15T15:26:14.805528Z","shell.execute_reply":"2023-11-15T15:26:14.819041Z"},"trusted":true},"execution_count":null,"outputs":[]}]}