{"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)\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-05-05T00:44:41.262319Z","iopub.execute_input":"2023-05-05T00:44:41.263726Z","iopub.status.idle":"2023-05-05T00:44:41.288354Z","shell.execute_reply.started":"2023-05-05T00:44:41.263669Z","shell.execute_reply":"2023-05-05T00:44:41.287212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport polars as pl\nfrom matplotlib import pyplot as plt\nimport seaborn as sns\nplt.style.use('fivethirtyeight')\nplt.rcParams['figure.figsize'] = (30, 20)\nsns.set_style('darkgrid')","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:44:44.745734Z","iopub.execute_input":"2023-05-05T00:44:44.746244Z","iopub.status.idle":"2023-05-05T00:44:45.722851Z","shell.execute_reply.started":"2023-05-05T00:44:44.746206Z","shell.execute_reply":"2023-05-05T00:44:45.721334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_id = pl.read_csv('/kaggle/input/predict-student-performance-from-game-play/train.csv', columns = ['index'])\ndisplay(train_id)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:44:48.981073Z","iopub.execute_input":"2023-05-05T00:44:48.981547Z","iopub.status.idle":"2023-05-05T00:45:23.729960Z","shell.execute_reply.started":"2023-05-05T00:44:48.981507Z","shell.execute_reply":"2023-05-05T00:45:23.728933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp = pd.read_csv(\"/kaggle/input/predict-student-performance-from-game-play/train.csv\", usecols=[0])\ndisplay(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:46:40.276680Z","iopub.execute_input":"2023-05-05T00:46:40.277182Z","iopub.status.idle":"2023-05-05T00:47:09.567007Z","shell.execute_reply.started":"2023-05-05T00:46:40.277138Z","shell.execute_reply":"2023-05-05T00:47:09.565616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp['session_id'].hist(bins = 30)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:47:17.129245Z","iopub.execute_input":"2023-05-05T00:47:17.130172Z","iopub.status.idle":"2023-05-05T00:47:18.448430Z","shell.execute_reply.started":"2023-05-05T00:47:17.130118Z","shell.execute_reply":"2023-05-05T00:47:18.447444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp = tmp.groupby('session_id').session_id.agg('count')\nprint(tmp)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:46:29.886341Z","iopub.execute_input":"2023-05-05T00:46:29.886880Z","iopub.status.idle":"2023-05-05T00:46:30.670184Z","shell.execute_reply.started":"2023-05-05T00:46:29.886835Z","shell.execute_reply":"2023-05-05T00:46:30.668727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp.iloc[0:5]","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:47:30.459702Z","iopub.execute_input":"2023-05-05T00:47:30.460183Z","iopub.status.idle":"2023-05-05T00:47:30.474631Z","shell.execute_reply.started":"2023-05-05T00:47:30.460142Z","shell.execute_reply":"2023-05-05T00:47:30.473400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gc\ngc.enable()\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:47:38.642917Z","iopub.execute_input":"2023-05-05T00:47:38.644259Z","iopub.status.idle":"2023-05-05T00:47:38.825621Z","shell.execute_reply.started":"2023-05-05T00:47:38.644209Z","shell.execute_reply":"2023-05-05T00:47:38.824445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ITER = 20\nPIECES = int(np.ceil(len(tmp) / ITER))\n\nreads = []\nskips = [0]\nfor k in range(ITER) :\n    a = k*PIECES\n    b = (k+1)*PIECES\n    if b>len(tmp) : b=len(tmp)\n    r = tmp.iloc[a:b].sum()\n    reads.append(r)\n    skips.append(skips[-1] + r)\nprint(f'untuk menghindari kesalahan memori, kita akan membaca kereta dalam {PIECES} ukuran potongan:')\nprint(reads)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:47:42.240226Z","iopub.execute_input":"2023-05-05T00:47:42.240683Z","iopub.status.idle":"2023-05-05T00:47:42.308837Z","shell.execute_reply.started":"2023-05-05T00:47:42.240648Z","shell.execute_reply":"2023-05-05T00:47:42.307595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n_train = len(train_id)","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:48:05.858632Z","iopub.execute_input":"2023-05-05T00:48:05.859181Z","iopub.status.idle":"2023-05-05T00:48:05.864293Z","shell.execute_reply.started":"2023-05-05T00:48:05.859137Z","shell.execute_reply":"2023-05-05T00:48:05.863249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gc\ngc.enable()\ndel train_id\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:48:10.691068Z","iopub.execute_input":"2023-05-05T00:48:10.691517Z","iopub.status.idle":"2023-05-05T00:48:10.883107Z","shell.execute_reply.started":"2023-05-05T00:48:10.691481Z","shell.execute_reply":"2023-05-05T00:48:10.881950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtyping = {\n    'session_id' : np.uint64,\n    'index' : np.uint16,\n    'elapsed_time' : np.uint16,\n    'event_name' : 'category',\n    'name' : 'category',\n    'level' : np.uint8,\n    'page' : np.uint16,\n    'room_coor_x' : np.float16,\n    'room_coor_y' : np.float16,\n    'screen_coor_x' : np.float16,\n    'screen_coor_y' : np.float16,\n    'hover_duration' : np.float16,\n    'text' : 'category',\n    'fqid' : 'category',\n    'room_fqid' : 'category',\n    'text_fqid' : 'category',\n    'fullscreen' : np.bool8,\n    'hq' : np.bool8,\n    'music' : np.bool8,\n    'level_group' : 'category'\n}","metadata":{"execution":{"iopub.status.busy":"2023-05-05T00:49:39.899733Z","iopub.execute_input":"2023-05-05T00:49:39.900278Z","iopub.status.idle":"2023-05-05T00:49:39.908660Z","shell.execute_reply.started":"2023-05-05T00:49:39.900232Z","shell.execute_reply":"2023-05-05T00:49:39.907206Z"},"trusted":true},"execution_count":null,"outputs":[]}]}