{"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":"import pandas as pd#导入csv文件的库\nimport numpy as np#进行矩阵运算的库\nimport warnings#避免一些可以忽略的报错\nwarnings.filterwarnings('ignore')#filterwarnings()方法是用于设置警告过滤器的方法，它可以控制警告信息的输出方式和级别。","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-13T04:15:28.400972Z","iopub.execute_input":"2023-10-13T04:15:28.401651Z","iopub.status.idle":"2023-10-13T04:15:28.407351Z","shell.execute_reply.started":"2023-10-13T04:15:28.401591Z","shell.execute_reply":"2023-10-13T04:15:28.406385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#设置随机种子\nimport random\nnp.random.seed(2023)\nrandom.seed(2023)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\")\ntrain.drop(['image_width','image_height','is_tma'],axis=1,inplace=True)\nprint(f\"len(train):{len(train)}\")\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-13T04:15:28.409186Z","iopub.execute_input":"2023-10-13T04:15:28.409709Z","iopub.status.idle":"2023-10-13T04:15:28.470389Z","shell.execute_reply.started":"2023-10-13T04:15:28.409659Z","shell.execute_reply":"2023-10-13T04:15:28.469371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['label'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-10-13T04:15:55.333579Z","iopub.execute_input":"2023-10-13T04:15:55.333994Z","iopub.status.idle":"2023-10-13T04:15:55.344957Z","shell.execute_reply.started":"2023-10-13T04:15:55.333962Z","shell.execute_reply":"2023-10-13T04:15:55.343702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#如果没有压缩版图片就预测成‘HGSC’ label=0\ntrain['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-13T04:16:00.897267Z","iopub.execute_input":"2023-10-13T04:16:00.897822Z","iopub.status.idle":"2023-10-13T04:16:00.910386Z","shell.execute_reply.started":"2023-10-13T04:16:00.897782Z","shell.execute_reply":"2023-10-13T04:16:00.909258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label=['HGSC','EC','CC','LGSC','MC']\np=np.array([0,222,124,99,47,46])\np=p/np.sum(p)\nfor i in range(len(p)-1):\n    p[i+1]+=p[i]\nprint(p)","metadata":{"execution":{"iopub.status.busy":"2023-10-13T04:20:21.729309Z","iopub.execute_input":"2023-10-13T04:20:21.729746Z","iopub.status.idle":"2023-10-13T04:20:21.741075Z","shell.execute_reply.started":"2023-10-13T04:20:21.72971Z","shell.execute_reply":"2023-10-13T04:20:21.739284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=pd.read_csv(\"/kaggle/input/UBC-OCEAN/sample_submission.csv\")\ntest_pred=[]\nfor i in range(len(submission)):\n    random_number=np.random.random()\n    for j in range(len(p)-1):\n        if random_number>=p[j] and random_number<p[j+1]:\n            test_pred.append(label[j])\nsubmission['label']=test_pred\nsubmission.to_csv(\"submission.csv\",index=None)\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-13T04:23:16.947258Z","iopub.execute_input":"2023-10-13T04:23:16.947693Z","iopub.status.idle":"2023-10-13T04:23:16.958912Z","shell.execute_reply.started":"2023-10-13T04:23:16.947648Z","shell.execute_reply":"2023-10-13T04:23:16.957425Z"},"trusted":true},"execution_count":null,"outputs":[]}]}