{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":59094,"databundleVersionId":7010844,"sourceType":"competition"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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\nimport torch\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nprint(f'Using{device}')\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-08-26T14:04:56.034212Z","iopub.execute_input":"2024-08-26T14:04:56.035060Z","iopub.status.idle":"2024-08-26T14:05:00.722521Z","shell.execute_reply.started":"2024-08-26T14:04:56.035027Z","shell.execute_reply":"2024-08-26T14:05:00.721485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Processing","metadata":{}},{"cell_type":"code","source":"df = pd.read_parquet('../input/open-problems-single-cell-perturbations/de_train.parquet')\ndf.tail()","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:10.930565Z","iopub.execute_input":"2024-08-26T14:07:10.930939Z","iopub.status.idle":"2024-08-26T14:07:12.354944Z","shell.execute_reply.started":"2024-08-26T14:07:10.930912Z","shell.execute_reply":"2024-08-26T14:07:12.353762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"column_array = df['SMILES'].values","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:12.356826Z","iopub.execute_input":"2024-08-26T14:07:12.357177Z","iopub.status.idle":"2024-08-26T14:07:12.362359Z","shell.execute_reply.started":"2024-08-26T14:07:12.357145Z","shell.execute_reply":"2024-08-26T14:07:12.361473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##column_array","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:11:08.615543Z","iopub.execute_input":"2024-07-11T14:11:08.615781Z","iopub.status.idle":"2024-07-11T14:11:08.623361Z","shell.execute_reply.started":"2024-07-11T14:11:08.615760Z","shell.execute_reply":"2024-07-11T14:11:08.622423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Loader","metadata":{}},{"cell_type":"markdown","source":"# Building Experts","metadata":{}},{"cell_type":"markdown","source":"# final trial","metadata":{}},{"cell_type":"code","source":"feature_cols =['cell_type','sm_name']\ntarget_cols = ['cell_type','sm_name','sm_lincs_id','SMILES','control']\ntargets = df.drop(columns=target_cols)\nfeatures = pd.DataFrame(df,columns=feature_cols)\nfeatures","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:16.846017Z","iopub.execute_input":"2024-08-26T14:07:16.846650Z","iopub.status.idle":"2024-08-26T14:07:16.891979Z","shell.execute_reply.started":"2024-08-26T14:07:16.846621Z","shell.execute_reply":"2024-08-26T14:07:16.890911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import OneHotEncoder\none_hot = OneHotEncoder()\nfeatures_array = one_hot.fit_transform(features)","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:18.648233Z","iopub.execute_input":"2024-08-26T14:07:18.648583Z","iopub.status.idle":"2024-08-26T14:07:19.102443Z","shell.execute_reply.started":"2024-08-26T14:07:18.648551Z","shell.execute_reply":"2024-08-26T14:07:19.101405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features_array.shape","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:20.961037Z","iopub.execute_input":"2024-08-26T14:07:20.961976Z","iopub.status.idle":"2024-08-26T14:07:20.967855Z","shell.execute_reply.started":"2024-08-26T14:07:20.961941Z","shell.execute_reply":"2024-08-26T14:07:20.966771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features_one_hot=features_array\nprint(features_one_hot.toarray().shape)\n","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:21.383097Z","iopub.execute_input":"2024-08-26T14:07:21.383482Z","iopub.status.idle":"2024-08-26T14:07:21.389979Z","shell.execute_reply.started":"2024-08-26T14:07:21.383452Z","shell.execute_reply":"2024-08-26T14:07:21.388975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\n# Split the data into 70% training, 15% validation, and 15% testing\nX_train, X_temp, y_train, y_temp = train_test_split(features_one_hot, targets.values, test_size=0.1, shuffle=False)\nX_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:21.770065Z","iopub.execute_input":"2024-08-26T14:07:21.770438Z","iopub.status.idle":"2024-08-26T14:07:21.927988Z","shell.execute_reply.started":"2024-08-26T14:07:21.770410Z","shell.execute_reply":"2024-08-26T14:07:21.927090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"featurespace = features_one_hot.toarray()\ntargetsspace = targets.values\ntargetsspace.shape","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:22.143268Z","iopub.execute_input":"2024-08-26T14:07:22.143761Z","iopub.status.idle":"2024-08-26T14:07:22.150655Z","shell.execute_reply.started":"2024-08-26T14:07:22.143730Z","shell.execute_reply":"2024-08-26T14:07:22.149768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from torch.utils.data import DataLoader,Dataset\nclass dataset(Dataset):\n    def __init__(self,X_train,y_train):\n        self.X_train=X_train\n        self.y_train=y_train\n    def __len__(self):\n        return len(self.X_train)\n    def __getitem__(self,idx):\n        return self.X_train[idx], self.y_train[idx]","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:22.569033Z","iopub.execute_input":"2024-08-26T14:07:22.569418Z","iopub.status.idle":"2024-08-26T14:07:22.575353Z","shell.execute_reply.started":"2024-08-26T14:07:22.569388Z","shell.execute_reply":"2024-08-26T14:07:22.574290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\n\nfeatures_t= torch.tensor(featurespace).to(device)\ntarget_t=torch.tensor(targetsspace).to(device)\ndata=dataset(features_t,target_t)\ntarget_t.shape","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:23.009833Z","iopub.execute_input":"2024-08-26T14:07:23.010182Z","iopub.status.idle":"2024-08-26T14:07:23.242598Z","shell.execute_reply.started":"2024-08-26T14:07:23.010155Z","shell.execute_reply":"2024-08-26T14:07:23.241717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batchsize=64\ndataloader = torch.utils.data.DataLoader(data,batch_size=batchsize,shuffle=True)\nfor batch,(x,y) in enumerate(dataloader):\n    print('batch',batch,x.shape,y.shape)","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:23.493676Z","iopub.execute_input":"2024-08-26T14:07:23.494022Z","iopub.status.idle":"2024-08-26T14:07:23.549704Z","shell.execute_reply.started":"2024-08-26T14:07:23.493996Z","shell.execute_reply":"2024-08-26T14:07:23.548830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_absolute_error\nimport numpy as np\nfrom scipy.sparse import issparse\n\n# Define custom loss function\nclass LogCoshLoss(nn.Module):\n    def __init__(self):\n        super().__init__()\n    \n    def forward(self, y_prime_t, y_t):\n        ey_t = (y_t - y_prime_t) / 3  # divide by 3 to avoid numerical overflow in cosh\n        return torch.mean(torch.log(torch.cosh(ey_t + 1e-12)))\n\n# Define expert models\nclass Conv(nn.Module):\n    def __init__(self, scheme, input_channels=1):\n        super(Conv, self).__init__()\n        self.name = 'Conv'\n        self.conv_block = nn.Sequential(\n            nn.Conv1d(input_channels, 32, kernel_size=5, stride=1, padding=2),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.Conv1d(32, 64, kernel_size=5, stride=2, padding=2),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.Conv1d(64, 128, kernel_size=5, stride=2, padding=2),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.AdaptiveAvgPool1d(1),\n            nn.Flatten())\n        self.linear = nn.Sequential(\n            nn.Linear(128, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.Linear(512, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3)\n        )\n        self.head1 = nn.Linear(512, output_size)\n        \n    def forward(self, x):\n        # Ensure input is 3D: (batch_size, channels, sequence_length)\n        if x.dim() == 2:\n            x = x.unsqueeze(1)\n        out = self.conv_block(x)\n        out = self.linear(out)\n        out = self.head1(out)\n        return out\n\nclass LSTM(nn.Module):\n    def __init__(self, scheme, input_size, output_size):\n        super(LSTM, self).__init__()\n        self.name = 'LSTM'\n        self.lstm = nn.LSTM(input_size, 128, num_layers=2, batch_first=True)\n        self.linear = nn.Sequential(\n            nn.Linear(128, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.Linear(512, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3)\n        )\n        self.head1 = nn.Linear(512, output_size)\n        \n    def forward(self, x):\n        # Ensure input is 3D: (batch_size, sequence_length, input_size)\n        if x.dim() == 2:\n            x = x.unsqueeze(1)  # Add sequence dimension\n        \n        batch_size, seq_len, _ = x.size()\n        \n        out, (hn, cn) = self.lstm(x)\n        \n        if seq_len == 1:\n            out = out.squeeze(1)  # Remove sequence dimension if it's 1\n        else:\n            out = out[:, -1, :]  # Take the last time step\n        \n        out = self.linear(out)\n        out = self.head1(out)\n        return out\n\nclass GRU(nn.Module):\n    def __init__(self, scheme, input_size, output_size):\n        super(GRU, self).__init__()\n        self.name = 'GRU'\n        self.gru = nn.GRU(input_size, 128, num_layers=2, batch_first=True)\n        self.linear = nn.Sequential(\n            nn.Linear(128, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3),\n            nn.Linear(512, 512),\n            nn.ReLU(),\n            nn.Dropout(0.3)\n        )\n        self.head1 = nn.Linear(512, output_size)\n        \n    def forward(self, x):\n        # Ensure input is 3D: (batch_size, sequence_length, input_size)\n        if x.dim() == 2:\n            x = x.unsqueeze(1)  # Add sequence dimension\n        \n        batch_size, seq_len, _ = x.size()\n        \n        out, hn = self.gru(x)\n        \n        if seq_len == 1:\n            out = out.squeeze(1)  # Remove sequence dimension if it's 1\n        else:\n            out = out[:, -1, :]  # Take the last time step\n        \n        out = self.linear(out)\n        out = self.head1(out)\n        return out\n\n# Define Gating Network\nclass GatingNetwork(nn.Module):\n    def __init__(self, input_size, num_experts):\n        super(GatingNetwork, self).__init__()\n        self.linear1 = nn.Linear(input_size, 64)\n        self.relu = nn.ReLU()\n        self.linear2 = nn.Linear(64, num_experts)\n        self.softmax = nn.Softmax(dim=-1)\n    \n    def forward(self, data):\n        x = self.linear1(data)\n        x = self.relu(x)\n        x = self.linear2(x)\n        x = self.softmax(x)\n        return x\n\n# Define Mixture of Experts model\nclass MixtureOfExperts(nn.Module):\n    def __init__(self, input_size, output_size, scheme):\n        super(MixtureOfExperts, self).__init__()\n        self.experts = nn.ModuleList([\n            Conv(scheme, input_channels=1),\n            LSTM(scheme, input_size, output_size),\n            GRU(scheme, input_size, output_size)\n        ])\n        self.gating_network = GatingNetwork(input_size, len(self.experts))\n        self.loss1 = nn.MSELoss()\n        self.loss2 = LogCoshLoss()\n        self.loss3 = nn.L1Loss()\n        self.loss4 = nn.BCELoss()\n    \n    def forward(self, data, y=None):\n        data = data.float()\n        \n        gating_weights = self.gating_network(data)\n        \n        expert_outputs = []\n        for i, expert in enumerate(self.experts):\n            if i == 0:  # Conv\n                expert_input = data.unsqueeze(1) if data.dim() == 2 else data\n            else:  # LSTM and GRU\n                expert_input = data if data.dim() == 3 else data.unsqueeze(1)\n            \n            output = expert(expert_input)\n            expert_outputs.append(output)\n        \n        expert_outputs = torch.stack(expert_outputs, dim=1)\n        combined_output = torch.sum(expert_outputs * gating_weights.unsqueeze(-1), dim=1)\n        \n        if y is None:\n            return combined_output\n        else:\n            y = y.float()\n            loss1 = 0.4 * self.loss1(combined_output, y) + 0.3 * self.loss2(combined_output, y) + 0.3 * self.loss3(combined_output, y)\n            yhat = torch.sigmoid(combined_output)\n            yy = torch.sigmoid(y)\n            loss2 = self.loss4(yhat, yy)\n            return 0.8 * loss1 + 0.2 * loss2\n# Define RMSE rowwise loss\ndef RMSE_rowwise_loss(model, data, y_true):\n    model.eval()\n    with torch.no_grad():\n        y_pred_original = model(data.float())\n    mae = mean_absolute_error(y_true.numpy(), y_pred_original.numpy())\n    rowwise_rmse = np.sqrt(np.mean(np.square(y_true.numpy() - y_pred_original.numpy()), axis=1))\n    mrrmse_score = np.mean(rowwise_rmse)\n    return mrrmse_score\n\n# Usage\ninput_size = 152\noutput_size = 18211\nscheme = 'initial'\nepochs = 2000\n\nmodel = MixtureOfExperts(input_size, output_size, scheme)\nmodel = model.float()\nmodel = model.to(device)\n\n\noptimizer = torch.optim.Adam(model.parameters(), lr=0.001)","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:23.909799Z","iopub.execute_input":"2024-08-26T14:07:23.910127Z","iopub.status.idle":"2024-08-26T14:07:26.958291Z","shell.execute_reply.started":"2024-08-26T14:07:23.910103Z","shell.execute_reply":"2024-08-26T14:07:26.957495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(model)","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:13:41.317195Z","iopub.execute_input":"2024-08-26T14:13:41.317963Z","iopub.status.idle":"2024-08-26T14:13:41.324296Z","shell.execute_reply.started":"2024-08-26T14:13:41.317930Z","shell.execute_reply":"2024-08-26T14:13:41.322697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import logging\n# Set up logging\nlogging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')\n\ndef train_model(model, data, optimizer, epochs, batch_size, device):\n    dataloader = DataLoader(data, batch_size=batch_size, shuffle=True)\n    \n    for epoch in range(epochs):\n        model.train()\n        epoch_loss = 0\n        total_batches = 0\n        \n        for batch, (x, y) in enumerate(dataloader):\n            x = x.float().to(device)\n            y = y.float().to(device)\n            \n            optimizer.zero_grad()\n            try:\n                loss = model(x, y)\n                loss.backward()\n                optimizer.step()\n                \n                epoch_loss += loss.item()\n                total_batches += 1\n            except RuntimeError as e:\n                print(f\"Error in epoch {epoch+1}, batch {batch+1}: {str(e)}\")\n                print(f\"Input shapes: x: {x.shape}, y: {y.shape}\")\n                continue\n        \n        avg_loss = epoch_loss / total_batches\n        print(f'Epoch {epoch+1}/{epochs} completed. Average loss: {avg_loss:.4f}')\n\n# Usage\nepochs = 2000\nbatch_size = 64\ntrain_model(model, data, optimizer, epochs, batch_size, device)","metadata":{"execution":{"iopub.status.busy":"2024-08-26T14:07:26.959697Z","iopub.execute_input":"2024-08-26T14:07:26.960109Z","iopub.status.idle":"2024-08-26T14:07:37.510116Z","shell.execute_reply.started":"2024-08-26T14:07:26.960083Z","shell.execute_reply":"2024-08-26T14:07:37.508814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# import torch.optim as optim\n# from torch.autograd import Variable\n\n# input_size = 152\n# output_size = 18211\n# num_experts = 5\n# epochs = 200\n\n# # Create the model\n# model = MixtureOfExperts(input_size, output_size, num_experts)\n\n# # Define the optimizer\n# optimizer = optim.Adam(model.parameters(), lr=0.001)\n\n# for epoch in range(0, epochs):\n#     for batch, (feature_train, target_train) in enumerate(dataloader):\n#         optimizer.zero_grad()\n#         loss = RMSE_rowwise_loss(model, feature_train.float(), target_train.float())\n#         loss = Variable(torch.tensor(loss), requires_grad=True)\n#         loss.backward()\n#         optimizer.step()\n#     if epoch % 5 == 0:\n#         print(f\"epoch: {epoch + 1} loss: {loss}\")","metadata":{"execution":{"iopub.status.busy":"2024-07-11T09:49:44.939854Z","iopub.execute_input":"2024-07-11T09:49:44.940208Z","iopub.status.idle":"2024-07-11T09:49:44.944982Z","shell.execute_reply.started":"2024-07-11T09:49:44.940180Z","shell.execute_reply":"2024-07-11T09:49:44.944037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_map = pd.read_csv(\"/kaggle/input/open-problems-single-cell-perturbations/id_map.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:39.007994Z","iopub.execute_input":"2024-07-11T14:17:39.008721Z","iopub.status.idle":"2024-07-11T14:17:39.028727Z","shell.execute_reply.started":"2024-07-11T14:17:39.008688Z","shell.execute_reply":"2024-07-11T14:17:39.027987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testdata = pd.DataFrame(id_map,columns=feature_cols) \n#testdata.head()","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:40.249825Z","iopub.execute_input":"2024-07-11T14:17:40.250216Z","iopub.status.idle":"2024-07-11T14:17:40.255337Z","shell.execute_reply.started":"2024-07-11T14:17:40.250161Z","shell.execute_reply":"2024-07-11T14:17:40.254365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"one_hot_test = one_hot.transform(testdata)\nprint(features_one_hot.toarray().shape,one_hot_test.toarray().shape)","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:42.359811Z","iopub.execute_input":"2024-07-11T14:17:42.360451Z","iopub.status.idle":"2024-07-11T14:17:42.368120Z","shell.execute_reply.started":"2024-07-11T14:17:42.360417Z","shell.execute_reply":"2024-07-11T14:17:42.367038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.eval()\ntarget_pred = model(torch.Tensor(one_hot_test.toarray()).to(device))","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:45.445530Z","iopub.execute_input":"2024-07-11T14:17:45.445892Z","iopub.status.idle":"2024-07-11T14:17:45.460540Z","shell.execute_reply.started":"2024-07-11T14:17:45.445863Z","shell.execute_reply":"2024-07-11T14:17:45.459693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res = target_pred.cpu()","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:46.915622Z","iopub.execute_input":"2024-07-11T14:17:46.916242Z","iopub.status.idle":"2024-07-11T14:17:46.935250Z","shell.execute_reply.started":"2024-07-11T14:17:46.916199Z","shell.execute_reply":"2024-07-11T14:17:46.934540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.eval()","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:47.914111Z","iopub.execute_input":"2024-07-11T14:17:47.914998Z","iopub.status.idle":"2024-07-11T14:17:47.921989Z","shell.execute_reply.started":"2024-07-11T14:17:47.914965Z","shell.execute_reply":"2024-07-11T14:17:47.921047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv(\"/kaggle/input/open-problems-single-cell-perturbations/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:53.576805Z","iopub.execute_input":"2024-07-11T14:17:53.577190Z","iopub.status.idle":"2024-07-11T14:17:56.489448Z","shell.execute_reply.started":"2024-07-11T14:17:53.577146Z","shell.execute_reply":"2024-07-11T14:17:56.488596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_columns = sample_submission.columns\nsample_columns= sample_columns[1:]\nsubmission_df = pd.DataFrame(res.detach().numpy(), columns=sample_columns)","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:17:56.490843Z","iopub.execute_input":"2024-07-11T14:17:56.491138Z","iopub.status.idle":"2024-07-11T14:17:56.496412Z","shell.execute_reply.started":"2024-07-11T14:17:56.491112Z","shell.execute_reply":"2024-07-11T14:17:56.495436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.insert(0, 'id', range(255))","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:18:03.019125Z","iopub.execute_input":"2024-07-11T14:18:03.019970Z","iopub.status.idle":"2024-07-11T14:18:03.028947Z","shell.execute_reply.started":"2024-07-11T14:18:03.019938Z","shell.execute_reply":"2024-07-11T14:18:03.027904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:18:12.433991Z","iopub.execute_input":"2024-07-11T14:18:12.434373Z","iopub.status.idle":"2024-07-11T14:18:12.479556Z","shell.execute_reply.started":"2024-07-11T14:18:12.434341Z","shell.execute_reply":"2024-07-11T14:18:12.478683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:18:16.221863Z","iopub.execute_input":"2024-07-11T14:18:16.222697Z","iopub.status.idle":"2024-07-11T14:18:16.252714Z","shell.execute_reply.started":"2024-07-11T14:18:16.222664Z","shell.execute_reply":"2024-07-11T14:18:16.251739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2024-07-11T14:18:26.892059Z","iopub.execute_input":"2024-07-11T14:18:26.892915Z","iopub.status.idle":"2024-07-11T14:18:35.086481Z","shell.execute_reply.started":"2024-07-11T14:18:26.892881Z","shell.execute_reply":"2024-07-11T14:18:35.085457Z"},"trusted":true},"execution_count":null,"outputs":[]}]}