{"cells":[{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":false},"cell_type":"markdown","source":"# Joke Submissions for the GA Customer Revenue Prediction Competition\nBecause life is too short, this workbook: <br>\n1. Generates a submission file that predicts **no return customers** (because the proportion of return to new customers in a given time period is **TINY**, and this will likely be a hard benchmark to beat come Feb!)\n2. Generates a submission file that calculates the **right answer** through aggregating the revenue per customer in the test file - in essence, calculating the \"hidden\" answer (because it feels great being at the top of a leaderboard, even when you know your method cannot generalize :p)"},{"metadata":{"trusted":true,"_uuid":"5d683de656666a186f695f9ee20d5fe29478352e"},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport ast # for dict parsing down the track","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f824d8466f3eabc158fa1ba69c7aebc210311517"},"cell_type":"code","source":"test = pd.read_csv('../input/test_v2.csv',dtype={'fullVisitorId': 'str'})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5a055115266700e8305e241d4683ded230e6fcee"},"cell_type":"code","source":"submission_sample = pd.read_csv('../input/sample_submission_v2.csv',dtype={'fullVisitorId': 'str'})\nsubmission_sample.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e415e9a634d7cafae6a3d51c94d3de6eaf0720e5"},"cell_type":"code","source":"submission_sample.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ad4cf7c5575f1c8d4fb077181598ad310bcb4037"},"cell_type":"code","source":"test.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"cde7c56067dcb54c1464508a979cd490fb132021"},"cell_type":"markdown","source":"## 1. Submission File Predicting No Return Customers"},{"metadata":{"trusted":true,"_uuid":"c9ca04cb97d2764c3d26460ce4cd2de3fa91ce5e"},"cell_type":"code","source":"test_prep = test.copy()\ntest_prep['PredictedLogRevenue'] = 0\nsubmission_no_return = test_prep.groupby('fullVisitorId',as_index=False).PredictedLogRevenue.sum()\nsubmission_no_return.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9a67d062d893d22b1a62e18b193c481e59aa183e"},"cell_type":"code","source":"submission_no_return.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"86e252f31ad4f47c812bf6c36c6bd0ed6d0971ee"},"cell_type":"code","source":"submission_no_return.to_csv('submission_no_return.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4bedab23cecd6e955e2f4011f7a3bf350f531328"},"cell_type":"markdown","source":"## 2. Submission File Aggregating Right Answer"},{"metadata":{"trusted":true,"_uuid":"33da1ca5c61d803b9bb45862e61a51a582c8d537"},"cell_type":"code","source":"test_prep_2 = test.copy()\ntest_prep_2['Revenue'] = test_prep_2['totals'].apply(lambda x: ast.literal_eval(x).get('transactionRevenue',np.nan))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aecefb2795601b8e9dbf5761977db80eb056bdcf"},"cell_type":"code","source":"test_prep_2['Revenue'] =pd.to_numeric(test_prep_2['Revenue'],errors='coerce')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a46e0a3ea7c221b0e39314e04ad2787432b5545b"},"cell_type":"code","source":"submission_right_answer = test_prep_2.groupby('fullVisitorId',as_index=False).Revenue.sum()\nsubmission_right_answer['PredictedLogRevenue'] = submission_right_answer.Revenue.apply(lambda x: np.log(x+1))\nsubmission_right_answer.drop(columns='Revenue',inplace=True)\nsubmission_right_answer.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c1d88b7ca149643fc56e0381fea23d77dc456c30"},"cell_type":"code","source":"submission_right_answer.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2b8500c307775e2028ba27946cab8a7d4fa4cbde"},"cell_type":"code","source":"submission_right_answer.to_csv('submission_right_answer.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"65e163e462cf6c8a26a868113207451c73e0866f"},"cell_type":"markdown","source":"## 3. How do these perform?\nNo return customers? Scores **RMSE of 2.11** <br>\n![Predictably bad](https://imgur.com/YSxDQbh.png)\nRight answer? Scores **RMSE of 0.00** <br>\n![So good](https://imgur.com/roUWAdp.png)\n"},{"metadata":{"_uuid":"fa0ceb79fb027945559a9f9705764925989d7118"},"cell_type":"markdown","source":"# End Joke"}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}