<jupyter_start><jupyter_text>Ce script génère les diagrammes des données du corpus DCU.<jupyter_code>from __future__ import absolute_import, division, print_function, unicode_literals

import os
import argparse

import pandas as pd
import matplotlib.pyplot as plt
from data_handler import DataHandler


# parse arguments
## general
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--working_path', default='.')

## data
arg_parser.add_argument('dataset_name', default='mimic3',
                        help='The data files should be saved in [working_path]/data/[dataset_name] directory.')
arg_parser.add_argument('label_name', default='mortality')
arg_parser.add_argument('--max_timesteps', type=int, default=200, 
                        help='Time series of at most # time steps are used. Default: 200.')
arg_parser.add_argument('--max_timestamp', type=int, default=48*60*60,
                        help='Time series of at most # seconds are used. Default: 48 (hours).')

## model
arg_parser.add_argument('--recurrent_dim', type=lambda x: x and [int(xx) for xx in x.split(',')] or [], default='64')
arg_parser.add_argument('--hidden_dim', type=lambda x: x and [int(xx) for xx in x.split(',')] or [], default='64')
arg_parser.add_argument('--model', default='GRUD', choices=['GRUD', 'GRUforward', 'GRU0', 'GRUsimple'])
arg_parser.add_argument('--use_bidirectional_rnn', default=False)
                           
## training
arg_parser.add_argument('--pretrained_model_file', default=None,
                        help='If pre-trained model is provided, training will be skipped.') # e.g., [model_name]_[i_fold].h5
arg_parser.add_argument('--epochs', type=int, default=100)
arg_parser.add_argument('--early_stopping_patience', type=int, default=10)
arg_parser.add_argument('--batch_size', type=int, default=2)


## set the actual arguments if running in notebook
if not (__name__ == '__main__' and '__file__' in globals()):
    # '''ARGS = arg_parser.parse_args([
    #     'mimic3',
    #     'mortality',
    #     '--model', 'GRUD',
    #     '--hidden_dim', '',
    #     '--epochs', '100'
    # ])'''
    ARGS = arg_parser.parse_args([
        'detection',
        'risk_situation',
        '--model', 'GRUD',
        '--hidden_dim', '',
        '--max_timestamp', '5807537',
        '--epochs', '100'
    ])
else:
    ARGS = arg_parser.parse_args()

#print('Arguments:', ARGS)
# get dataset
dataset = DataHandler(
    data_path=os.path.join(ARGS.working_path, 'data', ARGS.dataset_name), 
    label_name=ARGS.label_name, 
    max_steps=ARGS.max_timesteps,
    max_timestamp=ARGS.max_timestamp
)<jupyter_output><empty_output><jupyter_text>Embeding<jupyter_code>df = pd.DataFrame(dataset._data['input'])
df.columns = ["timestamp","name", "latitude", "longitude", "step","gsr","heart_rate","skin_temp","calories","risk_situation"]
#df = df[pd.notnull(df['risk_situation'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
df.sample(10)<jupyter_output><empty_output><jupyter_text>Statistiques par classe<jupyter_code>stat = df['risk_situation'].value_counts(dropna=False)
stat
stat.plot(kind='bar')
stat.plot
# Prepare data: throw useless features away
timeDf=df.drop(['latitude','longitude','name', 'risk_situation'],axis=1)
timeDf = timeDf[pd.notnull(timeDf['timestamp'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
timeDf.set_index('timestamp', inplace=True, drop=True)<jupyter_output><empty_output><jupyter_text>GSR<jupyter_code># Plot gsr
timeDfGsr=timeDf.drop(['step','heart_rate', 'skin_temp','calories'],axis=1)
timeDfGsr = timeDfGsr[pd.notnull(timeDfGsr['gsr'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
timeDfGsr=timeDfGsr.astype(float)
timeDfGsr=timeDfGsr.sort_index(axis=0)
plt.rcParams.update({'figure.figsize': (15,5)})
timeDfGsr.plot()<jupyter_output><empty_output><jupyter_text>Heart Rate<jupyter_code># Plot heart_rate
timeDfHr=timeDf.drop(['step','gsr', 'skin_temp','calories'],axis=1)
timeDfHr = timeDfHr[pd.notnull(timeDfHr['heart_rate'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
timeDfHr=timeDfHr.astype(float)
timeDfHr=timeDfHr.sort_index(axis=0)
plt.rcParams.update({'figure.figsize': (15,5)})
timeDfHr.plot()
timeDfHr.plot.kde()<jupyter_output><empty_output><jupyter_text>Skin temp<jupyter_code># Plot skin_temp
timeDfSt=timeDf.drop(['step','gsr', 'heart_rate','calories'],axis=1)
timeDfSt = timeDfSt[pd.notnull(timeDfSt['skin_temp'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
timeDfSt=timeDfSt.astype(float)
timeDfSt=timeDfSt.sort_index(axis=0)
plt.rcParams.update({'figure.figsize': (15,5)})
timeDfSt.plot()
timeDfSt.plot.kde()<jupyter_output><empty_output><jupyter_text>Calories<jupyter_code># Plot calories
timeDfC=timeDf.drop(['step','gsr', 'heart_rate','skin_temp'],axis=1)
timeDfC = timeDfC[pd.notnull(timeDfC['calories'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
timeDfC=timeDfC.astype(float)
timeDfC=timeDfC.sort_index(axis=0)
plt.rcParams.update({'figure.figsize': (15,5)})
#timeDfC.reset_index().plot.scatter(x='timestamp', y='calories')
timeDfC.plot()
timeDfC.plot.kde()<jupyter_output><empty_output><jupyter_text>Steps<jupyter_code># Plot steps
timeDfC=timeDf.drop(['calories','gsr', 'heart_rate','skin_temp'],axis=1)
timeDfC = timeDfC[pd.notnull(timeDfC['step'])] #-> ça c'est pour enlever toutes les entrées ou il y a NaN ou Null
timeDfC=timeDfC.astype(float)
timeDfC=timeDfC.sort_index(axis=0)
plt.rcParams.update({'figure.figsize': (15,5)})
#timeDfC.reset_index().plot.bar(x='timestamp', y='step')
timeDfC.plot()
timeDfC.plot.kde()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1609945335919591, 'fraction_numerical': 0.01216716628460589, 'mean_word_length': 5.784688995215311, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '340272', 'license': 'MIT', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2119, 'n_words': 380, 'path': 'Plots.ipynb', 'repo_name': 'edwinlebreton/Birds', 'size': '5671'}