{"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)\nimport glob","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-24T18:32:57.528925Z","iopub.execute_input":"2022-08-24T18:32:57.529457Z","iopub.status.idle":"2022-08-24T18:32:57.535839Z","shell.execute_reply.started":"2022-08-24T18:32:57.529411Z","shell.execute_reply":"2022-08-24T18:32:57.534722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"paths = [x for x in glob.glob('../input/*/*.csv') if 'amex-default-prediction' not in x]\npaths","metadata":{"execution":{"iopub.status.busy":"2022-08-24T18:45:45.069768Z","iopub.execute_input":"2022-08-24T18:45:45.070170Z","iopub.status.idle":"2022-08-24T18:45:45.085963Z","shell.execute_reply.started":"2022-08-24T18:45:45.070140Z","shell.execute_reply":"2022-08-24T18:45:45.085098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weights = [0.83, 1.0, 0.5, 0.5, 0.9, 1, 1, 0.9]","metadata":{"execution":{"iopub.status.busy":"2022-08-22T19:06:56.482460Z","iopub.execute_input":"2022-08-22T19:06:56.483076Z","iopub.status.idle":"2022-08-22T19:06:56.487968Z","shell.execute_reply.started":"2022-08-22T19:06:56.483043Z","shell.execute_reply":"2022-08-22T19:06:56.486946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfs = [pd.read_csv(x) for x in paths]\ndfs = [x.sort_values(by='customer_ID') for x in dfs]","metadata":{"execution":{"iopub.status.busy":"2022-08-22T19:06:56.491069Z","iopub.execute_input":"2022-08-22T19:06:56.491902Z","iopub.status.idle":"2022-08-22T19:07:16.270124Z","shell.execute_reply.started":"2022-08-22T19:06:56.491865Z","shell.execute_reply":"2022-08-22T19:07:16.268976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for df in dfs:\n    df['prediction'] = np.clip(df['prediction'], 0, 1)","metadata":{"execution":{"iopub.status.busy":"2022-08-22T15:18:35.204439Z","iopub.execute_input":"2022-08-22T15:18:35.205794Z","iopub.status.idle":"2022-08-22T15:18:35.312605Z","shell.execute_reply.started":"2022-08-22T15:18:35.205727Z","shell.execute_reply":"2022-08-22T15:18:35.311178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit = pd.read_csv('../input/amex-default-prediction/sample_submission.csv')\nsubmit['prediction'] = 0\n\nfor df, weight in zip(dfs, weights):\n    submit['prediction'] += (df['prediction'] * weight)\n    \nsubmit['prediction'] /= np.sum(weights)\n\nsubmit.to_csv('mean_submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T10:16:47.440432Z","iopub.execute_input":"2022-08-01T10:16:47.440815Z","iopub.status.idle":"2022-08-01T10:16:52.513851Z","shell.execute_reply.started":"2022-08-01T10:16:47.440782Z","shell.execute_reply":"2022-08-01T10:16:52.512829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit = pd.read_csv('../input/amex-default-prediction/sample_submission.csv')\nsubmit['prediction'] = 0\n\nfrom scipy.stats import rankdata\n\nfor df, weight in zip(dfs, weights):\n    submit['prediction'] += (rankdata(df['prediction'])/df.shape[0]) * weight\n    \nsubmit['prediction'] /= 4\n\nsubmit.to_csv('submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-01T10:16:53.765387Z","iopub.execute_input":"2022-08-01T10:16:53.7658Z","iopub.status.idle":"2022-08-01T10:16:59.066936Z","shell.execute_reply.started":"2022-08-01T10:16:53.765768Z","shell.execute_reply":"2022-08-01T10:16:59.065907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}