{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":104854,"databundleVersionId":12637092,"isSourceIdPinned":false,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-09T14:27:49.014031Z","iopub.execute_input":"2025-06-09T14:27:49.014436Z","iopub.status.idle":"2025-06-09T14:27:51.413824Z","shell.execute_reply.started":"2025-06-09T14:27:49.014407Z","shell.execute_reply":"2025-06-09T14:27:51.412647Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Загрузка данных\ndf_train = pd.read_parquet(\"/kaggle/input/alpha-summer-challenge/train.pa\")\ndf_txn   = pd.read_parquet(\"/kaggle/input/alpha-summer-challenge/df_transaction.pa\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-09T14:27:51.414895Z","iopub.execute_input":"2025-06-09T14:27:51.415447Z","iopub.status.idle":"2025-06-09T14:28:01.191652Z","shell.execute_reply.started":"2025-06-09T14:27:51.415418Z","shell.execute_reply":"2025-06-09T14:28:01.190559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Определяем клиентов в тесте\ntest_clients = (\n    df_txn.loc[~df_txn.client_num.isin(df_train.client_num), \"client_num\"]\n    .unique()\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-09T14:28:01.193434Z","iopub.execute_input":"2025-06-09T14:28:01.193708Z","iopub.status.idle":"2025-06-09T14:28:01.475387Z","shell.execute_reply.started":"2025-06-09T14:28:01.193685Z","shell.execute_reply":"2025-06-09T14:28:01.474366Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Вычисляем распределение классов в train\nclass_probs = (\n    df_train[\"target\"]\n    .value_counts(normalize=True)\n    .sort_index()\n    .values\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-09T14:28:01.476554Z","iopub.execute_input":"2025-06-09T14:28:01.476886Z","iopub.status.idle":"2025-06-09T14:28:01.495431Z","shell.execute_reply.started":"2025-06-09T14:28:01.476851Z","shell.execute_reply":"2025-06-09T14:28:01.494156Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Для каждого тестового клиента случайно выбираем класс согласно распределению классов в обучающей выборке\nrng = np.random.default_rng(seed=42)\n\nsubmission = pd.DataFrame({\n    \"client_num\": test_clients,\n    \"target\": rng.choice(np.arange(7), size=len(test_clients), p=class_probs)\n})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-09T14:28:01.496336Z","iopub.execute_input":"2025-06-09T14:28:01.497121Z","iopub.status.idle":"2025-06-09T14:28:01.524171Z","shell.execute_reply.started":"2025-06-09T14:28:01.497079Z","shell.execute_reply":"2025-06-09T14:28:01.523164Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Сохраняем сабмит\nsubmission.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-09T14:28:01.525253Z","iopub.execute_input":"2025-06-09T14:28:01.525635Z","iopub.status.idle":"2025-06-09T14:28:01.582212Z","shell.execute_reply.started":"2025-06-09T14:28:01.525602Z","shell.execute_reply":"2025-06-09T14:28:01.581151Z"}},"outputs":[],"execution_count":null}]}