{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"b320e6b2-1761-2a7c-1dec-6e0d021fba51"},"source":""},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"8dd5bd3b-19eb-5164-79f0-4cd6e8da111b"},"outputs":[],"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\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c797e9e4-7628-b275-9245-07b0aaf897d4"},"outputs":[],"source":"dtypes = {'display_id': int, 'ad_id': int, 'clicked': int}\ntrain = pd.read_csv(\"../input/clicks_train.csv\", dtype=dtypes)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"4c53539b-c241-4ecb-dbbc-a8a124b7b401"},"outputs":[],"source":"p_clicks = train.groupby(by='ad_id')['clicked'].mean()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"611f8a1e-d5e6-6c70-f961-d1e21b19a206"},"outputs":[],"source":"def click_prob(ad):\n    '''not all _test ads will have been seen in _train'''\n    try:\n        prob = p_clicks[ad]\n    except:\n        prob = 0\n    return prob"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"51e2d680-495d-319e-59d2-3f74ae97a378"},"outputs":[],"source":"test = pd.read_csv(\"../input/clicks_test.csv\", dtype=dtypes)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ecc7a2a3-23d7-a5b2-e65c-cae3a4819b73"},"outputs":[],"source":"train.ad_id.max(), test.ad_id.max()"}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.5.2"}},"nbformat":4,"nbformat_minor":0}