{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Feather format for super fast data loading\n\nOriginal `panquet` format takes time to load data. Here I converted them and uploaded with `feather` format.<br/>\nIt is about **30 times faster**.\n\nYou can see dataset here: [https://www.kaggle.com/corochann/bengaliaicv19feather](https://www.kaggle.com/corochann/bengaliaicv19feather)<br/>\nPlease upvote both dataset and this kernel if you like it! :)\n\nThis kernel describes how to load this dataset."},{"metadata":{},"cell_type":"markdown","source":"# How to add dataset\n\nWhen you write kernel, click \"+ Add Data\" botton on right top.<br/>\nThen inside window pop-up, you can see \"Search Datasets\" text box on right top.<br/>\nYou can type \"bengaliai-cv19-feather\" to find this dataset and press \"Add\" botton to add the data."},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"import gc\nimport os\nfrom pathlib import Path\nimport random\nimport sys\n\nfrom tqdm import tqdm_notebook as tqdm\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom IPython.core.display import display, HTML\n\n# --- plotly ---\nfrom plotly import tools, subplots\nimport plotly.offline as py\npy.init_notebook_mode(connected=True)\nimport plotly.graph_objs as go\nimport plotly.express as px\nimport plotly.figure_factory as ff\n\n# --- models ---\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import KFold\nimport lightgbm as lgb\nimport xgboost as xgb\nimport catboost as cb\n\n# --- setup ---\npd.set_option('max_columns', 50)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"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 in \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 \"../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# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"%%time\ndatadir = Path('/kaggle/input/bengaliai-cv19')\n\n# Read in the data CSV files\ntrain = pd.read_csv(datadir/'train.csv')\ntest = pd.read_csv(datadir/'test.csv')\nsample_submission = pd.read_csv(datadir/'sample_submission.csv')\nclass_map = pd.read_csv(datadir/'class_map.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"To load `feather` format, we just need to change `read_parquet` to `read_feather`.\n\nOriginal `parquet` format takes about 60 sec to load 1 data, while `feather` format takes about **2 sec to load 1 data!!!**"},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\ntrain_image_df0 = pd.read_parquet(datadir/'train_image_data_0.parquet')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\nfeatherdir = Path('/kaggle/input/bengaliaicv19feather')\n\ntrain_image_df0 = pd.read_feather(featherdir/'train_image_data_0.feather')\ntrain_image_df1 = pd.read_feather(featherdir/'train_image_data_1.feather')\ntrain_image_df2 = pd.read_feather(featherdir/'train_image_data_2.feather')\ntrain_image_df3 = pd.read_feather(featherdir/'train_image_data_3.feather')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"For test files, please be careful that this is **code competition** and **test data will change in the actual submission**. <br/>\nSo I guess we need to load from original `parquet` format to load private test data when submission."},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\n# Please change this to `True` when actual submission\nsubmission = False\n\nif submission:\n    test_image_df0 = pd.read_parquet(datadir/'test_image_data_0.parquet')\n    test_image_df1 = pd.read_parquet(datadir/'test_image_data_1.parquet')\n    test_image_df2 = pd.read_parquet(datadir/'test_image_data_2.parquet')\n    test_image_df3 = pd.read_parquet(datadir/'test_image_data_3.parquet')\nelse:\n    test_image_df0 = pd.read_feather(featherdir/'test_image_data_0.feather')\n    test_image_df1 = pd.read_feather(featherdir/'test_image_data_1.feather')\n    test_image_df2 = pd.read_feather(featherdir/'test_image_data_2.feather')\n    test_image_df3 = pd.read_feather(featherdir/'test_image_data_3.feather')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_image_df0.head()","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":1}