{"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-01T10:16:16.028921Z","iopub.execute_input":"2022-08-01T10:16:16.029415Z","iopub.status.idle":"2022-08-01T10:16:16.054389Z","shell.execute_reply.started":"2022-08-01T10:16:16.029306Z","shell.execute_reply":"2022-08-01T10:16:16.053458Z"},"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-01T10:16:16.389565Z","iopub.execute_input":"2022-08-01T10:16:16.389931Z","iopub.status.idle":"2022-08-01T10:16:16.433199Z","shell.execute_reply.started":"2022-08-01T10:16:16.389901Z","shell.execute_reply":"2022-08-01T10:16:16.432466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"weights = [0.5, 0.9, 0.9, 0.5, 1, 0.8]","metadata":{"execution":{"iopub.status.busy":"2022-08-01T10:16:17.215342Z","iopub.execute_input":"2022-08-01T10:16:17.216253Z","iopub.status.idle":"2022-08-01T10:16:17.220838Z","shell.execute_reply.started":"2022-08-01T10:16:17.216212Z","shell.execute_reply":"2022-08-01T10:16:17.219850Z"},"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-01T10:16:19.049851Z","iopub.execute_input":"2022-08-01T10:16:19.050247Z","iopub.status.idle":"2022-08-01T10:16:31.480198Z","shell.execute_reply.started":"2022-08-01T10:16:19.050215Z","shell.execute_reply":"2022-08-01T10:16:31.478946Z"},"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-01T10:16:46.538021Z","iopub.execute_input":"2022-08-01T10:16:46.538449Z","iopub.status.idle":"2022-08-01T10:16:46.600034Z","shell.execute_reply.started":"2022-08-01T10:16:46.538384Z","shell.execute_reply":"2022-08-01T10:16:46.598746Z"},"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.765800Z","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":[]}]}