{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","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 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 the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":1,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import pytz\nimport gc\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\n\ntr_s = 300000\nte_s = 100000\nnrows=None\n\ndtypes = {\n        'ip'            : 'uint32',\n        'app'           : 'uint16',\n        'device'        : 'uint16',\n        'os'            : 'uint16',\n        'channel'       : 'uint16',\n        'is_attributed' : 'uint8',\n        'click_id'      : 'uint32'\n        }\n\ntr = pd.read_csv('../input/train.csv', dtype=dtypes, usecols=['ip', 'is_attributed', 'click_time'], nrows=nrows).sample(tr_s)\ngc.collect()\nte = pd.read_csv('../input/test_supplement.csv', dtype=dtypes, usecols=['ip', 'click_time'], nrows=nrows).sample(te_s)\nall_df = tr.append(te)\ngc.collect()\n\ncst = pytz.timezone('Asia/Shanghai')\nall_df['click_time'] = pd.to_datetime(all_df['click_time']).dt.tz_localize(pytz.utc).dt.tz_convert(cst)\nall_df['day'] = all_df.click_time.dt.day.astype('uint8')\n\nall_df['day7'] = all_df.day == 7 # 1'st day\nall_df['day8'] = all_df.day == 8 # 2'nd day\nall_df['day9'] = all_df.day == 9 # 3'rd day\nall_df['day_test'] = all_df.day == 10 # 4'th day(test)","execution_count":6,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"936ccbc6b06db96c0f0764833c3ff723dab30138"},"cell_type":"code","source":"def print_count(df, tgt):\n    df = df[['ip', tgt]].groupby('ip')[tgt].sum().to_frame().reset_index()\n    df[tgt+'_count'] = df[tgt].rolling(window=1000).mean()\n    plt.plot(df.ip, df[tgt+'_count'])\n","execution_count":7,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"72907788e932f79489caf85804cf78eae82ed879"},"cell_type":"code","source":"print_count(all_df,'day_test')","execution_count":8,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f23f05ea4fa9b3d93522547738a86bf53ea4f3a7"},"cell_type":"code","source":"print_count(all_df,'day7')","execution_count":9,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1e8c320daee9c81701801a33e4f9c2585a053530"},"cell_type":"code","source":"print_count(all_df,'day8')","execution_count":10,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f6e578f61e631bbd20c04d4b0d21ddd028a6a7ab"},"cell_type":"code","source":"print_count(all_df,'day9')","execution_count":11,"outputs":[]},{"metadata":{"_uuid":"80271ae22206052849ba3d4d93c86240066597e8"},"cell_type":"markdown","source":"Endoding should be done by day10(test) -> day7 -> day8 -> day9.\n\nIPs between 130,000 and 220,000 did not appear on the 10th (test), but it appeared on the 7th.\n\nSo, it is no wonder that these IPs are different from the behavior of IPs that appeared on the 10th.\n\nAlso, it is not surprising that CVR differs in these groups as follows."},{"metadata":{"trusted":true,"_uuid":"26727af177684669f3c50b1efd0934f90d285483"},"cell_type":"code","source":"def print_attr(df):\n    df = df[['ip', 'is_attributed']].groupby('ip').is_attributed.mean().to_frame().reset_index()\n    df['roll'] = df.is_attributed.rolling(window=1000).mean()\n    plt.plot(df.ip, df.roll)\n\nprint_attr(all_df[all_df.day == 7])\nprint_attr(all_df[all_df.day == 8])\nprint_attr(all_df[all_df.day == 9])","execution_count":13,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}