{"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 os\nimport glob\n\nimport pandas as pd\nimport numpy as np\nfrom pathlib import Path\n\nimport random\nfrom tqdm.notebook import tqdm\nimport matplotlib.pyplot as plt\n\nimport pydicom # Handle MRI images\n\nimport cv2  # OpenCV - https://docs.opencv.org/master/d6/d00/tutorial_py_root.html\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import roc_auc_score, accuracy_score, log_loss\n\nfrom scipy import ndimage\n\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras import layers","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:21.319104Z","iopub.execute_input":"2023-01-25T18:28:21.319439Z","iopub.status.idle":"2023-01-25T18:28:26.952579Z","shell.execute_reply.started":"2023-01-25T18:28:21.319361Z","shell.execute_reply":"2023-01-25T18:28:26.951784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#veri dizini\ndata_dir = Path('../input/rsna-miccai-brain-tumor-radiogenomic-classification/')\n\nmri_types = [\"FLAIR\", \"T1w\", \"T2w\", \"T1wCE\"]\nexcluded_images = [109, 123, 709] # Bad images","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:26.956351Z","iopub.execute_input":"2023-01-25T18:28:26.956578Z","iopub.status.idle":"2023-01-25T18:28:26.961099Z","shell.execute_reply.started":"2023-01-25T18:28:26.956552Z","shell.execute_reply":"2023-01-25T18:28:26.960402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Veri kümelerini yükleme\ntrain_df = pd.read_csv(data_dir / \"train_labels.csv\")\ntest_df = pd.read_csv(data_dir / \"sample_submission.csv\")\nsample_submission = pd.read_csv(data_dir / \"sample_submission.csv\")\n\ntrain_df = train_df[~train_df.BraTS21ID.isin(excluded_images)]\n\nprint(f\"train data: Rows={train_df.shape[0]}, Columns={train_df.shape[1]}\")\nprint(f\"test data : Rows={test_df.shape[0]}, Columns={test_df.shape[1]}\")","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:26.962639Z","iopub.execute_input":"2023-01-25T18:28:26.963213Z","iopub.status.idle":"2023-01-25T18:28:27.008938Z","shell.execute_reply.started":"2023-01-25T18:28:26.963166Z","shell.execute_reply":"2023-01-25T18:28:27.008241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Z ekseni boyunca yeniden boyutlandırma","metadata":{}},{"cell_type":"code","source":"def resize_volume(img):\n    \"\"\"Resize across z-axis\"\"\"\n    # Set the desired depth-İstenilen derinliği ayarla\n    desired_depth = 64\n    desired_width = 128\n    desired_height = 128\n    # Get current depth-Mevcut derinliği al\n    current_depth = img.shape[-1]\n    current_width = img.shape[0]\n    current_height = img.shape[1]\n    # Compute depth factor-Hesaplama derinliği faktörü\n    depth = current_depth / desired_depth\n    width = current_width / desired_width\n    height = current_height / desired_height\n    depth_factor = 1 / depth\n    width_factor = 1 / width\n    height_factor = 1 / height\n    # Resize across z-axis-Z ekseni boyunca yeniden boyutlandırma\n    img = ndimage.zoom(img, (width_factor, height_factor, depth_factor), order=1)\n    return img","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.010936Z","iopub.execute_input":"2023-01-25T18:28:27.011194Z","iopub.status.idle":"2023-01-25T18:28:27.016872Z","shell.execute_reply.started":"2023-01-25T18:28:27.011161Z","shell.execute_reply":"2023-01-25T18:28:27.01601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_dicom(path, size = 224):\n    #Bir DICOM görüntüsünü okur, piksel değerleri 0 ile 1 arasında olacak şekilde standartlaştırır,\n    #ardından 0 ile 255 arasında yeniden ölçeklendirir.\n    dicom = pydicom.read_file(path)\n    data = dicom.pixel_array\n    #verileri siyah beyaz skalaya / gri skalaya dönüştürün\n    if np.max(data) != 0:\n        data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n    return cv2.resize(data, (size, size))","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.018348Z","iopub.execute_input":"2023-01-25T18:28:27.018667Z","iopub.status.idle":"2023-01-25T18:28:27.027654Z","shell.execute_reply.started":"2023-01-25T18:28:27.018633Z","shell.execute_reply":"2023-01-25T18:28:27.026853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_dicom2(path):\n    data = np.concatenate([tf.expand_dims(pydicom.read_file(p).pixel_array, axis=-1) for p in path], axis=2)\n    if np.max(data) != 0:\n        data = data / np.max(data)\n    data = (data * 255).astype(np.uint8)\n    return resize_volume(data)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.028924Z","iopub.execute_input":"2023-01-25T18:28:27.029177Z","iopub.status.idle":"2023-01-25T18:28:27.038854Z","shell.execute_reply.started":"2023-01-25T18:28:27.029143Z","shell.execute_reply":"2023-01-25T18:28:27.038064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_all_image_paths(brats21id, image_type, folder='train'):\n    #Belirli bir hasta kimliği için belirli bir türdeki tüm görüntülerin sırasını döndürür\n    assert(image_type in mri_types)\n    \n    patient_path = os.path.join(\n        \"../input/rsna-miccai-brain-tumor-radiogenomic-classification/%s/\" % folder, \n        str(brats21id).zfill(5),\n    )\n\n    paths = sorted(\n        glob.glob(os.path.join(patient_path, image_type, \"*\")), \n        key=lambda x: int(x[:-4].split(\"-\")[-1]),\n    )\n    \n    num_images = len(paths)\n    \n    start = int(num_images * 0.25)\n    end = int(num_images * 0.75)\n\n    interval = 1\n    \n    return np.array(paths[start:end:interval])\n\ndef get_all_images(brats21id, image_type, folder='train', size=225):\n    return [load_dicom(path, size) for path in get_all_image_paths(brats21id, image_type, folder)]\n\ndef get_all_images2(brats21id, image_type, folder='train', size=225):\n    return [load_dicom2(get_all_image_paths(brats21id, image_type, folder))]","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.041447Z","iopub.execute_input":"2023-01-25T18:28:27.041694Z","iopub.status.idle":"2023-01-25T18:28:27.050777Z","shell.execute_reply.started":"2023-01-25T18:28:27.041668Z","shell.execute_reply":"2023-01-25T18:28:27.050016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Train için veriler","metadata":{}},{"cell_type":"code","source":"def get_all_data_for_train(image_type, image_size=32):\n    global train_df\n    \n    X = []\n    y = []\n    train_ids = []\n\n    for i in tqdm(train_df.index):\n        x = train_df.loc[i]\n        images = get_all_images2(int(x['BraTS21ID']), image_type, 'train', image_size)\n        label = x['MGMT_value']\n\n        X += images\n        y += [label] * len(images)\n        train_ids += [int(x['BraTS21ID'])] * len(images)\n        assert(len(X) == len(y))\n    return np.array(X), np.array(y), np.array(train_ids)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.052167Z","iopub.execute_input":"2023-01-25T18:28:27.052443Z","iopub.status.idle":"2023-01-25T18:28:27.060803Z","shell.execute_reply.started":"2023-01-25T18:28:27.052393Z","shell.execute_reply":"2023-01-25T18:28:27.059932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Test için veriler yüklendi\ndef get_all_data_for_test(image_type, image_size=32):\n    global test_df\n    \n    X = []\n    test_ids = []\n\n    for i in tqdm(test_df.index):\n        x = test_df.loc[i]\n        images = get_all_images2(int(x['BraTS21ID']), image_type, 'test', image_size)\n        X += images\n        test_ids += [int(x['BraTS21ID'])] * len(images)\n\n    return np.array(X), np.array(test_ids)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.06189Z","iopub.execute_input":"2023-01-25T18:28:27.062257Z","iopub.status.idle":"2023-01-25T18:28:27.069251Z","shell.execute_reply.started":"2023-01-25T18:28:27.062178Z","shell.execute_reply":"2023-01-25T18:28:27.06846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Train ve test T1wCE verileri ","metadata":{}},{"cell_type":"code","source":"X, y, trainidt = get_all_data_for_train('T1wCE', image_size=32)\nX_test, testidt = get_all_data_for_test('T1wCE', image_size=32)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:28:27.072517Z","iopub.execute_input":"2023-01-25T18:28:27.07273Z","iopub.status.idle":"2023-01-25T18:40:18.728816Z","shell.execute_reply.started":"2023-01-25T18:28:27.0727Z","shell.execute_reply":"2023-01-25T18:40:18.728063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X_train, X_valid, y_train, y_valid, trainidt_train, trainidt_valid = train_test_split(X, y, trainidt, test_size=0.2, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.730041Z","iopub.execute_input":"2023-01-25T18:40:18.731668Z","iopub.status.idle":"2023-01-25T18:40:18.735539Z","shell.execute_reply.started":"2023-01-25T18:40:18.731623Z","shell.execute_reply":"2023-01-25T18:40:18.73481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# X_train = tf.expand_dims(X_train, axis=-1)\n# X_valid = tf.expand_dims(X_valid, axis=-1)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.736865Z","iopub.execute_input":"2023-01-25T18:40:18.737316Z","iopub.status.idle":"2023-01-25T18:40:18.749319Z","shell.execute_reply.started":"2023-01-25T18:40:18.737281Z","shell.execute_reply":"2023-01-25T18:40:18.748473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Tek seferlik kodlama etiketleri\n# y_train = to_categorical(y_train)\n# y_valid = to_categorical(y_valid)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.750495Z","iopub.execute_input":"2023-01-25T18:40:18.750765Z","iopub.status.idle":"2023-01-25T18:40:18.759095Z","shell.execute_reply.started":"2023-01-25T18:40:18.750732Z","shell.execute_reply":"2023-01-25T18:40:18.758257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"3 Boyutlu CNN modeli","metadata":{}},{"cell_type":"code","source":"#Modeli tanımlama,eğitme\n# source: https://keras.io/examples/vision/3D_image_classification/\ndef get_3DCNNmodel(width=128, height=128, depth=64, name='3dcnn'):\n    \"\"\"Build a 3D convolutional neural network model.\"\"\"\n\n    inputs = tf.keras.Input((width, height, depth, 1))\n\n    x = tf.keras.layers.Conv3D(filters=64, kernel_size=3, activation=\"relu\")(inputs)\n    x = tf.keras.layers.MaxPool3D(pool_size=2)(x)\n    x = tf.keras.layers.BatchNormalization()(x)\n    #Batch normalization sayesinde ağdaki katmanlar, önceki katmanın\n    #öğrenmesini beklemek zorunda kalmaz. Eş zamanlı olarak öğrenime \n    #olanak sağlar. Eğitimimizin hızlanmasını sağlar.\n\n    x = tf.keras.layers.Conv3D(filters=64, kernel_size=3, activation=\"relu\")(x)\n    x = tf.keras.layers.MaxPool3D(pool_size=2)(x)\n    x = tf.keras.layers.BatchNormalization()(x)\n\n    x = tf.keras.layers.Conv3D(filters=128, kernel_size=3, activation=\"relu\")(x)\n    x = tf.keras.layers.MaxPool3D(pool_size=2)(x)\n    x = tf.keras.layers.BatchNormalization()(x)\n\n    x = tf.keras.layers.Conv3D(filters=256, kernel_size=3, activation=\"relu\")(x)\n    x = tf.keras.layers.MaxPool3D(pool_size=2)(x)\n    x = tf.keras.layers.BatchNormalization()(x)\n\n    x = tf.keras.layers.GlobalAveragePooling3D()(x)\n    x = tf.keras.layers.Dense(units=512, activation=\"relu\")(x)\n    x = tf.keras.layers.Dropout(0.3)(x)\n\n    #outputs = tf.keras.layers.Dense(units=1, activation=\"sigmoid\")(x)\n    output = keras.layers.Dense(2, activation=\"softmax\")(x)\n\n    #model = tf.keras.Model(inputs, outputs, name=name)\n\n    #initial_learning_rate = 0.0001\n    #lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n    #    initial_learning_rate, decay_steps=100000, decay_rate=0.96, staircase=True\n    #)\n    #model.compile(\n    #    loss=\"binary_crossentropy\",\n    #    optimizer=tf.keras.optimizers.Adam(learning_rate=lr_schedule),\n    #    metrics=[\"acc\"],\n    #)\n    model = keras.Model(inputs, output)\n    initial_learning_rate =  0.0001\n    lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n        initial_learning_rate,\n        decay_steps=100000,\n        decay_rate=0.96, \n        staircase=True\n    )\n  \n    roc_auc = tf.keras.metrics.AUC(name='roc_auc', curve='ROC')\n\n    model.compile(\n        loss=\"categorical_crossentropy\", \n        optimizer=keras.optimizers.Adam(),\n        metrics=[roc_auc],\n    )\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.760397Z","iopub.execute_input":"2023-01-25T18:40:18.760796Z","iopub.status.idle":"2023-01-25T18:40:18.773832Z","shell.execute_reply.started":"2023-01-25T18:40:18.76076Z","shell.execute_reply":"2023-01-25T18:40:18.773054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"2 Boyutlu CNN modeli","metadata":{}},{"cell_type":"code","source":"def get_2DCNNmodel():\n    np.random.seed(0)\n    random.seed(12)\n    tf.random.set_seed(12)\n\n    inpt = keras.Input(shape=X_train.shape[1:])\n\n    h = keras.layers.experimental.preprocessing.Rescaling(1.0 / 255)(inpt)\n\n    h = keras.layers.Conv2D(64, kernel_size=(4, 4), activation=\"relu\", name=\"Conv_1\")(h)\n    h = keras.layers.MaxPool2D(pool_size=(2, 2))(h)\n\n    h = keras.layers.Conv2D(32, kernel_size=(2, 2), activation=\"relu\", name=\"Conv_2\")(h)\n    h = keras.layers.MaxPool2D(pool_size=(1, 1))(h)\n\n    h = keras.layers.Dropout(0.1)(h)\n\n    h = keras.layers.Flatten()(h)\n    h = keras.layers.Dense(32, activation=\"relu\")(h)\n\n    output = keras.layers.Dense(2, activation=\"softmax\")(h)\n\n    model = keras.Model(inpt, output)\n    initial_learning_rate =  0.0001\n    lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(\n        initial_learning_rate,\n        decay_steps=100000,\n        decay_rate=0.96, \n        staircase=True\n    )\n  \n    roc_auc = tf.keras.metrics.AUC(name='roc_auc', curve='ROC')\n\n    model.compile(\n        loss=\"categorical_crossentropy\", \n        optimizer=keras.optimizers.Adam(),\n        metrics=[roc_auc],\n    )\n    return model","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.775144Z","iopub.execute_input":"2023-01-25T18:40:18.775816Z","iopub.status.idle":"2023-01-25T18:40:18.786737Z","shell.execute_reply.started":"2023-01-25T18:40:18.775782Z","shell.execute_reply":"2023-01-25T18:40:18.785953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checkpoint_filepath = \"best_model.h5\"\n\n# model_checkpoint_cb = tf.keras.callbacks.ModelCheckpoint(\n#     filepath=checkpoint_filepath,\n#     save_weights_only=False,\n#     monitor=\"val_roc_auc\",\n#     mode=\"max\",\n#     save_best_only=True,\n#     save_freq=\"epoch\",\n#     verbose=1,\n# )","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.787736Z","iopub.execute_input":"2023-01-25T18:40:18.788319Z","iopub.status.idle":"2023-01-25T18:40:18.7989Z","shell.execute_reply.started":"2023-01-25T18:40:18.788275Z","shell.execute_reply":"2023-01-25T18:40:18.798155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stopping_cb = tf.keras.callbacks.EarlyStopping(monitor=\"val_roc_auc\", mode='max', patience=10)","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.800216Z","iopub.execute_input":"2023-01-25T18:40:18.800565Z","iopub.status.idle":"2023-01-25T18:40:18.807517Z","shell.execute_reply.started":"2023-01-25T18:40:18.800532Z","shell.execute_reply":"2023-01-25T18:40:18.806855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"auc_list = []\nbest_auc = float(\"-inf\")\n\nfor i in tqdm(range(20)):\n    checkpoint_filepath = \"best_model_\"+str(i)+\".h5\"\n\n    model_checkpoint_cb = tf.keras.callbacks.ModelCheckpoint(\n        filepath=checkpoint_filepath,\n        save_weights_only=False,\n        monitor=\"val_roc_auc\",\n        mode=\"max\",\n        save_best_only=True,\n        save_freq=\"epoch\",\n        verbose=0,\n    )\n    X_train, X_valid, y_train, y_valid, trainidt_train, trainidt_valid = train_test_split(X, y, trainidt, test_size=0.2, random_state=i)\n\n    X_train = tf.expand_dims(X_train, axis=-1)\n    X_valid = tf.expand_dims(X_valid, axis=-1)\n    y_train = to_categorical(y_train)\n    y_valid = to_categorical(y_valid)\n\n    model = get_3DCNNmodel()\n\n    history = model.fit(x=X_train, y = y_train, epochs=40, batch_size = 2,\n                        callbacks=[model_checkpoint_cb, early_stopping_cb],\n                        validation_data=(X_valid, y_valid), verbose=0)\n\n    model_best = tf.keras.models.load_model(filepath=checkpoint_filepath)\n    #Doğrulama kümesiyle ilgili tahminler\n    y_pred = model_best.predict(X_valid,batch_size = 2)\n\n    pred = np.argmax(y_pred, axis=1)\n\n    result = pd.DataFrame(trainidt_valid)\n    result[1] = pred\n\n    result.columns = [\"BraTS21ID\", \"MGMT_value\"]\n    result2 = result.groupby(\"BraTS21ID\", as_index=False).mean()\n\n    result2 = result2.merge(train_df, on=\"BraTS21ID\")\n    auc = roc_auc_score(\n        result2.MGMT_value_y,\n        result2.MGMT_value_x,\n    )\n    print(f\"Validation AUC={auc}\")\n    auc_list.append(auc)\n    if auc > best_auc:\n        best_i = i\n        best_auc = auc","metadata":{"execution":{"iopub.status.busy":"2023-01-25T18:40:18.810576Z","iopub.execute_input":"2023-01-25T18:40:18.810816Z","iopub.status.idle":"2023-01-25T21:01:29.448774Z","shell.execute_reply.started":"2023-01-25T18:40:18.810751Z","shell.execute_reply":"2023-01-25T21:01:29.447953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.hist(auc_list)\nplt.xlabel(\"AUC\")\nplt.ylabel(\"No. of trials\") #deneme sayısı\nplt.title(f\"Mean AUC = {np.mean(auc_list)}\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-25T21:01:29.450098Z","iopub.execute_input":"2023-01-25T21:01:29.450711Z","iopub.status.idle":"2023-01-25T21:01:29.761073Z","shell.execute_reply.started":"2023-01-25T21:01:29.450674Z","shell.execute_reply":"2023-01-25T21:01:29.760339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"checkpoint_filepath = \"best_model_\"+str(best_i)+\".h5\"\nprint(f\"Using {checkpoint_filepath} with AUC = {best_auc}.\")\nmodel_best = tf.keras.models.load_model(filepath=checkpoint_filepath)\n#Test Setiyle İlgili Tahminler\ny_pred = model_best.predict(X_test,batch_size = 2)\n\npred = np.argmax(y_pred, axis=1) #\n\nresult = pd.DataFrame(testidt)\nresult[1] = pred\npred","metadata":{"execution":{"iopub.status.busy":"2023-01-25T21:01:29.762443Z","iopub.execute_input":"2023-01-25T21:01:29.762874Z","iopub.status.idle":"2023-01-25T21:01:31.531197Z","shell.execute_reply.started":"2023-01-25T21:01:29.762834Z","shell.execute_reply":"2023-01-25T21:01:31.530431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_pred = model_best.predict(X_valid,batch_size = 2)\n\n# pred = np.argmax(y_pred, axis=1)\n\n# result = pd.DataFrame(trainidt_valid)\n# result[1] = pred\n\n# result.columns = [\"BraTS21ID\", \"MGMT_value\"]\n# result2 = result.groupby(\"BraTS21ID\", as_index=False).mean()\n\n# result2 = result2.merge(train_df, on=\"BraTS21ID\")\n# auc = roc_auc_score(\n#     result2.MGMT_value_y,\n#     result2.MGMT_value_x,\n# )\n# accuracy = accuracy_score(\n#     result2.MGMT_value_y,\n#     result2.MGMT_value_x,\n# )\n# loss = log_loss(\n#     result2.MGMT_value_y,\n#     result2.MGMT_value_x,\n# )\n# print(f\"Validation AUC={auc}, Validation accuracy={accuracy}, Validation loss={loss}\")","metadata":{"execution":{"iopub.status.busy":"2023-01-25T21:01:31.53231Z","iopub.execute_input":"2023-01-25T21:01:31.532581Z","iopub.status.idle":"2023-01-25T21:01:31.537383Z","shell.execute_reply.started":"2023-01-25T21:01:31.532542Z","shell.execute_reply":"2023-01-25T21:01:31.5364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# y_pred = model_best.predict(X_test,batch_size = 2)\n\n# pred = np.argmax(y_pred, axis=1) #\n\n# result = pd.DataFrame(testidt)\n# result[1] = pred\n# pred","metadata":{"execution":{"iopub.status.busy":"2023-01-25T21:01:31.53885Z","iopub.execute_input":"2023-01-25T21:01:31.539255Z","iopub.status.idle":"2023-01-25T21:01:31.551359Z","shell.execute_reply.started":"2023-01-25T21:01:31.539219Z","shell.execute_reply":"2023-01-25T21:01:31.550671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#submission dosyası/Gönderim dosyası\nresult.columns=['BraTS21ID','MGMT_value']\n\nresult2 = result.groupby('BraTS21ID',as_index=False).mean()\nresult2['BraTS21ID'] = sample_submission['BraTS21ID']\n#Yuvarlama\nresult2['MGMT_value'] = result2['MGMT_value'].apply(lambda x:round(x*10)/10)\n\nresult2.to_csv('submission.csv',index=False)\nresult2","metadata":{"execution":{"iopub.status.busy":"2023-01-25T21:01:31.553466Z","iopub.execute_input":"2023-01-25T21:01:31.554041Z","iopub.status.idle":"2023-01-25T21:01:31.582307Z","shell.execute_reply.started":"2023-01-25T21:01:31.553997Z","shell.execute_reply":"2023-01-25T21:01:31.581687Z"},"trusted":true},"execution_count":null,"outputs":[]}]}