{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":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\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 5GB 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","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Since data is huge, it is not possible to load at once, needs to be splitted into chunks. ","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import zipfile\n\nzf = zipfile.ZipFile('../input/bosch-production-line-performance/train_numeric.csv.zip') \ntrain_numeric_chunks = pd.read_csv(zf.open('train_numeric.csv'), iterator=True, chunksize=100000)\n\nzf = zipfile.ZipFile('../input/bosch-production-line-performance/train_categorical.csv.zip') \ntrain_categorical_chunks = pd.read_csv(zf.open('train_categorical.csv'), iterator=True, chunksize=100000, low_memory=False)\n\nzf = zipfile.ZipFile('../input/bosch-production-line-performance/train_date.csv.zip') \ntrain_date_chunks = pd.read_csv(zf.open('train_date.csv'), iterator=True, chunksize=100000)\n\npd.options.display.max_columns = None\npd.options.display.max_rows = None","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Total number of lines in train csv files is 1183747","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"'''\ntotal_number_of_lines_numeric = 0\ntotal_number_of_lines_categorical = 0\ntotal_number_of_lines_date = 0\n\nfor chunk in train_numeric_chunks:\n    total_number_of_lines_numeric += chunk.shape[0]\n\nfor chunk in train_categorical_chunks:\n    total_number_of_lines_categorical += chunk.shape[0]\n    \nfor chunk in train_date_chunks:\n    total_number_of_lines_date += chunk.shape[0]\n    \nprint(\"Number of lines in numeric data is {}\".format(total_number_of_lines_numeric))\nprint(\"Number of lines in categorical data is {}\".format(total_number_of_lines_categorical))\nprint(\"Number of lines in date data is {}\".format(total_number_of_lines_date))\n'''\n\ntotal_number_of_lines_numeric = 1183747\ntotal_number_of_lines_categorical = 1183747\ntotal_number_of_lines_date = 1183747","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Generator structure is used for loading chunks","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_numeric_frame():\n    for data_frame in train_numeric_chunks:\n        yield data_frame\n        \ndef get_categorical_frame():\n    for data_frame in train_categorical_chunks:\n        yield data_frame\n        \ndef get_date_frame():\n    for data_frame in train_date_chunks:\n        yield data_frame\n\nget_df_numeric = get_numeric_frame()\nget_df_categorical = get_categorical_frame()\nget_df_date = get_date_frame()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_numeric = next(get_df_numeric)\ndf_categorical = next(get_df_categorical)\ndf_date = next(get_df_date)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **NUMERIC**","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"Numeric data has 970 feature columns starting with *Id* ending with *Response*","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df_numeric.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"numeric has {} columns\".format(len(df_numeric.columns)))\n#df_numeric.columns.tolist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#df_numeric\ndf_numeric.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_numeric.describe()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **CATEGORICAL**","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"2141 feature columns","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df_categorical.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"categorical has {} columns\".format(len(df_categorical.columns)))\n#df_categorical.columns.tolist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#df_categorical\ndf_categorical.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_categorical.describe()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# **DATE**","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"1157 feature columns","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df_date.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"date has {} columns\".format(len(df_date.columns)))\n#df_date.columns.tolist()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#df_date\ndf_date.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_date.describe()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# FAIL PARTS","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"fail_parts_numeric = df_numeric[df_numeric.Response == 1]\nfail_parts_categorical = df_categorical[df_numeric.Response == 1]\nfail_parts_date = df_date[df_numeric.Response == 1]\nworking_parts = df_numeric[df_numeric.Response == 0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"Number of fails in first 100000 parts: {}\".format(len(fail_parts_numeric)))\nprint(\"Number of working parts in first 100000 parts: {}\".format(len(working_parts)))\nprint(\"Fail/Working ratio: {}\".format(len(fail_parts_numeric)/len(working_parts)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_numeric['Response'].value_counts().sort_index().plot.bar()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#fail_parts_numeric\nfail_parts_numeric.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#fail_parts_categorical\nfail_parts_categorical.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#fail_parts_date\nfail_parts_date.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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":4}