{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":59094,"databundleVersionId":7010844,"sourceType":"competition"},{"sourceId":153748170,"sourceType":"kernelVersion"},{"sourceId":153696496,"sourceType":"kernelVersion"},{"sourceId":146928847,"sourceType":"kernelVersion"}],"dockerImageVersionId":30558,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport random\nimport plotly.figure_factory as ff\nimport matplotlib.pyplot as plt\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2023-12-05T17:32:55.674144Z","iopub.execute_input":"2023-12-05T17:32:55.674483Z","iopub.status.idle":"2023-12-05T17:32:55.679371Z","shell.execute_reply.started":"2023-12-05T17:32:55.674437Z","shell.execute_reply":"2023-12-05T17:32:55.678524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import_nn = pd.read_csv('/kaggle/input/4th-place-neural-net/submission.csv', index_col='id')\nimport_lgbm = pd.read_csv('/kaggle/input/lgbm-with-gene-aggregation-4th-place-writeup/submission.csv', index_col='id')\nimport_nlp = pd.read_csv('/kaggle/input/nlp-regression/submission.csv', index_col='id')","metadata":{"execution":{"iopub.status.busy":"2023-12-05T17:33:21.835070Z","iopub.execute_input":"2023-12-05T17:33:21.835410Z","iopub.status.idle":"2023-12-05T17:33:30.976169Z","shell.execute_reply.started":"2023-12-05T17:33:21.835382Z","shell.execute_reply":"2023-12-05T17:33:30.975184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ensemble_ratio = [3, 1, 1]\nensemble_ratio = [i/sum(ensemble_ratio) for i in ensemble_ratio]\nprint(ensemble_ratio)","metadata":{"execution":{"iopub.status.busy":"2023-12-05T17:33:30.978790Z","iopub.execute_input":"2023-12-05T17:33:30.979036Z","iopub.status.idle":"2023-12-05T17:33:30.983381Z","shell.execute_reply.started":"2023-12-05T17:33:30.979015Z","shell.execute_reply":"2023-12-05T17:33:30.982796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/open-problems-single-cell-perturbations/sample_submission.csv', index_col='id')\ncol = list(submission.columns)\nsubmission[col] = import_nn[col] * ensemble_ratio[0] + import_lgbm * ensemble_ratio[1] + import_nlp * ensemble_ratio[2]","metadata":{"execution":{"iopub.status.busy":"2023-12-05T17:33:30.984384Z","iopub.execute_input":"2023-12-05T17:33:30.984633Z","iopub.status.idle":"2023-12-05T17:33:41.816500Z","shell.execute_reply.started":"2023-12-05T17:33:30.984613Z","shell.execute_reply":"2023-12-05T17:33:41.815527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Simple Postprocessing\nB_MULT = 1.5\nM_MULT = 1.3\nB_ADD = -0.12\nM_ADD = -0.1\n\n# First 128 are B next 127 Myeloid\nsubmission.iloc[:128] = submission.iloc[:128] * B_MULT + B_ADD\nsubmission.iloc[128:] = submission.iloc[128:] * M_MULT + M_ADD","metadata":{"execution":{"iopub.status.busy":"2023-12-05T16:26:13.409376Z","iopub.execute_input":"2023-12-05T16:26:13.409830Z","iopub.status.idle":"2023-12-05T16:26:18.786484Z","shell.execute_reply.started":"2023-12-05T16:26:13.409794Z","shell.execute_reply":"2023-12-05T16:26:18.784647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv')\n!ls","metadata":{"execution":{"iopub.status.busy":"2023-12-05T16:26:34.204948Z","iopub.execute_input":"2023-12-05T16:26:34.205262Z","iopub.status.idle":"2023-12-05T16:27:03.729344Z","shell.execute_reply.started":"2023-12-05T16:26:34.205240Z","shell.execute_reply":"2023-12-05T16:27:03.727884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"control_ids = [\n#     'LSM-36361'  # DMSO\n    'LSM-43181',  # Belinostat\n    'LSM-6303',  # Dabrafenib\n]\n\nprivte_ids = [\n    'LSM-45710', 'LSM-4062', \n    'LSM-2193',  #  'forskolin' -> 'Colforsin'\n    'LSM-4105', 'LSM-4031', 'LSM-1099', 'LSM-45153', 'LSM-3822', 'LSM-4933', \n    'LSM-45630',  # 'KD-025' -> 'SLx-2119'\n    'LSM-6258', 'LSM-1023', 'LSM-2655', 'LSM-47602', 'LSM-3349', 'LSM-1020', 'LSM-1143',\n    'LSM-3828', 'LSM-1051', 'LSM-1120', 'LSM-5467', 'LSM-2292', 'LSM-43293', 'LSM-45437',\n    'LSM-2703', 'LSM-45831', 'LSM-1179', 'LSM-1199', 'LSM-1190', 'LSM-36374', 'LSM-5215',\n    'LSM-1195', 'LSM-45468', 'LSM-45410', 'LSM-47459', 'LSM-45663', 'LSM-45518', 'LSM-1062',\n    'LSM-3667',  # 'BRD-K74305673' -> 'IMD-0354',\n    'LSM-1032', 'LSM-5855', 'LSM-45988',\n    'LSM-24954',  # 'BRD-K98039984' -> 'Prednisolone'\n    'LSM-6286', 'LSM-45984', 'LSM-1124', 'LSM-1165', 'LSM-42802', 'LSM-1121', 'LSM-6308',\n    'LSM-1136', 'LSM-1186', 'LSM-45915', 'LSM-2621', 'LSM-5341', 'LSM-45724', 'LSM-2219',\n    'LSM-2936', 'LSM-3171', 'LSM-46889', 'LSM-2379', 'LSM-47132', 'LSM-47120', 'LSM-47437',\n    'LSM-1139', 'LSM-1144', 'LSM-4353', 'LSM-1210', 'LSM-5887', 'LSM-1025', 'LSM-5771', 'LSM-1132',\n    'LSM-1263',  # 'BRD-A04553218' -> 'Chlorpheniramine'\n    'LSM-1167',\n    'LSM-1194',  # 'BRD-A92800748' -> 'TIE2 Kinase Inhibitor'\n    'LSM-45948', 'LSM-45514', 'LSM-5430', 'LSM-2309', \n]\n\npublic_ids = [\n    'LSM-43216', 'LSM-1050', 'LSM-45849', 'LSM-42800', 'LSM-1131', 'LSM-6335', 'LSM-1211',\n    'LSM-45239', 'LSM-1130', 'LSM-45786', 'LSM-5199', 'LSM-45281',\n    'LSM-6324', # 'ACY-1215' -> 'Ricolinostat'\n    'LSM-3309', 'LSM-1056', 'LSM-45591', 'LSM-46203', 'LSM-5662',\n    'LSM-47134',  # 'SB-2342' -> '5-(9-Isopropyl-8-methyl-2-morpholino-9H-purin-6-yl)pyrimidin-2-amine\t'\n    'LSM-45637', 'LSM-1127', 'LSM-46971', 'LSM-1172', 'LSM-46042', 'LSM-1101', 'LSM-45758',\n    'LSM-5218', 'LSM-2287', 'LSM-1014',\n    'LSM-1040', #  'fostamatinib' -> 'Tamatinib'\n    'LSM-1476;LSM-5290',\n    'LSM-45680',  # 'basimglurant' -> 'RG7090'\n    'LSM-4349',  # '5-iodotubercidin' -> 'IN1451'\n    'LSM-3425', 'LSM-45806',\n    'LSM-45616',  # 'SB-683698' -> 'TR-14035'\n    'LSM-1055',\n    'LSM-43281',  # 'C-646' -> 'STK219801'\n    'LSM-5690', 'LSM-1155', 'LSM-2499',\n    'LSM-2382',  # 'JTC-801' -> 'UNII-BXU45ZH6LI'\n    'LSM-45220', 'LSM-1037', 'LSM-1005', 'LSM-1180', 'LSM-36812',\n    'LSM-45924',  # 'filgotinib' -> 'GLPG0634'\n    'LSM-2013',  # 'TL-HRAS-61' -> TL_HRAS26'\n    'LSM-4738',\n]\n\n\ntrain_ids = [\n    'LSM-1027', 'LSM-1071', 'LSM-45916',\n    'LSM-4944',  # 'ixazomib' -> 'MLN 2238'\n    'LSM-47425',  # 'IWP-L6' -> 'Porcn Inhibitor III'\n    'LSM-1115',\n    'LSM-6237',  # 'CD-437' -> 'O-Demethylated Adapalene'\n    'LSM-1205', 'LSM-45574',\n    'LSM-4255',  # 'NVP-BEZ235' -> 'Dactolisib'\n    'LSM-1181', 'LSM-1158', 'LSM-2334', 'LSM-45496', 'LSM-1011',\n]","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-12-05T16:27:03.731524Z","iopub.execute_input":"2023-12-05T16:27:03.731809Z","iopub.status.idle":"2023-12-05T16:27:03.742686Z","shell.execute_reply.started":"2023-12-05T16:27:03.731787Z","shell.execute_reply":"2023-12-05T16:27:03.740835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def classify_id(row):\n    if row['sm_lincs_id'] in privte_ids:\n        return 'Private'\n    elif row['sm_lincs_id'] in public_ids:\n        return 'Public'\n    elif row['sm_lincs_id'] in train_ids:\n        return 'Train'\n    elif row['sm_lincs_id'] in control_ids:\n        return 'Control'\n    else:\n        return 'Other'","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2023-12-05T16:27:03.744457Z","iopub.execute_input":"2023-12-05T16:27:03.744744Z","iopub.status.idle":"2023-12-05T16:27:03.759849Z","shell.execute_reply.started":"2023-12-05T16:27:03.744722Z","shell.execute_reply":"2023-12-05T16:27:03.758460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"de_train = pd.read_parquet('/kaggle/input/open-problems-single-cell-perturbations/de_train.parquet')\ndata = de_train.copy()       \n# Apply the function to create a new column 'id_class' in the 'data' DataFrame\nlb_split = data.apply(classify_id, axis=1)\n# Display the updated DataFrame with the new 'id_class' column\ndata.insert(2, 'lb_split', lb_split)\n\nid_map = pd.read_csv('/kaggle/input/open-problems-single-cell-perturbations/id_map.csv')\nlb_split = id_map['sm_name'].map(data.set_index('sm_name')['lb_split'].to_dict())\n\n# Insert the 'per_compound_mean_abs_gene' column\npred = submission.copy()\n# pred = prediction.drop('id', axis=1)\npred.insert(0, 'sm_name', id_map['sm_name'])  \npred.insert(1, 'lb_split', lb_split)\nper_compound_mean_abs_gene = pred.iloc[:, 2:].apply(lambda row: np.abs(row).mean(), axis=1)\n\npred.insert(0, 'per_compound_mean_abs_gene', per_compound_mean_abs_gene)\n\n# Filter 'Public' and 'Private' test data\npublic_test = pred[pred['lb_split'] == 'Public']\nprivate_test = pred[pred['lb_split'] == 'Private']\n\n# Plotting\nplt.figure(figsize=(10, 6))\n\n# Scatter plot for 'Public' test data\nplt.scatter(range(len(public_test)), public_test['per_compound_mean_abs_gene'], label='Public', color='blue', alpha=0.7)\n\n# Scatter plot for 'Private' test data\nplt.scatter(range(len(private_test)), private_test['per_compound_mean_abs_gene'], label='Private', color='red', alpha=0.7)\n\nplt.xlabel('Index', fontsize=12)\nplt.ylabel('Per Compound: abs(predicted gene_expression).mean', fontsize=12)\nplt.title('Absolute_Prediction_Mean Metric for Public and Private Test Predictions', fontsize=15)\nplt.legend()\nplt.grid(True)\nplt.tight_layout()\n\n# Uncomment the next line if you want to save the plot as a JPEG file\n# plt.savefig('scatter_plot_pred.jpg')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-05T16:27:59.169746Z","iopub.execute_input":"2023-12-05T16:27:59.170116Z","iopub.status.idle":"2023-12-05T16:28:01.510344Z","shell.execute_reply.started":"2023-12-05T16:27:59.170089Z","shell.execute_reply":"2023-12-05T16:28:01.509674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}