{"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":"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)\nimport polars as pl\nimport datetime\nfrom matplotlib import pyplot as plt\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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-11-09T12:57:15.318482Z","iopub.execute_input":"2023-11-09T12:57:15.318847Z","iopub.status.idle":"2023-11-09T12:57:15.929190Z","shell.execute_reply.started":"2023-11-09T12:57:15.318818Z","shell.execute_reply":"2023-11-09T12:57:15.928231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_submission = pd.read_csv('/kaggle/input/child-mind-institute-detect-sleep-states/sample_submission.csv')\n#df_pq_test = pd.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet')\n#df_pq_train = pd.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet')\ndf_train_events = pl.read_csv(\"/kaggle/input/child-mind-institute-detect-sleep-states/train_events.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-11-09T12:57:24.633485Z","iopub.execute_input":"2023-11-09T12:57:24.633989Z","iopub.status.idle":"2023-11-09T12:57:24.808487Z","shell.execute_reply.started":"2023-11-09T12:57:24.633959Z","shell.execute_reply":"2023-11-09T12:57:24.807544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_events = df_train_events.with_columns(\n    pl.col(\"timestamp\").apply(lambda x: x[-5:]).alias(\"timezone_offset\"),\n    pl.col(\"timestamp\").apply(lambda x: datetime.datetime.strptime(str(x), '%Y-%m-%dT%H:%M:%S%z')).alias(\"timestamp\"),\n)\n","metadata":{"execution":{"iopub.status.busy":"2023-11-09T12:57:38.673422Z","iopub.execute_input":"2023-11-09T12:57:38.673820Z","iopub.status.idle":"2023-11-09T12:57:38.876369Z","shell.execute_reply.started":"2023-11-09T12:57:38.673788Z","shell.execute_reply":"2023-11-09T12:57:38.875595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_events['night'].describe()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T12:57:53.725059Z","iopub.execute_input":"2023-11-09T12:57:53.725989Z","iopub.status.idle":"2023-11-09T12:57:53.759079Z","shell.execute_reply.started":"2023-11-09T12:57:53.725937Z","shell.execute_reply":"2023-11-09T12:57:53.757928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=[20,10])\ndata = df_train_events[\"night\"].to_numpy()\nhist, edges = np.histogram(data, bins=20)\nfreq = hist / sum(hist)\ncolors = plt.cm.rainbow(freq)\nplt.bar(edges[:-1], hist, width=np.diff(edges), color=colors, alpha=0.7)\nplt.title(\"Nights vs Sensor Count\")\nplt.xlabel(\"Nights\")\nplt.ylabel(\"Number of Sensors\")\nplt.xlim([0,100]) ","metadata":{"execution":{"iopub.status.busy":"2023-11-09T13:39:41.655645Z","iopub.execute_input":"2023-11-09T13:39:41.656038Z","iopub.status.idle":"2023-11-09T13:39:41.985134Z","shell.execute_reply.started":"2023-11-09T13:39:41.656012Z","shell.execute_reply":"2023-11-09T13:39:41.983575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"available_colormaps = plt.colormaps()\n\nprint(available_colormaps)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T13:29:44.220372Z","iopub.execute_input":"2023-11-09T13:29:44.220916Z","iopub.status.idle":"2023-11-09T13:29:44.227737Z","shell.execute_reply.started":"2023-11-09T13:29:44.220877Z","shell.execute_reply":"2023-11-09T13:29:44.226432Z"},"trusted":true},"execution_count":null,"outputs":[]}]}