{"cells":[{"metadata":{"_uuid":"68d63ad5d73c918482569f58d67c05c17128f4c7"},"cell_type":"markdown","source":"Plot of time series for each class to see if a [rainflow cycle counting](https://en.wikipedia.org/wiki/Rainflow-counting_algorithm) algorithm can help in the classification."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\n\nimport os\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train_set = pd.read_csv('../input/training_set.csv')\ntrain_md = pd.read_csv('../input/training_set_metadata.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"176f838bca395df6be0b20262bf61c68dcacb865"},"cell_type":"code","source":"train_set.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d337e0c82584a2ecbfcca8fc4c631ad2455bfd62"},"cell_type":"code","source":"train_md.head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"39ab67f48ffa7089ab4731dadf4be02ec4ec4ba0"},"cell_type":"markdown","source":"Get some random objects for each class and plot the flux for each band:"},{"metadata":{"trusted":true,"_uuid":"db966ca9f99cf15c40563da3b15b906144948b21"},"cell_type":"code","source":"class_ids = train_md['target'].unique()\nclass_ids.sort(axis=0)\noids = [(c, train_md[train_md['target']==c].sample(n=3, random_state=2018)['object_id'].values) for c in class_ids]\noids","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"4afb4f9d06256879248bee45b2423a12136f7e5b"},"cell_type":"code","source":"for cid, oid in oids:\n    plt.figure(figsize=(10, 10))\n    for band in range(6):        \n        plt.subplot(6, 1, band+1)\n        if band == 0:\n            plt.title('Target {} (object_id = {})'.format(cid, oid))\n        plt.ylabel('Band {}'.format(band))\n        for i in range(3):\n            ts = train_set[((train_set['object_id']==oid[i]) & (train_set['passband']==band))]\n            plt.plot(ts['mjd'], ts['flux'], 'x-')\n    plt.show()\n    ","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"31c461c34c06dc46c4bd31027a048f56bd6bcd5a"},"cell_type":"markdown","source":"Maybe some classes could be identified with a rainflow algorithm analyzing only the time series:\n* Target 52: band 0 has a lot of fluctuations while the other bands have only one cycle\n* Target 65: quite flat for every band\n* Target 92: many fluctuations in bands 1 to 5\n"}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}