{
 "nbformat": 4,
 "nbformat_minor": 0,
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "version_major": 2,
    "version_minor": 0,
    "state": {
     "b0a448f563a746bd9e6c88e23f32240f": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "VBoxModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "VBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "VBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_2af176ddf3d5451ba7a3cbf406b0214c",
        "IPY_MODEL_f9ba73fabf954b60948d0749a4f77d84",
        "IPY_MODEL_faeaec9d76c64c3e9f79426f7129fc32",
        "IPY_MODEL_8d6bdc29150642d4beab484a5c300fcd",
        "IPY_MODEL_d053292dd10e498f9634c9f0b7b3de38",
        "IPY_MODEL_1700d3237550494fb1e9d019808dd7b6",
        "IPY_MODEL_08ee080a2f6c43de84581bb87157df99",
        "IPY_MODEL_c5c4b18ca0334931959a13a6655d0d36"
       ],
       "layout": "IPY_MODEL_33f06136569d45f081bae78a5c8064bd"
      }
     },
     "2af176ddf3d5451ba7a3cbf406b0214c": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "HTMLModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_b98dcf8febc54e099a1849337458265d",
       "placeholder": "​",
       "style": "IPY_MODEL_474028457ad64384b820faedcf5f5adc",
       "value": "<h3>⚙️ CPU / GPU / TPU Seçimi</h3>"
      }
     },
     "f9ba73fabf954b60948d0749a4f77d84": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "HTMLModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_3e11ee03afa3415a8f39ecf7bbe94777",
       "placeholder": "​",
       "style": "IPY_MODEL_9a427e09c5884c2697cc5cd069826f1e",
       "value": "<p style='color:#555;'>Aşama 1’deki n_features / n_samples değerleri varsa otomatik dolar; değilse elle ayarlayın.</p>"
      }
     },
     "faeaec9d76c64c3e9f79426f7129fc32": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DropdownModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DropdownModel",
       "_options_labels": [
        "CPU — önerilen (küçük/orta QML)",
        "GPU — Aer GPU paketi ile",
        "TPU / v5e-1 — Qiskit Aer için önerilmez"
       ],
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "DropdownView",
       "description": "Ortam:",
       "description_tooltip": null,
       "disabled": false,
       "index": 1,
       "layout": "IPY_MODEL_bc0d3a276bbb4ba1900f6453dcd2860c",
       "style": "IPY_MODEL_0106e0a52c16493b97df96395ad14954"
      }
     },
     "8d6bdc29150642d4beab484a5c300fcd": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "IntSliderModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "IntSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "IntSliderView",
       "continuous_update": false,
       "description": "n_features≈",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_ff2514f0abfb416ba469c5f63f7b081d",
       "max": 30,
       "min": 2,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": "d",
       "step": 1,
       "style": "IPY_MODEL_5f442951b131498c91ae98681cb93803",
       "value": 25
      }
     },
     "d053292dd10e498f9634c9f0b7b3de38": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "IntSliderModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "IntSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "IntSliderView",
       "continuous_update": false,
       "description": "n_samples≈",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_15826a7196e74899b7f2f4f2d2d18459",
       "max": 5000,
       "min": 50,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": "d",
       "step": 50,
       "style": "IPY_MODEL_ec5916c873a1429195b89dad28fc0c49",
       "value": 5000
      }
     },
     "1700d3237550494fb1e9d019808dd7b6": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "HTMLModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_2d077bf93aa048dd8a33edc81e828e04",
       "placeholder": "​",
       "style": "IPY_MODEL_9c05e4407cf2485a80395bce33eb3f89",
       "value": "<br>"
      }
     },
     "08ee080a2f6c43de84581bb87157df99": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "ButtonModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ButtonModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "ButtonView",
       "button_style": "primary",
       "description": "Ortamı Değerlendir ve Ayarla",
       "disabled": false,
       "icon": "cogs",
       "layout": "IPY_MODEL_98bc16737704402ba9605df9907c4653",
       "style": "IPY_MODEL_d0fca9b506734a5ea0802a640b55ccb0",
       "tooltip": ""
      }
     },
     "c5c4b18ca0334931959a13a6655d0d36": {
      "model_module": "@jupyter-widgets/output",
      "model_name": "OutputModel",
      "model_module_version": "1.0.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/output",
       "_model_module_version": "1.0.0",
       "_model_name": "OutputModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/output",
       "_view_module_version": "1.0.0",
       "_view_name": "OutputView",
       "layout": "IPY_MODEL_3b80284183af46e3ac7541662e149913",
       "msg_id": "",
       "outputs": [
        {
         "output_type": "display_data",
         "data": {
          "text/plain": "<IPython.core.display.HTML object>",
          "text/html": "<h3 style='color:#1a73e8;'>🖥️ Simülasyon Ortamı Sonucu</h3>"
         },
         "metadata": {}
        },
        {
         "output_type": "stream",
         "name": "stdout",
         "text": [
          "Seçim: GPU — Aer GPU paketi ile\n",
          "COMPUTE_BACKEND=gpu | USE_GPU_AER=True | AER_DEVICE=GPU\n",
          "Ölçek: n_features≈25, n_samples≈5000\n",
          "======================================================================\n",
          "GPU — Colab runtime da GPU olmalı (Runtime → Change runtime type).\n"
         ]
        },
        {
         "output_type": "display_data",
         "data": {
          "text/plain": "<IPython.core.display.HTML object>",
          "text/html": "<b>📝 Notlar</b>"
         },
         "metadata": {}
        },
        {
         "output_type": "stream",
         "name": "stdout",
         "text": [
          "  • Büyük kernel / yüksek özellik → GPU kazanç olasılığı artar.\n",
          "  • `!nvidia-smi` ile GPU’yu doğrulayın; gerekirse runtime Restart.\n",
          "  • StatevectorSampler varsayılanı CPU’dur; GPU için Aer device='GPU' gerekir.\n"
         ]
        },
        {
         "output_type": "display_data",
         "data": {
          "text/plain": "<IPython.core.display.HTML object>",
          "text/html": "<b>📦 Kurulum (Aşama 2 veya burada)</b>"
         },
         "metadata": {}
        },
        {
         "output_type": "stream",
         "name": "stdout",
         "text": [
          "!pip install -q qiskit qiskit-machine-learning qiskit-algorithms\n",
          "!pip install -q qiskit-aer-gpu-cu11   # CUDA 11 Colab\n",
          "# alternatif CUDA 12: !pip install -q qiskit-aer-gpu\n"
         ]
        },
        {
         "output_type": "display_data",
         "data": {
          "text/plain": "<IPython.core.display.HTML object>",
          "text/html": "<b>💻 Kod ipucu</b>"
         },
         "metadata": {}
        },
        {
         "output_type": "stream",
         "name": "stdout",
         "text": [
          "from qiskit_aer import AerSimulator\n",
          "sim = AerSimulator(method='statevector', device='GPU')\n",
          "print(AerSimulator().available_devices())\n"
         ]
        },
        {
         "output_type": "display_data",
         "data": {
          "text/plain": "<IPython.core.display.HTML object>",
          "text/html": "<b>🔎 Ortam kontrolü</b>"
         },
         "metadata": {}
        },
        {
         "output_type": "stream",
         "name": "stdout",
         "text": [
          "nvidia-smi yok / GPU görünmüyor (CPU veya TPU runtime olabilir).\n"
         ]
        },
        {
         "output_type": "display_data",
         "data": {
          "text/plain": "<IPython.core.display.HTML object>",
          "text/html": "<div style='background:#e8f0fe;padding:10px;border-radius:6px;margin-top:8px;'><b>Sonraki:</b> Aşama 2 kurulum. GPU seçtiyseniz aer-gpu paketini de kurun. Aşama 8 sampler <code>AER_DEVICE</code> bilgisini okur.</div>"
         },
         "metadata": {}
        }
       ]
      }
     },
     "33f06136569d45f081bae78a5c8064bd": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "b98dcf8febc54e099a1849337458265d": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "474028457ad64384b820faedcf5f5adc": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "3e11ee03afa3415a8f39ecf7bbe94777": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "9a427e09c5884c2697cc5cd069826f1e": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "bc0d3a276bbb4ba1900f6453dcd2860c": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": "520px"
      }
     },
     "0106e0a52c16493b97df96395ad14954": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "80px"
      }
     },
     "ff2514f0abfb416ba469c5f63f7b081d": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "5f442951b131498c91ae98681cb93803": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "SliderStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "100px",
       "handle_color": null
      }
     },
     "15826a7196e74899b7f2f4f2d2d18459": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "ec5916c873a1429195b89dad28fc0c49": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "SliderStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "100px",
       "handle_color": null
      }
     },
     "2d077bf93aa048dd8a33edc81e828e04": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "9c05e4407cf2485a80395bce33eb3f89": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "98bc16737704402ba9605df9907c4653": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": "40px",
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": "320px"
      }
     },
     "d0fca9b506734a5ea0802a640b55ccb0": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "ButtonStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ButtonStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "button_color": null,
       "font_weight": ""
      }
     },
     "3b80284183af46e3ac7541662e149913": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "88dca262feae4c99851575d9553b8999": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "FileUploadModel",
      "model_module_version": "1.5.0",
      "state": {
       "_counter": 0,
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FileUploadModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FileUploadView",
       "accept": ".csv",
       "button_style": "",
       "data": [],
       "description": "CSV Yükle",
       "description_tooltip": null,
       "disabled": false,
       "error": "",
       "icon": "upload",
       "layout": "IPY_MODEL_d4eba1fac4ba4e9c86dbe8982f351c9a",
       "metadata": [],
       "multiple": false,
       "style": "IPY_MODEL_8b20979c08554df3a476d07355ef58e7"
      }
     },
     "d4eba1fac4ba4e9c86dbe8982f351c9a": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "8b20979c08554df3a476d07355ef58e7": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "ButtonStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ButtonStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "button_color": null,
       "font_weight": ""
      }
     },
     "d712c49777c744be86514a2f31107cbd": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "VBoxModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "VBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "VBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_afe97e70031e48ffb96bde9d5999d43c",
        "IPY_MODEL_117514629e734129a82dd14c32280e2a",
        "IPY_MODEL_5b515d99a34d4fe5b770e2805d9a67ac",
        "IPY_MODEL_0f9f765b703d43d9975fe3a6c6fbcfa2",
        "IPY_MODEL_a15d5be8c76c47f7849a6373b599a55f",
        "IPY_MODEL_47ed77dc301d47d2b51bad60f882cdcc",
        "IPY_MODEL_be8698e83c1145678f12ec1b3ddc1abb",
        "IPY_MODEL_1dfce3668cfb4ffa9e928993fce35ca1",
        "IPY_MODEL_9cfbaa0eac394ea5acb6c1886fcca06d",
        "IPY_MODEL_4a8525d27bd04de2b7afc80f89126220"
       ],
       "layout": "IPY_MODEL_b6cbb54349e04ddc995a5af6944a4f31"
      }
     },
     "afe97e70031e48ffb96bde9d5999d43c": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "HTMLModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_acdc08a9ee6a44aeb16d768008f4219a",
       "placeholder": "​",
       "style": "IPY_MODEL_73c8b1fc19ab4ef7944221a624ce5312",
       "value": "<h3>🎯 İlaç Etkinliği — Problem & Encoding Seçim Aracı</h3>"
      }
     },
     "117514629e734129a82dd14c32280e2a": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "HTMLModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_67a881470330491195b41bf9c8953444",
       "placeholder": "​",
       "style": "IPY_MODEL_01a8a4dda1594f6dbd1f55f80e299f2a",
       "value": "<p style='color:#555;'><b>n_features</b> = özellik/kübit adayı; <b>n_samples</b> = hasta sayısı. Ham MR boyutu burada seçilmez.</p>"
      }
     },
     "5b515d99a34d4fe5b770e2805d9a67ac": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DropdownModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DropdownModel",
       "_options_labels": [
        "Sınıflandırma — İlaç etkili / etkisiz",
        "Regresyon — Etkinlik skoru (0-1 veya %)",
        "Optimizasyon — Doz / kombinasyon arama"
       ],
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "DropdownView",
       "description": "Problem:",
       "description_tooltip": null,
       "disabled": false,
       "index": 0,
       "layout": "IPY_MODEL_13af59f7da8446de9a727e458ef78977",
       "style": "IPY_MODEL_545e2ca53d0b437dab280b65447a4067"
      }
     },
     "0f9f765b703d43d9975fe3a6c6fbcfa2": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "IntSliderModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "IntSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "IntSliderView",
       "continuous_update": false,
       "description": "Özellik (n_features):",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_e74944b35ad54dcc8cd7e37c03aefa09",
       "max": 50,
       "min": 2,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": "d",
       "step": 1,
       "style": "IPY_MODEL_d703a301835d4081ba977c0072b51e2d",
       "value": 12
      }
     },
     "a15d5be8c76c47f7849a6373b599a55f": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "IntSliderModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "IntSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "IntSliderView",
       "continuous_update": false,
       "description": "Hasta sayısı (n):",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_0c56bf122d6d4b398647fd07f68bfc82",
       "max": 5000,
       "min": 50,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": "d",
       "step": 50,
       "style": "IPY_MODEL_76fcf218d1844fab9396ba1fc7c6d6da",
       "value": 300
      }
     },
     "47ed77dc301d47d2b51bad60f882cdcc": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DropdownModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DropdownModel",
       "_options_labels": [
        "Sürekli (tahlil + radiomics özellikler)",
        "Kategorik (cinsiyet, komorbidite, ilaç grubu)",
        "Karışık (demografik + tahlil + görüntü özellikleri)"
       ],
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "DropdownView",
       "description": "Veri Tipi:",
       "description_tooltip": null,
       "disabled": false,
       "index": 2,
       "layout": "IPY_MODEL_ba6c3940442a432e9ee0ec08d1778b96",
       "style": "IPY_MODEL_219d59553e954ba7ad0ffabf66fb4d4f"
      }
     },
     "be8698e83c1145678f12ec1b3ddc1abb": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DropdownModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DropdownModel",
       "_options_labels": [
        "Hızlı prototip / Eğitim (Simülatör)",
        "Gerçek IBM Quantum denemesi",
        "Yüksek doğruluk (simülatör + error mitigation)"
       ],
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "DropdownView",
       "description": "Öncelik:",
       "description_tooltip": null,
       "disabled": false,
       "index": 0,
       "layout": "IPY_MODEL_74aad48683164d66b66c8be597aaed5c",
       "style": "IPY_MODEL_8b1bd41bcf84444eacec4fe9ba7de1fc"
      }
     },
     "1dfce3668cfb4ffa9e928993fce35ca1": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "HTMLModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "HTMLModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "HTMLView",
       "description": "",
       "description_tooltip": null,
       "layout": "IPY_MODEL_f1b681a70dcb43c4a8c2032cbb7705ea",
       "placeholder": "​",
       "style": "IPY_MODEL_6276766130e74519b1480d0280e1e6c5",
       "value": "<br>"
      }
     },
     "9cfbaa0eac394ea5acb6c1886fcca06d": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "ButtonModel",
      "model_module_version": "1.5.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ButtonModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "ButtonView",
       "button_style": "success",
       "description": "Encoding + Qubit + Algoritma & Cihaz Öner",
       "disabled": false,
       "icon": "check",
       "layout": "IPY_MODEL_f56ceb6b183c4645a2c66029e1123e04",
       "style": "IPY_MODEL_1debb7ac70b24419b354b9b549879a29",
       "tooltip": ""
      }
     },
     "4a8525d27bd04de2b7afc80f89126220": {
      "model_module": "@jupyter-widgets/output",
      "model_name": "OutputModel",
      "model_module_version": "1.0.0",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/output",
       "_model_module_version": "1.0.0",
       "_model_name": "OutputModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/output",
       "_view_module_version": "1.0.0",
       "_view_name": "OutputView",
       "layout": "IPY_MODEL_1c6399173cc448068ccade5aa8c1d190",
       "msg_id": "",
       "outputs": []
      }
     },
     "b6cbb54349e04ddc995a5af6944a4f31": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "acdc08a9ee6a44aeb16d768008f4219a": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "73c8b1fc19ab4ef7944221a624ce5312": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "67a881470330491195b41bf9c8953444": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "01a8a4dda1594f6dbd1f55f80e299f2a": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "13af59f7da8446de9a727e458ef78977": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": "520px"
      }
     },
     "545e2ca53d0b437dab280b65447a4067": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "140px"
      }
     },
     "e74944b35ad54dcc8cd7e37c03aefa09": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "d703a301835d4081ba977c0072b51e2d": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "SliderStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "140px",
       "handle_color": null
      }
     },
     "0c56bf122d6d4b398647fd07f68bfc82": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "76fcf218d1844fab9396ba1fc7c6d6da": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "SliderStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "140px",
       "handle_color": null
      }
     },
     "ba6c3940442a432e9ee0ec08d1778b96": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": "520px"
      }
     },
     "219d59553e954ba7ad0ffabf66fb4d4f": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "140px"
      }
     },
     "74aad48683164d66b66c8be597aaed5c": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": "520px"
      }
     },
     "8b1bd41bcf84444eacec4fe9ba7de1fc": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "140px"
      }
     },
     "f1b681a70dcb43c4a8c2032cbb7705ea": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "6276766130e74519b1480d0280e1e6c5": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "DescriptionStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "DescriptionStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": ""
      }
     },
     "f56ceb6b183c4645a2c66029e1123e04": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": "40px",
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": "400px"
      }
     },
     "1debb7ac70b24419b354b9b549879a29": {
      "model_module": "@jupyter-widgets/controls",
      "model_name": "ButtonStyleModel",
      "model_module_version": "1.5.0",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "ButtonStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "button_color": null,
       "font_weight": ""
      }
     },
     "1c6399173cc448068ccade5aa8c1d190": {
      "model_module": "@jupyter-widgets/base",
      "model_name": "LayoutModel",
      "model_module_version": "1.2.0",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     }
    }
   }
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "IbMu57zs9FwJ"
   },
   "source": "# Applied QML: Hastane Senaryosu — İlaç Etkinliği Tahmini\n## Kuantum Makine Öğrenmesi Uygulama Rehberi\n\n**Eğitmen:** Joseph Volkan Özcan\n\nBu notebook, bir hastanede hasta verilerinin (kişisel bilgiler, tahlil sonuçları, MR/görüntüleme özellik vektörleri)  \nkuantum bilgisayara güvenli şekilde gönderilerek **ilaç etkinliği tahmini** yapılmasını uçtan uca gösterir.\n\n### Senaryo Özeti\n1. Hasta verileri toplanır (demografik + laboratuvar + görüntüleme özellikleri)\n2. **Anonimleştirme** (KVKK / GDPR uyumlu) uygulanır\n3. Yüksek boyutlu veriler **boyut indirgeme (PCA)** ile küçültülür\n4. Veri kuantum devresine **encoding** ile aktarılır\n5. Kuantum sınıflandırıcı / kernel ile **ilaç etkinliği** (etkili / etkisiz veya etkinlik skoru) tahmin edilir\n6. Sonuçlar ölçülür, yorumlanır ve (yetkili erişimde) de-anonimleştirilebilir\n\n> Sadece **Python + IBM Qiskit** kullanılarak tasarlanmıştır. Colab’da çalışacak şekilde hazırlanmıştır.\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "UJVQpdXw9FwU"
   },
   "source": "## AŞAMA 1: Proje Tanımı, Veri Büyüklüğü ve Seçim Aracı\n\n### 1.1 Problemin Tanımı\nBu projede çözülmek istenen problem:\n\n> **İlaç Etkinliği Tahmini (Drug Efficacy Prediction)**  \n> Belirli bir hasta profili (yaş, cinsiyet, tahlil değerleri, MR’dan türetilmiş özellikler vb.) verildiğinde,  \n> seçilen ilacın **etkili olup olmayacağını** (sınıflandırma) veya **etkinlik skorunu** (regresyon) tahmin etmek.\n\nBu bir **Sınıflandırma** (veya isteğe bağlı Regresyon) problemidir. Optimizasyon (ör. doz ayarlama) ikinci aşamada düşünülebilir.\n\n### 1.2 “Veri Büyüklüğü” Ne Anlama Gelir?\n\nKuantum makine öğrenmesinde “veri büyüklüğü” iki ayrı boyutta ele alınır. Bunları karıştırmamak kritiktir:\n\n| Kavram | Anlamı (Hastane Senaryosunda) | Kuantum Etkisi |\n|--------|-------------------------------|----------------|\n| **n_samples (kayıt / hasta sayısı)** | Kaç adet hasta kaydı var? (ör. 200, 1000, 5000) | Kernel yöntemlerinde (QSVM) maliyet ≈ O(n²). Çok büyük n → simülatörde yavaşlar, gerçek cihazda pahalılaşır. |\n| **n_features (özellik / nitelik sayısı)** | Her hasta için kaç sayısal özellik kullanılıyor? | **Doğrudan kübit sayısını belirler.** Angle Encoding’de 1 özellik ≈ 1 kübit. |\n| **Ham veri boyutu** | MR görüntüsü (MB/GB), ham tahlil tabloları | Kuantuma **gönderilmez**. Önce klasik ön-işleme + özellik çıkarımı yapılır. |\n\n#### Hastane verisinde tipik özellik kaynakları\n- **Demografik / kişisel:** yaş, cinsiyet, BMI, komorbidite sayısı → düşük boyut\n- **Laboratuvar tahlilleri:** hemogram, biyokimya, tümör belirteçleri → 10–50 özellik\n- **Görüntüleme (MR / BT / PET):** ham piksel verisi **doğrudan kullanılmaz**.  \n  Klasik bir CNN veya radiomics ile özellik vektörü çıkarılır (ör. 100–512 boyut).  \n  Bu vektör daha sonra PCA ile 4–8 boyuta indirilir.\n\n> **Özet kural (NISQ dönemi):**  \n> - n_features > 8–10 ise **mutlaka PCA** uygulayın.  \n> - n_samples çok büyükse (binlerce) önce alt-örnekleme veya mini-batch düşünün.  \n> - Ham görüntü / kişisel kimlik bilgisi **asla** kuantum devresine ham haliyle gitmez.\n\n### 1.3 Anonimleştirme (KVKK / GDPR)\nKuantuma gönderilmeden önce:\n- Doğrudan tanımlayıcılar (TC, ad-soyad, protokol no) kaldırılır veya hash’lenir\n- Kvası-tanımlayıcılar (nadir hastalık + yaş + posta kodu kombinasyonu) genelleştirilir\n- Sadece model için gerekli sayısal özellikler ve anonim hasta ID’si tutulur\n\nSonuçlar yalnızca yetkili hekim / sistem tarafından de-anonimleştirilebilir (Aşama 10).\n\nAşağıdaki **interaktif seçim aracı** ile problem tipinizi, özellik sayısını, hasta (kayıt) sayısını ve veri tipini seçerek  \nuygun **encoding**, **kübit ihtiyacı**, **algoritma** ve **cihaz** önerisini alabilirsiniz.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama1_secim",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 348,
     "referenced_widgets": [
      "d712c49777c744be86514a2f31107cbd",
      "afe97e70031e48ffb96bde9d5999d43c",
      "117514629e734129a82dd14c32280e2a",
      "5b515d99a34d4fe5b770e2805d9a67ac",
      "0f9f765b703d43d9975fe3a6c6fbcfa2",
      "a15d5be8c76c47f7849a6373b599a55f",
      "47ed77dc301d47d2b51bad60f882cdcc",
      "be8698e83c1145678f12ec1b3ddc1abb",
      "1dfce3668cfb4ffa9e928993fce35ca1",
      "9cfbaa0eac394ea5acb6c1886fcca06d",
      "4a8525d27bd04de2b7afc80f89126220",
      "b6cbb54349e04ddc995a5af6944a4f31",
      "acdc08a9ee6a44aeb16d768008f4219a",
      "73c8b1fc19ab4ef7944221a624ce5312",
      "67a881470330491195b41bf9c8953444",
      "01a8a4dda1594f6dbd1f55f80e299f2a",
      "13af59f7da8446de9a727e458ef78977",
      "545e2ca53d0b437dab280b65447a4067",
      "e74944b35ad54dcc8cd7e37c03aefa09",
      "d703a301835d4081ba977c0072b51e2d",
      "0c56bf122d6d4b398647fd07f68bfc82",
      "76fcf218d1844fab9396ba1fc7c6d6da",
      "ba6c3940442a432e9ee0ec08d1778b96",
      "219d59553e954ba7ad0ffabf66fb4d4f",
      "74aad48683164d66b66c8be597aaed5c",
      "8b1bd41bcf84444eacec4fe9ba7de1fc",
      "f1b681a70dcb43c4a8c2032cbb7705ea",
      "6276766130e74519b1480d0280e1e6c5",
      "f56ceb6b183c4645a2c66029e1123e04",
      "1debb7ac70b24419b354b9b549879a29",
      "1c6399173cc448068ccade5aa8c1d190"
     ]
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1787231490914,
     "user_tz": -180,
     "elapsed": 354,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "2377c781-0b87-4923-c80d-838ca7d34473"
   },
   "source": "# ============================================================\n# AŞAMA 1 - İnteraktif Seçim Aracı\n# (Encoding + Qubit + Algoritma + Cihaz) — İlaç Etkinliği\n# ============================================================\n\nimport ipywidgets as widgets\nfrom IPython.display import display, clear_output, HTML\nimport math\n\nproblem_type = widgets.Dropdown(\n    options=[\n        (\"Sınıflandırma — İlaç etkili / etkisiz\", \"classification\"),\n        (\"Regresyon — Etkinlik skoru (0-1 veya %)\", \"regression\"),\n        (\"Optimizasyon — Doz / kombinasyon arama\", \"optimization\")\n    ],\n    value=\"classification\",\n    description=\"Problem:\",\n    style={\"description_width\": \"140px\"},\n    layout=widgets.Layout(width=\"520px\")\n)\n\nn_features = widgets.IntSlider(\n    value=12, min=2, max=50, step=1,\n    description=\"Özellik (n_features):\",\n    style={\"description_width\": \"140px\"}, continuous_update=False\n)\n\nn_samples = widgets.IntSlider(\n    value=300, min=50, max=5000, step=50,\n    description=\"Hasta sayısı (n):\",\n    style={\"description_width\": \"140px\"}, continuous_update=False\n)\n\ndata_type = widgets.Dropdown(\n    options=[\n        (\"Sürekli (tahlil + radiomics özellikler)\", \"continuous\"),\n        (\"Kategorik (cinsiyet, komorbidite, ilaç grubu)\", \"categorical\"),\n        (\"Karışık (demografik + tahlil + görüntü özellikleri)\", \"mixed\")\n    ],\n    value=\"mixed\",\n    description=\"Veri Tipi:\",\n    style={\"description_width\": \"140px\"},\n    layout=widgets.Layout(width=\"520px\")\n)\n\npriority = widgets.Dropdown(\n    options=[\n        (\"Hızlı prototip / Eğitim (Simülatör)\", \"prototype\"),\n        (\"Gerçek IBM Quantum denemesi\", \"hardware\"),\n        (\"Yüksek doğruluk (simülatör + error mitigation)\", \"accuracy\")\n    ],\n    value=\"prototype\",\n    description=\"Öncelik:\",\n    style={\"description_width\": \"140px\"},\n    layout=widgets.Layout(width=\"520px\")\n)\n\nrun_button = widgets.Button(\n    description=\"Encoding + Qubit + Algoritma & Cihaz Öner\",\n    button_style=\"success\", icon=\"check\",\n    layout=widgets.Layout(width=\"400px\", height=\"40px\")\n)\noutput_area = widgets.Output()\n\n# Aşama 1b ile paylaşılacak ölçek\nSELECTED_N_FEATURES = 12\nSELECTED_N_SAMPLES = 300\n\ndef compute_encoding_and_qubits(features, samples, dtype):\n    results = {\n        \"primary\": None, \"alternatives\": [],\n        \"pca_recommended\": features > 8,\n        \"pca_target\": min(6, max(2, features // 2)) if features > 8 else features,\n        \"warnings\": []\n    }\n    angle_qubits = features\n    amp_qubits = math.ceil(math.log2(max(features, 2)))\n    amp_padded = 2 ** amp_qubits\n\n    if dtype == \"continuous\":\n        if features <= 8:\n            results[\"primary\"] = (\n                \"Angle Encoding + ZZFeatureMap\", angle_qubits,\n                \"Tahlil ve radiomics sürekli değerleri dönme açılarına yazılır. NISQ için stabil.\",\n                \"zz_feature_map(feature_dimension=n, reps=2, entanglement='linear')\"\n            )\n            results[\"alternatives\"].append((\"PauliFeatureMap\", angle_qubits, \"Daha zengin kernel için alternatif.\"))\n            results[\"alternatives\"].append((\n                \"Amplitude Encoding\", amp_qubits,\n                f\"~{amp_qubits} kübit (2^{amp_qubits}={amp_padded} pad). State preparation pahalı.\"\n            ))\n        else:\n            results[\"primary\"] = (\n                \"PCA → Angle Encoding + ZZFeatureMap\", results[\"pca_target\"],\n                f\"Özellik ({features}) yüksek. PCA → {results['pca_target']} boyut, sonra Angle/ZZ.\",\n                \"PCA(n_components=k) + zz_feature_map(feature_dimension=k, reps=2)\"\n            )\n            results[\"alternatives\"].append((\"Amplitude Encoding\", amp_qubits, f\"Doğrudan {amp_qubits} kübit; derin hazırlama.\"))\n            results[\"warnings\"].append(f\"n_features={features} > 8 → PCA uygulayın.\")\n    elif dtype == \"categorical\":\n        results[\"primary\"] = (\n            \"One-Hot (klasik) → Angle / Basis Encoding\", angle_qubits,\n            \"Kategorikler One-Hot ile sayısallaştırılır, sonra Angle Encoding.\",\n            \"pd.get_dummies(...) → zz_feature_map\"\n        )\n        results[\"alternatives\"].append((\"Basis Encoding\", \"log2(kategori)\", \"Düşük kardinalitede daha az kübit.\"))\n        results[\"warnings\"].append(\"One-Hot kübit sayısını artırabilir.\")\n    else:\n        results[\"primary\"] = (\n            \"Hibrit: Kategorik→One-Hot + Sürekli→Angle/ZZ (+ PCA)\", angle_qubits,\n            \"Hastane karışık veri için tipik yol. Yüksek boyutta PCA şart.\",\n            \"One-Hot + StandardScaler + (PCA) + zz_feature_map\"\n        )\n        if features > 6:\n            results[\"pca_recommended\"] = True\n            results[\"warnings\"].append(\"Karışık klinik veri → PCA ile 4–6 boyut önerilir.\")\n\n    if samples > 1000:\n        results[\"warnings\"].append(f\"n_samples={samples} büyük → QSVM O(n²); alt-örnekleme düşünün.\")\n    if samples < 80:\n        results[\"warnings\"].append(\"Kohort küçük → overfitting riski; cross-validation kullanın.\")\n    return results\n\ndef get_recommendations(prob, features, samples, dtype, prio):\n    recs = {\n        \"algorithms\": [], \"devices\": [], \"notes\": [],\n        \"encoding_info\": compute_encoding_and_qubits(features, samples, dtype),\n        \"pca_required\": features > 8\n    }\n    enc = recs[\"encoding_info\"]\n    if prob == \"classification\":\n        recs[\"algorithms\"] = [\n            (\"FidelityQuantumKernel + QSVM\", \"İlaç etkili/etkisiz için ana yöntem.\"),\n            (\"VQC (RealAmplitudes)\", \"Eğitilebilir varyasyonel sınıflandırıcı.\"),\n            (\"SamplerQNN / EstimatorQNN\", \"Esnek kuantum sinir ağı.\")\n        ]\n    elif prob == \"regression\":\n        recs[\"algorithms\"] = [\n            (\"Variational Quantum Regressor\", \"Etkinlik skoru tahmini.\"),\n            (\"Quantum Kernel Ridge\", \"Kernel regresyon.\"),\n            (\"EstimatorQNN regresyon\", \"Beklenti değeri çıktısı.\")\n        ]\n    else:\n        recs[\"algorithms\"] = [\n            (\"QAOA\", \"Doz / kombinasyon arama.\"),\n            (\"VQE\", \"Maliyet minimizasyonu.\"),\n            (\"Grover\", \"Yapılandırılmış arama (ileri).\")\n        ]\n\n    effective_q = enc[\"primary\"][1]\n    if isinstance(effective_q, str):\n        effective_q = features\n\n    if prio == \"prototype\":\n        recs[\"devices\"] = [\n            (\"AerSimulator / StatevectorSampler\", \"Geliştirme varsayılanı.\"),\n            (\"Qiskit Runtime Simulator\", \"Bulut simülasyonu.\")\n        ]\n        recs[\"notes\"].append(\"Önce simülatör, sonra gerçek donanım.\")\n    elif prio == \"hardware\":\n        if isinstance(effective_q, int) and effective_q <= 5:\n            recs[\"devices\"] = [(\"IBM Quantum küçük backend\", \"≤5 kübit.\"), (\"AerSimulator ön test\", \"Önce simülatör.\")]\n        elif isinstance(effective_q, int) and effective_q <= 10:\n            recs[\"devices\"] = [(\"IBM 127+ kübit + error mitigation\", \"PCA sonrası.\"), (\"Runtime SamplerV2/EstimatorV2\", \"Modern primitives.\")]\n            recs[\"notes\"].append(\"reps=1–2, ResilienceLevel kullanın.\")\n        else:\n            recs[\"devices\"] = [(\"PCA → 4–6 özellik sonra donanım\", \"12+ pratik değil.\"), (\"Aer + noise model\", \"Gürültü taklidi.\")]\n    else:\n        recs[\"devices\"] = [\n            (\"StatevectorSampler (exact)\", \"Gürültüsüz referans.\"),\n            (\"Aer + yüksek shot\", \"İstatistiksel kararlılık.\"),\n            (\"Donanım + ZNE/PEC\", \"Son aşama.\")\n        ]\n\n    recs[\"notes\"].append(\"Kişisel tanımlayıcılar kuantum devresine gönderilmez (KVKK).\")\n    return recs\n\ndef on_button_clicked(b):\n    global SELECTED_N_FEATURES, SELECTED_N_SAMPLES\n    with output_area:\n        clear_output()\n        SELECTED_N_FEATURES = n_features.value\n        SELECTED_N_SAMPLES = n_samples.value\n        recs = get_recommendations(\n            problem_type.value, n_features.value, n_samples.value,\n            data_type.value, priority.value\n        )\n        enc = recs[\"encoding_info\"]\n        display(HTML(\"<h3 style='color:#1a73e8;'>🔍 Öneri Sonuçları — İlaç Etkinliği</h3>\"))\n        print(f\"Problem: {problem_type.label}\")\n        print(f\"n_features={n_features.value} | n_samples={n_samples.value} | {data_type.label}\")\n        print(\"=\" * 70)\n        name, qubits, desc, hint = enc[\"primary\"]\n        display(HTML(\"<b>📐 Encoding & Qubit</b>\"))\n        print(f\"▶ {name}\\n   Kübit: {qubits}\\n   {desc}\\n   Qiskit: {hint}\\n\")\n        if enc[\"alternatives\"]:\n            print(\"Alternatifler:\")\n            for a, q, d in enc[\"alternatives\"]:\n                print(f\"  • {a} | kübit≈{q} — {d}\")\n        f = n_features.value\n        print(f\"\\nKarşılaştırma: Angle={f} | Amplitude={math.ceil(math.log2(max(f,2)))} kübit\")\n        if enc[\"pca_recommended\"]:\n            display(HTML(f\"<div style='background:#fff3cd;padding:8px;border-radius:6px;'>\"\n                         f\"⚠️ PCA önerilir → hedef ~{enc['pca_target']} özellik</div>\"))\n        for w in enc[\"warnings\"]:\n            print(f\"  ⚠ {w}\")\n        print()\n        display(HTML(\"<b>🧠 Algoritmalar</b>\"))\n        for i, (n, d) in enumerate(recs[\"algorithms\"], 1):\n            print(f\"  {i}. {n} — {d}\")\n        display(HTML(\"<b>💻 Cihazlar</b>\"))\n        for i, (n, d) in enumerate(recs[\"devices\"], 1):\n            print(f\"  {i}. {n} — {d}\")\n        display(HTML(\"<b>📝 Notlar</b>\"))\n        for note in recs[\"notes\"]:\n            print(f\"  • {note}\")\n        display(HTML(\"<p><b>➡️ Sonraki:</b> Aşama 1b (CPU/GPU/TPU), sonra Aşama 2 kurulum.</p>\"))\n\nrun_button.on_click(on_button_clicked)\ndisplay(widgets.VBox([\n    widgets.HTML(\"<h3>🎯 İlaç Etkinliği — Problem & Encoding Seçim Aracı</h3>\"),\n    widgets.HTML(\"<p style='color:#555;'><b>n_features</b> = özellik/kübit adayı; <b>n_samples</b> = hasta sayısı. Ham MR boyutu burada seçilmez.</p>\"),\n    problem_type, n_features, n_samples, data_type, priority,\n    widgets.HTML(\"<br>\"), run_button, output_area\n]))\n",
   "execution_count": 1,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": [
       "VBox(children=(HTML(value='<h3>🎯 İlaç Etkinliği — Problem & Encoding Seçim Aracı</h3>'), HTML(value=\"<p style=…"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "d712c49777c744be86514a2f31107cbd"
      }
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "iw6Kq1EB9Fwf"
   },
   "source": "## AŞAMA 1b: Simülasyon Ortamı Seçimi (CPU / GPU / TPU)\n\nColab menüsü (**Runtime → Change runtime type**) ile bu hücredeki seçim birlikte kullanılmalıdır.\n\n| Seçim | Qiskit Aer | Bu ilaç etkinliği problemi (genelde 4–8 kübit) |\n|-------|------------|-----------------------------------------------|\n| **CPU** | Varsayılan | **Önerilen** — stabil, ek kurulum yok |\n| **GPU** | `qiskit-aer-gpu` + `device=\"GPU\"` | Büyük n_samples veya yüksek kübit denemelerinde denenebilir |\n| **TPU / v5e-1** | Aer TPU **kullanmaz** | **Önerilmez** — TF/JAX içindir |\n\nSadece runtime’dan GPU/TPU seçmek Qiskit kodunu otomatik hızlandırmaz; aşağıdaki araç kurulum ve kod ipuçlarını üretir.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama1b_compute_backend",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 693,
     "referenced_widgets": [
      "b0a448f563a746bd9e6c88e23f32240f",
      "2af176ddf3d5451ba7a3cbf406b0214c",
      "f9ba73fabf954b60948d0749a4f77d84",
      "faeaec9d76c64c3e9f79426f7129fc32",
      "8d6bdc29150642d4beab484a5c300fcd",
      "d053292dd10e498f9634c9f0b7b3de38",
      "1700d3237550494fb1e9d019808dd7b6",
      "08ee080a2f6c43de84581bb87157df99",
      "c5c4b18ca0334931959a13a6655d0d36",
      "33f06136569d45f081bae78a5c8064bd",
      "b98dcf8febc54e099a1849337458265d",
      "474028457ad64384b820faedcf5f5adc",
      "3e11ee03afa3415a8f39ecf7bbe94777",
      "9a427e09c5884c2697cc5cd069826f1e",
      "bc0d3a276bbb4ba1900f6453dcd2860c",
      "0106e0a52c16493b97df96395ad14954",
      "ff2514f0abfb416ba469c5f63f7b081d",
      "5f442951b131498c91ae98681cb93803",
      "15826a7196e74899b7f2f4f2d2d18459",
      "ec5916c873a1429195b89dad28fc0c49",
      "2d077bf93aa048dd8a33edc81e828e04",
      "9c05e4407cf2485a80395bce33eb3f89",
      "98bc16737704402ba9605df9907c4653",
      "d0fca9b506734a5ea0802a640b55ccb0",
      "3b80284183af46e3ac7541662e149913"
     ]
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471478448,
     "user_tz": -180,
     "elapsed": 701,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "17777de0-9025-4c35-b284-b0763536956c"
   },
   "source": "# ============================================================\n# AŞAMA 1b - CPU / GPU / TPU seçimi (probleme duyarlı)\n# ============================================================\n\nimport ipywidgets as widgets\nfrom IPython.display import display, clear_output, HTML\nimport subprocess, os\n\nCOMPUTE_BACKEND = \"cpu\"\nUSE_GPU_AER = False\nAER_DEVICE = \"CPU\"\n\nbackend_dd = widgets.Dropdown(\n    options=[\n        (\"CPU — önerilen (küçük/orta QML)\", \"cpu\"),\n        (\"GPU — Aer GPU paketi ile\", \"gpu\"),\n        (\"TPU / v5e-1 — Qiskit Aer için önerilmez\", \"tpu\"),\n    ],\n    value=\"cpu\",\n    description=\"Ortam:\",\n    style={\"description_width\": \"80px\"},\n    layout=widgets.Layout(width=\"520px\"),\n)\n\n_default_f = int(globals().get(\"SELECTED_N_FEATURES\", 6))\n_default_n = int(globals().get(\"SELECTED_N_SAMPLES\", 300))\n\nfeat_slider = widgets.IntSlider(\n    value=min(max(_default_f, 2), 30), min=2, max=30,\n    description=\"n_features≈\", style={\"description_width\": \"100px\"}, continuous_update=False\n)\nsamp_slider = widgets.IntSlider(\n    value=min(max(_default_n, 50), 5000), min=50, max=5000, step=50,\n    description=\"n_samples≈\", style={\"description_width\": \"100px\"}, continuous_update=False\n)\n\nbtn = widgets.Button(\n    description=\"Ortamı Değerlendir ve Ayarla\",\n    button_style=\"primary\", icon=\"cogs\",\n    layout=widgets.Layout(width=\"320px\", height=\"40px\"),\n)\nout = widgets.Output()\n\ndef _recommend(backend, n_feat, n_samp):\n    notes, install_cmds = [], []\n    code_hint, verdict = \"\", \"\"\n    heavy = n_samp >= 800\n    many_q = n_feat >= 12\n    tiny = n_feat <= 8 and n_samp <= 500\n\n    if backend == \"cpu\":\n        verdict = \"CPU — bu problem ölçeği için genelde en iyi denge.\"\n        notes.append(\"StatevectorSampler / Aer CPU ek paketsiz çalışır.\")\n        if heavy:\n            notes.append(f\"n_samples≈{n_samp} yüksek → kernel O(n²) pahalı; alt-örnekleme veya GPU deneyin.\")\n        if many_q:\n            notes.append(f\"n_features≈{n_feat} yüksek → PCA ile 4–6 boyuta indirin.\")\n        install_cmds = [\"!pip install -q qiskit qiskit-aer qiskit-machine-learning qiskit-algorithms\"]\n        code_hint = (\n            \"from qiskit.primitives import StatevectorSampler\\n\"\n            \"sampler = StatevectorSampler()\\n\"\n            \"# veya AerSimulator(method='statevector', device='CPU')\"\n        )\n    elif backend == \"gpu\":\n        verdict = \"GPU — Colab runtime da GPU olmalı (Runtime → Change runtime type).\"\n        install_cmds = [\n            \"!pip install -q qiskit qiskit-machine-learning qiskit-algorithms\",\n            \"!pip install -q qiskit-aer-gpu-cu11   # CUDA 11 Colab\",\n            \"# alternatif CUDA 12: !pip install -q qiskit-aer-gpu\",\n        ]\n        code_hint = (\n            \"from qiskit_aer import AerSimulator\\n\"\n            \"sim = AerSimulator(method='statevector', device='GPU')\\n\"\n            \"print(AerSimulator().available_devices())\"\n        )\n        if tiny:\n            notes.append(\"Küçük devrede GPU bazen CPU’dan yavaş kalır (transfer maliyeti).\")\n        if heavy or many_q:\n            notes.append(\"Büyük kernel / yüksek özellik → GPU kazanç olasılığı artar.\")\n        notes.append(\"`!nvidia-smi` ile GPU’yu doğrulayın; gerekirse runtime Restart.\")\n        notes.append(\"StatevectorSampler varsayılanı CPU’dur; GPU için Aer device='GPU' gerekir.\")\n    else:\n        verdict = \"TPU — Qiskit Aer TPU kullanmaz; simülasyon CPU’da kalır.\"\n        notes.append(\"TPU/v5e-1 TF-JAX içindir; bu QML yığınını hızlandırmaz.\")\n        notes.append(\"Öneri: Runtime’ı CPU veya (Aer GPU deneyecekseniz) GPU yapın.\")\n        install_cmds = [\"!pip install -q qiskit qiskit-aer qiskit-machine-learning qiskit-algorithms\"]\n        code_hint = \"from qiskit.primitives import StatevectorSampler\\nsampler = StatevectorSampler()\"\n\n    return verdict, notes, install_cmds, code_hint\n\ndef on_click(_):\n    global COMPUTE_BACKEND, USE_GPU_AER, AER_DEVICE\n    with out:\n        clear_output()\n        COMPUTE_BACKEND = backend_dd.value\n        USE_GPU_AER = COMPUTE_BACKEND == \"gpu\"\n        AER_DEVICE = \"GPU\" if USE_GPU_AER else \"CPU\"\n        verdict, notes, install_cmds, code_hint = _recommend(\n            COMPUTE_BACKEND, feat_slider.value, samp_slider.value\n        )\n        display(HTML(\"<h3 style='color:#1a73e8;'>🖥️ Simülasyon Ortamı Sonucu</h3>\"))\n        print(f\"Seçim: {backend_dd.label}\")\n        print(f\"COMPUTE_BACKEND={COMPUTE_BACKEND} | USE_GPU_AER={USE_GPU_AER} | AER_DEVICE={AER_DEVICE}\")\n        print(f\"Ölçek: n_features≈{feat_slider.value}, n_samples≈{samp_slider.value}\")\n        print(\"=\" * 70)\n        print(verdict)\n        display(HTML(\"<b>📝 Notlar</b>\"))\n        for n in notes:\n            print(f\"  • {n}\")\n        display(HTML(\"<b>📦 Kurulum (Aşama 2 veya burada)</b>\"))\n        for c in install_cmds:\n            print(c)\n        display(HTML(\"<b>💻 Kod ipucu</b>\"))\n        print(code_hint)\n        display(HTML(\"<b>🔎 Ortam kontrolü</b>\"))\n        try:\n            print(subprocess.check_output([\"nvidia-smi\", \"-L\"], stderr=subprocess.STDOUT, text=True).strip())\n        except Exception:\n            print(\"nvidia-smi yok / GPU görünmüyor (CPU veya TPU runtime olabilir).\")\n        if os.environ.get(\"COLAB_TPU_ADDR\"):\n            print(\"COLAB_TPU_ADDR tanımlı → TPU runtime (Aer yine CPU kullanır).\")\n        display(HTML(\n            \"<div style='background:#e8f0fe;padding:10px;border-radius:6px;margin-top:8px;'>\"\n            \"<b>Sonraki:</b> Aşama 2 kurulum. GPU seçtiyseniz aer-gpu paketini de kurun. \"\n            \"Aşama 8 sampler <code>AER_DEVICE</code> bilgisini okur.\"\n            \"</div>\"\n        ))\n\nbtn.on_click(on_click)\ndisplay(widgets.VBox([\n    widgets.HTML(\"<h3>⚙️ CPU / GPU / TPU Seçimi</h3>\"),\n    widgets.HTML(\"<p style='color:#555;'>Aşama 1’deki n_features / n_samples değerleri varsa otomatik dolar; değilse elle ayarlayın.</p>\"),\n    backend_dd, feat_slider, samp_slider, widgets.HTML(\"<br>\"), btn, out\n]))\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": [
       "VBox(children=(HTML(value='<h3>⚙️ CPU / GPU / TPU Seçimi</h3>'), HTML(value=\"<p style='color:#555;'>Aşama 1’de…"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "b0a448f563a746bd9e6c88e23f32240f"
      }
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "9zCkzA4m9Fwj"
   },
   "source": "## AŞAMA 2: Kütüphane Kurulumları ve Çevresel Ayarlar\n\n- **CPU** (varsayılan / Aşama 1b): standart `qiskit-aer` yeterli.\n- **GPU** (Aşama 1b): `qiskit-aer-gpu-cu11` (veya CUDA 12 için `qiskit-aer-gpu`) kurun; Colab runtime GPU olmalı.\n- **TPU**: ek Qiskit paketi yok; Aer CPU kullanır.\n\nIBM Quantum için API anahtarı `.env` veya Colab Secrets ile verilebilir.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama2_kurulum",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471593036,
     "user_tz": -180,
     "elapsed": 65863,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "5449f940-1f52-4432-9273-aeb8ce0695c7"
   },
   "source": "import os\nimport sys\n\n_backend = globals().get(\"COMPUTE_BACKEND\", \"cpu\")\n_use_gpu = bool(globals().get(\"USE_GPU_AER\", False))\n\nprint(f\"Kurulum modu: COMPUTE_BACKEND={_backend}, USE_GPU_AER={_use_gpu}\")\n\n# Temel paketler (her zaman)\n!pip install -q qiskit qiskit-machine-learning qiskit-ibm-runtime qiskit-algorithms\n!pip install -q scikit-learn numpy pandas python-dotenv matplotlib seaborn\n\n# Aer: GPU veya CPU\nif _use_gpu:\n    print(\"GPU Aer paketi kuruluyor (qiskit-aer-gpu-cu11)...\")\n    !pip install -q qiskit-aer-gpu-cu11\n    print(\"Sorun olursa Runtime Restart sonrası tekrar deneyin; CUDA 12 için: qiskit-aer-gpu\")\nelse:\n    print(\"CPU Aer kuruluyor...\")\n    !pip install -q qiskit-aer\n\nimport numpy as np\nimport pandas as pd\nfrom dotenv import load_dotenv\n\nload_dotenv()\nibm_api_key = os.getenv(\"IBM_QUANTUM_TOKEN\")\n\nprint(\"Kütüphaneler yüklendi.\")\nprint(f\"IBM API anahtarı {'tanımlı' if ibm_api_key else 'tanımlı değil (simülatör)'}.\")\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Kurulum modu: COMPUTE_BACKEND=gpu, USE_GPU_AER=True\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m9.7/9.7 MB\u001b[0m \u001b[31m75.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m263.1/263.1 kB\u001b[0m \u001b[31m24.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m49.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m327.8/327.8 kB\u001b[0m \u001b[31m21.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m412.6/412.6 kB\u001b[0m \u001b[31m29.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m120.7/120.7 kB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m94.7/94.7 kB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m66.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m224.2/224.2 kB\u001b[0m \u001b[31m16.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m54.5/54.5 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.6/76.6 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m8.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m541.5/541.5 kB\u001b[0m \u001b[31m32.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hGPU Aer paketi kuruluyor (qiskit-aer-gpu-cu11)...\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m18.1/18.1 MB\u001b[0m \u001b[31m67.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m38.6/38.6 MB\u001b[0m \u001b[31m17.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m53.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m417.9/417.9 MB\u001b[0m \u001b[31m3.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m875.6/875.6 kB\u001b[0m \u001b[31m49.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m128.2/128.2 MB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m204.1/204.1 MB\u001b[0m \u001b[31m5.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m139.1/139.1 MB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hSorun olursa Runtime Restart sonrası tekrar deneyin; CUDA 12 için: qiskit-aer-gpu\n",
      "Kütüphaneler yüklendi.\n",
      "IBM API anahtarı tanımlı değil (simülatör).\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "6acwkgtz9Fwl"
   },
   "source": "## AŞAMA 3: Veri Tipi, Nitelikler ve Boyut İndirgeme (PCA)\n\n### Hastane verisinde tipik nitelikler\n- **Demografik (kategorik / sürekli):** yaş, cinsiyet, BMI, sigara, komorbidite sayısı  \n- **Laboratuvar (sürekli):** WBC, CRP, kreatinin, tümör belirteçleri, karaciğer enzimleri…  \n- **Görüntüleme türevi (sürekli, yüksek boyut):** Radiomics veya CNN embedding (50–512 boyut)\n\nHam MR/BT **doğrudan** kuantum devresine verilmez. Klasik özellik çıkarımı sonrası  \nyüksek boyutlu vektör **PCA** ile 4–8 boyuta indirilir (NISQ kübit sınırı).\n\nAşağıdaki fonksiyon, standardizasyon + PCA uygular.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama3_pca",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471807693,
     "user_tz": -180,
     "elapsed": 1619,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "2adc4aff-8efd-4493-d879-e7ebe586e6a1"
   },
   "source": "from sklearn.decomposition import PCA\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.pipeline import make_pipeline\n\ndef boyut_indirgeme_uygula(X_veri, n_components=4):\n    \"\"\"\n    Kuantum devresine uygun boyut için StandardScaler + PCA.\n    X_veri: (n_samples, n_features) numpy array veya DataFrame\n    \"\"\"\n    pipeline = make_pipeline(\n        StandardScaler(),\n        PCA(n_components=n_components)\n    )\n    X_kucultulmus = pipeline.fit_transform(X_veri)\n    print(f\"Orijinal boyut : {X_veri.shape}\")\n    print(f\"İndirgenmiş   : {X_kucultulmus.shape}\")\n    print(f\"Açıklanan varyans oranı (kümülatif): {pipeline.named_steps['pca'].explained_variance_ratio_.sum():.3f}\")\n    return X_kucultulmus, pipeline\n\n# Örnek (rastgele yüksek boyutlu özellik → 4 boyuta)\nnp.random.seed(42)\nX_ornek = np.random.randn(100, 30)  # 100 hasta, 30 radiomics/tahlil özelliği\nX_4d, pca_pipe = boyut_indirgeme_uygula(X_ornek, n_components=4)\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Orijinal boyut : (100, 30)\n",
      "İndirgenmiş   : (100, 4)\n",
      "Açıklanan varyans oranı (kümülatif): 0.262\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Xpwn04l39Fwo"
   },
   "source": "### Kategorik alanların hazırlanması\nCinsiyet, ilaç grubu, komorbidite kodu gibi alanlar One-Hot Encoding ile sayısallaştırılmalıdır.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama3_onehot",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471814354,
     "user_tz": -180,
     "elapsed": 278,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "b166d594-22bb-4036-9823-7130e25d2968"
   },
   "source": "# Kategorik → One-Hot örneği (hastane bağlamı)\nornek_df = pd.DataFrame({\n    \"Yas\": [45, 62, 38],\n    \"Cinsiyet\": [\"K\", \"E\", \"K\"],\n    \"Komorbidite\": [\"Diyabet\", \"Yok\", \"Hipertansiyon\"]\n})\ndf_one_hot = pd.get_dummies(ornek_df, columns=[\"Cinsiyet\", \"Komorbidite\"], dtype=float)\nprint(\"One-Hot sonrası:\")\nprint(df_one_hot)\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "One-Hot sonrası:\n",
      "   Yas  Cinsiyet_E  Cinsiyet_K  Komorbidite_Diyabet  \\\n",
      "0   45         0.0         1.0                  1.0   \n",
      "1   62         1.0         0.0                  0.0   \n",
      "2   38         0.0         1.0                  0.0   \n",
      "\n",
      "   Komorbidite_Hipertansiyon  Komorbidite_Yok  \n",
      "0                        0.0              0.0  \n",
      "1                        0.0              1.0  \n",
      "2                        1.0              0.0  \n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hbR0vcC_9Fwq"
   },
   "source": "## AŞAMA 4: Sentetik Hasta Verisi Üretimi ve Anonimleştirme (KVKK)\n\nGerçek hasta verisi paylaşmadan modeli geliştirebilmek için **sentetik kohort** üretiriz.  \nArdından KVKK/GDPR uyumlu anonimleştirme adımları uygulanır:\n\n1. Doğrudan tanımlayıcılar (ad, TC, protokol) → hash veya tamamen kaldırılır  \n2. Sadece model özellikleri + anonim ID tutulur  \n3. Kuantum devresine **yalnızca anonim sayısal vektör** gider  \n\nAşağıda iki seçenek vardır:\n- **Sentetik veri üret** (önerilen başlangıç)\n- Kendi CSV’nizi yükleyin (Aşama 5)\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama4_sentetik_anon",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471821448,
     "user_tz": -180,
     "elapsed": 345,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "7185c7b4-cc9f-4b8b-bbcc-b5a2cb55032d"
   },
   "source": "import hashlib\nimport uuid\nfrom sklearn.datasets import make_classification\n\ndef sentetik_hasta_verisi_uret(n_samples=300, n_features=12, random_state=42):\n    \"\"\"\n    İlaç etkinliği sınıflandırması için sentetik hasta kohortu.\n    Özellikler: tahlil + radiomics benzeri sürekli değerler.\n    Hedef: 0 = ilaç etkisiz, 1 = ilaç etkili\n    \"\"\"\n    X, y = make_classification(\n        n_samples=n_samples,\n        n_features=n_features,\n        n_informative=max(2, n_features // 2),\n        n_redundant=max(0, n_features // 4),\n        n_clusters_per_class=2,\n        class_sep=1.2,\n        random_state=random_state\n    )\n    # Klinik isimlendirme (örnek)\n    feature_names = [f\"Ozellik_{i+1}\" for i in range(n_features)]\n    # İlk birkaçına anlamlı isim verelim\n    klinik_isimler = [\n        \"Yas_norm\", \"BMI_norm\", \"CRP\", \"WBC\", \"Kreatinin\",\n        \"Tumor_marker\", \"Radiomics_1\", \"Radiomics_2\",\n        \"Radiomics_3\", \"Radiomics_4\", \"Karaciger_ALT\", \"Hgb\"\n    ]\n    for i, isim in enumerate(klinik_isimler):\n        if i < n_features:\n            feature_names[i] = isim\n\n    df = pd.DataFrame(X, columns=feature_names)\n    df[\"Ilac_Etkin\"] = y  # 0/1\n\n    # Sahte doğrudan tanımlayıcılar (anonimleştirme demosu için)\n    df[\"Hasta_Ad\"] = [f\"Hasta_{i}\" for i in range(n_samples)]\n    df[\"Protokol_No\"] = [f\"PR-{10000+i}\" for i in range(n_samples)]\n    df[\"TC_Kimlik\"] = [f\"{10000000000+i}\" for i in range(n_samples)]\n\n    return df\n\ndef anonimlestir(df, id_col=\"Anonim_ID\"):\n    \"\"\"\n    Doğrudan tanımlayıcıları kaldırır / hash’ler.\n    Geri dönüşüm için sadece yetkili tarafta tutulacak mapping üretir.\n    \"\"\"\n    mapping = {}\n    anon_ids = []\n    for idx, row in df.iterrows():\n        ham = f\"{row.get('TC_Kimlik','')}-{row.get('Protokol_No','')}-{row.get('Hasta_Ad','')}\"\n        anon = hashlib.sha256(ham.encode()).hexdigest()[:16]\n        anon_ids.append(anon)\n        mapping[anon] = {\n            \"Hasta_Ad\": row.get(\"Hasta_Ad\"),\n            \"Protokol_No\": row.get(\"Protokol_No\"),\n            \"TC_Kimlik\": row.get(\"TC_Kimlik\")\n        }\n\n    # Tanımlayıcı sütunları düşür\n    drop_cols = [c for c in [\"Hasta_Ad\", \"Protokol_No\", \"TC_Kimlik\"] if c in df.columns]\n    df_anon = df.drop(columns=drop_cols).copy()\n    df_anon.insert(0, id_col, anon_ids)\n\n    print(f\"Anonimleştirme tamamlandı. {len(df_anon)} kayıt.\")\n    print(f\"Kaldırılan sütunlar: {drop_cols}\")\n    print(f\"Mapping sözlüğü {len(mapping)} girdi içeriyor (sadece yetkili tarafta saklanmalı).\")\n    return df_anon, mapping\n\n# --- Sentetik kohort üret ve anonimleştir ---\ndf_ham = sentetik_hasta_verisi_uret(n_samples=300, n_features=12)\nprint(\"Ham sentetik veri (ilk 3 satır, tanımlayıcılar görünür):\")\nprint(df_ham[[\"Hasta_Ad\", \"Protokol_No\", \"Yas_norm\", \"CRP\", \"Ilac_Etkin\"]].head(3))\nprint()\n\ndf_anon, deanon_mapping = anonimlestir(df_ham)\nprint(\"\\nAnonim veri (ilk 3 satır):\")\nprint(df_anon.head(3))\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Ham sentetik veri (ilk 3 satır, tanımlayıcılar görünür):\n",
      "  Hasta_Ad Protokol_No  Yas_norm       CRP  Ilac_Etkin\n",
      "0  Hasta_0    PR-10000  0.327880 -3.429009           0\n",
      "1  Hasta_1    PR-10001  1.096469 -5.153065           0\n",
      "2  Hasta_2    PR-10002 -1.643189  5.067190           0\n",
      "\n",
      "Anonimleştirme tamamlandı. 300 kayıt.\n",
      "Kaldırılan sütunlar: ['Hasta_Ad', 'Protokol_No', 'TC_Kimlik']\n",
      "Mapping sözlüğü 300 girdi içeriyor (sadece yetkili tarafta saklanmalı).\n",
      "\n",
      "Anonim veri (ilk 3 satır):\n",
      "          Anonim_ID  Yas_norm  BMI_norm       CRP       WBC  Kreatinin  \\\n",
      "0  ba65e1d607189a7d  0.327880 -0.125454 -3.429009 -0.966273   0.622677   \n",
      "1  693471c5ba2d6aa9  1.096469  1.223569 -5.153065  0.123042  -2.753199   \n",
      "2  baf585ace757c3cc -1.643189 -0.103255  5.067190  0.676039   4.462769   \n",
      "\n",
      "   Tumor_marker  Radiomics_1  Radiomics_2  Radiomics_3  Radiomics_4  \\\n",
      "0      1.057780    -0.633576    -2.640361    -1.195982     1.127387   \n",
      "1     -2.309980     0.784641    -1.693481    -2.583432     0.700140   \n",
      "2      1.021881    -2.666907     4.191878     3.264531    -0.658737   \n",
      "\n",
      "   Karaciger_ALT       Hgb  Ilac_Etkin  \n",
      "0      -2.404128  0.085893           0  \n",
      "1      -1.881216 -0.625677           0  \n",
      "2       3.296044 -0.175854           0  \n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hR3l5Nay9Fwu"
   },
   "source": "## AŞAMA 5: (Opsiyonel) Kendi CSV Dosyanızı Yükleme\n\nSentetik veri yerine gerçek (anonimleştirilmiş) hasta CSV’si kullanmak isterseniz  \naşağıdaki yükleyiciyi kullanın. CSV’de hedef sütun adı tercihen `Ilac_Etkin` olsun.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama5_upload",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 49,
     "referenced_widgets": [
      "88dca262feae4c99851575d9553b8999",
      "d4eba1fac4ba4e9c86dbe8982f351c9a",
      "8b20979c08554df3a476d07355ef58e7"
     ]
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471828728,
     "user_tz": -180,
     "elapsed": 474,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "4f12a8aa-34a8-4bf0-cd43-8b69c45cf163"
   },
   "source": "import ipywidgets as widgets\nfrom IPython.display import display\nimport io\n\nuploader = widgets.FileUpload(accept=\".csv\", multiple=False, description=\"CSV Yükle\")\ndisplay(uploader)\n\ndef yuklenen_csv_oku(uploader_widget):\n    if not uploader_widget.value:\n        print(\"Henüz dosya yüklenmedi. Sentetik veri (df_anon) kullanılmaya devam eder.\")\n        return None\n    # Colab / Jupyter farkı için esnek okuma\n    uploaded = uploader_widget.value\n    if isinstance(uploaded, dict):\n        file_info = list(uploaded.values())[0]\n        content = file_info[\"content\"]\n    else:\n        file_info = uploaded[0]\n        content = file_info[\"content\"]\n    df = pd.read_csv(io.BytesIO(content))\n    print(f\"Yüklendi: {df.shape[0]} satır, {df.shape[1]} sütun\")\n    print(df.head(3))\n    return df\n\n# Kullanım: df_yuklenen = yuklenen_csv_oku(uploader)\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": [
       "FileUpload(value={}, accept='.csv', description='CSV Yükle')"
      ],
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "88dca262feae4c99851575d9553b8999"
      }
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "VJ6zQweO9Fww"
   },
   "source": "## AŞAMA 5b: Model İçin Özellik Matrisinin Hazırlanması\n\nAnonim veri üzerinden:\n1. Hedef sütunu ayır  \n2. (Gerekirse) PCA uygula  \n3. Eğitim / test bölünmesi yap\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama5b_hazirlik",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471834272,
     "user_tz": -180,
     "elapsed": 95,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "49ef5118-bb92-453f-89dc-9811f9843243"
   },
   "source": "from sklearn.model_selection import train_test_split\n\n# Hedef ve özellikler\nTARGET = \"Ilac_Etkin\"\nfeature_cols = [c for c in df_anon.columns if c not in (TARGET, \"Anonim_ID\")]\n\nX = df_anon[feature_cols].values\ny = df_anon[TARGET].values\n\nprint(f\"Özellik matrisi: {X.shape}  |  Hedef dağılımı: {np.bincount(y)}\")\n\n# Boyut yüksekse PCA (seçim aracındaki öneriye göre ayarlayın)\nN_COMPONENTS = 4  # Seçim aracından gelen pca_target değerini buraya yazabilirsiniz\nif X.shape[1] > N_COMPONENTS:\n    X_red, pca_model = boyut_indirgeme_uygula(X, n_components=N_COMPONENTS)\nelse:\n    X_red = StandardScaler().fit_transform(X)\n    print(\"PCA gerekmedi, sadece standardizasyon uygulandı.\")\n\nX_train, X_test, y_train, y_test = train_test_split(\n    X_red, y, test_size=0.25, random_state=42, stratify=y\n)\nprint(f\"Eğitim: {X_train.shape[0]}  |  Test: {X_test.shape[0]}\")\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Özellik matrisi: (300, 12)  |  Hedef dağılımı: [151 149]\n",
      "Orijinal boyut : (300, 12)\n",
      "İndirgenmiş   : (300, 4)\n",
      "Açıklanan varyans oranı (kümülatif): 0.651\n",
      "Eğitim: 225  |  Test: 75\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "yUUK-Dch9Fwx"
   },
   "source": "## AŞAMA 6–7: Feature Map ve Ansatz (Kuantum Devresi)\n\n- **Feature Map:** Klasik özellikleri kuantum durumuna kodlar (ZZFeatureMap)  \n- **Ansatz:** Eğitilebilir parametreli devre (RealAmplitudes) — VQC kullanıldığında  \n\nKernel tabanlı QSVM için yalnızca feature map yeterlidir.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama6_7_circuit",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "status": "ok",
     "timestamp": 1786471842545,
     "user_tz": -180,
     "elapsed": 910,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "26c6d9e0-6243-424c-a521-fbb8f1e103f6"
   },
   "source": "from qiskit import QuantumCircuit\nfrom qiskit.circuit.library import zz_feature_map, real_amplitudes\n\nnum_features = X_train.shape[1]\nprint(f\"Kullanılacak kübit / özellik sayısı: {num_features}\")\n\nfeature_map = zz_feature_map(\n    feature_dimension=num_features,\n    reps=2,\n    entanglement=\"linear\"\n)\n\nansatz = real_amplitudes(num_qubits=num_features, reps=3)\n\n# Birleşik devre örneği (VQC için)\nqc = QuantumCircuit(num_features)\nqc.compose(feature_map, inplace=True)\nqc.compose(ansatz, inplace=True)\nqc.measure_all()\n\nprint(\"Feature map + Ansatz hazır.\")\nprint(f\"Feature map derinliği (approx): {feature_map.depth()}\")\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Kullanılacak kübit / özellik sayısı: 4\n",
      "Feature map + Ansatz hazır.\n",
      "Feature map derinliği (approx): 19\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "NID-KldK9Fw0"
   },
   "source": "## AŞAMA 8: Kuantum Kernel Oluşturma\n\nFidelityQuantumKernel, veri noktalarının kuantum durumlarındaki benzerliğini hesaplar.  \n`shots` değeri istatistiksel kararlılığı etkiler (1024 iyi bir başlangıçtır).\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama8_kernel",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 378
    },
    "executionInfo": {
     "status": "error",
     "timestamp": 1786472042027,
     "user_tz": -180,
     "elapsed": 18,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    },
    "outputId": "333d9b3b-2830-4cea-b91f-b47f4d5c99bd"
   },
   "source": "from qiskit_machine_learning.kernels import FidelityQuantumKernel\nfrom qiskit_algorithms.state_fidelities import ComputeUncompute\nfrom qiskit.primitives import StatevectorSampler\n\nshots = 1024\n_device = globals().get(\"AER_DEVICE\", \"CPU\")\n_use_gpu = globals().get(\"USE_GPU_AER\", False)\n\nif _use_gpu:\n    try:\n        from qiskit_aer import AerSimulator\n        sim = AerSimulator(method=\"statevector\", device=\"GPU\")\n        print(\"Aer GPU denemesi OK. available_devices:\", AerSimulator().available_devices())\n    except Exception as e:\n        print(\"GPU Aer kullanılamadı:\", e)\n    # Fidelity kernel için exact sampler (küçük devrede stabil)\n    sampler = StatevectorSampler()\n    print(\"FidelityQuantumKernel: StatevectorSampler (exact). Büyük devrede AerSampler+GPU özelleştirilebilir.\")\nelse:\n    sampler = StatevectorSampler()\n    print(f\"Sampler: StatevectorSampler (AER_DEVICE={_device})\")\n\nfidelity = ComputeUncompute(sampler=sampler)\nqkernel = FidelityQuantumKernel(fidelity=fidelity, feature_map=feature_map)\nprint(f\"Kuantum Kernel hazır. Shot referans: {shots}\")\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "error",
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'qiskit_machine_learning'",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_1029/4017765636.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mqiskit_machine_learning\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkernels\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mFidelityQuantumKernel\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mqiskit_algorithms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstate_fidelities\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mComputeUncompute\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mqiskit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprimitives\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mStatevectorSampler\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mshots\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1024\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'qiskit_machine_learning'",
      "",
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n"
     ],
     "errorDetails": {
      "actions": [
       {
        "action": "open_url",
        "actionText": "Open Examples",
        "url": "/notebooks/snippets/importing_libraries.ipynb"
       }
      ]
     }
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "CSn5JfAQ9Fw2"
   },
   "source": "## AŞAMA 9: Modelin Eğitilmesi (QSVM) — Simülatör\n\nQiskit Machine Learning içindeki QSVC (Quantum Support Vector Classifier) kullanılır.  \nÖnce simülatörde eğitip test skoruna bakıyoruz.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama9_qsvc",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 378
    },
    "outputId": "5026274f-1a0e-415e-9312-3e27381c6e25",
    "executionInfo": {
     "status": "error",
     "timestamp": 1786471994600,
     "user_tz": -180,
     "elapsed": 363,
     "user": {
      "displayName": "Joseph Volkan ÖZCAN",
      "userId": "11389530967736397480"
     }
    }
   },
   "source": "from qiskit_machine_learning.algorithms import QSVC\nfrom sklearn.metrics import classification_report, accuracy_score, confusion_matrix\n\n# QSVC — quantum kernel ile SVM\nqsvc = QSVC(quantum_kernel=qkernel)\n\nprint(\"Eğitim başlıyor (simülatör)...\")\nqsvc.fit(X_train, y_train)\n\ny_pred = qsvc.predict(X_test)\nacc = accuracy_score(y_test, y_pred)\nprint(f\"\\nTest doğruluğu: {acc:.3f}\")\nprint(\"\\nSınıflandırma raporu:\")\nprint(classification_report(y_test, y_pred, target_names=[\"Etkisiz\", \"Etkili\"]))\nprint(\"Karmaşıklık matrisi:\")\nprint(confusion_matrix(y_test, y_pred))\n",
   "execution_count": null,
   "outputs": [
    {
     "output_type": "error",
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'qiskit_machine_learning'",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m/tmp/ipykernel_570/295129105.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mqiskit_machine_learning\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0malgorithms\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mQSVC\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmetrics\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mclassification_report\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maccuracy_score\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconfusion_matrix\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;31m# QSVC — quantum kernel ile SVM\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mqsvc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mQSVC\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mquantum_kernel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mqkernel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'qiskit_machine_learning'",
      "",
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0;32m\nNOTE: If your import is failing due to a missing package, you can\nmanually install dependencies using either !pip or !apt.\n\nTo view examples of installing some common dependencies, click the\n\"Open Examples\" button below.\n\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n"
     ],
     "errorDetails": {
      "actions": [
       {
        "action": "open_url",
        "actionText": "Open Examples",
        "url": "/notebooks/snippets/importing_libraries.ipynb"
       }
      ]
     }
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "aUWqQe6e9Fw4"
   },
   "source": "## AŞAMA 10: Sonuçların Yorumlanması ve De-Anonimleştirme\n\nKuantum / model çıktısı anonim ID’ler üzerinden gelir.  \nSadece yetkili sistem, saklanan mapping ile gerçek kimliğe dönebilir.\n\n> Üretim ortamında mapping **ayrı, erişim kontrollü** bir serviste tutulmalıdır.  \n> Bu notebook yalnızca eğitim amaçlı demo yapar.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama10_deanon"
   },
   "source": "# Örnek: test setinden birkaç anonim ID için tahmin + de-anonimleştirme\n# (Gerçek pipeline'da X_test satırları ile Anonim_ID eşleştirilir)\n\n# Demo: rastgele 3 anonim ID al\nornek_anon_ids = df_anon[\"Anonim_ID\"].sample(3, random_state=1).tolist()\n\nprint(\"Örnek de-anonimleştirme (sadece yetkili erişim):\")\nfor aid in ornek_anon_ids:\n    gercek = deanon_mapping.get(aid, {})\n    print(f\"  Anonim ID : {aid}\")\n    print(f\"  → Gerçek  : {gercek.get('Hasta_Ad')} | Protokol: {gercek.get('Protokol_No')}\")\n    print()\n",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "lz5kLSYx9Fw5"
   },
   "source": "## AŞAMA 11: Sonuçların Dışa Aktarılması (CSV & SQL)\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama11_export"
   },
   "source": "import sqlite3\nimport os\n\n# Tahmin sonuçlarını tabloya dök (demo: test seti)\nsonuc_df = pd.DataFrame({\n    \"y_true\": y_test,\n    \"y_pred\": y_pred\n})\nsonuc_df[\"Dogru_Mu\"] = (sonuc_df[\"y_true\"] == sonuc_df[\"y_pred\"]).astype(int)\n\noutput_dir = \"./sonuclar\"\nos.makedirs(output_dir, exist_ok=True)\ncsv_path = os.path.join(output_dir, \"ilac_etkinligi_tahminleri.csv\")\nsonuc_df.to_csv(csv_path, index=False)\nprint(f\"CSV kaydedildi: {csv_path}\")\n\nconn = sqlite3.connect(\"qml_hastane.db\")\nsonuc_df.to_sql(\"Ilac_Etkinlik_Tahminleri\", conn, if_exists=\"replace\", index=False)\nconn.close()\nprint(\"SQL tablosuna yazıldı: Ilac_Etkinlik_Tahminleri\")\nprint(sonuc_df.head())\n",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "tQQ7VbZ89Fw7"
   },
   "source": "## AŞAMA 12: Görselleştirme\n\nSınıf dağılımı ve (varsa) kuantum ölçüm histogramı.\n"
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "asama12_viz"
   },
   "source": "%matplotlib inline\nimport matplotlib.pyplot as plt\nfrom qiskit.visualization import plot_histogram\n\n# 1) Gerçek vs tahmin sınıf dağılımı\nfig, axes = plt.subplots(1, 2, figsize=(10, 4))\naxes[0].hist(y_test, bins=[-0.5, 0.5, 1.5], rwidth=0.6, color=\"steelblue\")\naxes[0].set_xticks([0, 1])\naxes[0].set_xticklabels([\"Etkisiz\", \"Etkili\"])\naxes[0].set_title(\"Gerçek (y_test)\")\naxes[1].hist(y_pred, bins=[-0.5, 0.5, 1.5], rwidth=0.6, color=\"teal\")\naxes[1].set_xticks([0, 1])\naxes[1].set_xticklabels([\"Etkisiz\", \"Etkili\"])\naxes[1].set_title(\"Tahmin (y_pred)\")\nplt.tight_layout()\nplt.show()\n\n# 2) Örnek kuantum ölçüm histogramı (demo counts)\ndemo_counts = {\"00\": 480, \"01\": 120, \"10\": 95, \"11\": 329}\nfig2 = plot_histogram(demo_counts, title=\"Örnek Kuantum Ölçüm Histogramı\", figsize=(8, 5), color=\"teal\")\ndisplay(fig2)\n",
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hn2BQtAy9Fw8"
   },
   "source": "## Özet ve Sonraki Adımlar\n\nBu notebook’ta yapılanlar:\n\n1. **Problem tanımı** — Hastane ilaç etkinliği tahmini (sınıflandırma)\n2. **Aşama 1b** — CPU / GPU / TPU seçimi ve Qiskit Aer’e etkisi  \n2. **Veri büyüklüğü ayrımı** — `n_samples` (hasta sayısı) vs `n_features` (özellik / kübit) netleştirildi  \n3. **Seçim aracı** — Encoding, kübit hesabı, algoritma ve cihaz önerisi  \n4. **Sentetik kohort** + **KVKK anonimleştirme**  \n5. **PCA** ile boyut indirgeme  \n6. **ZZFeatureMap + FidelityQuantumKernel + QSVC** ile eğitim ve test  \n7. **De-anonimleştirme demosu**, CSV/SQL export, görselleştirme  \n\n### Gerçek ortama geçerken\n- Mapping tablosunu kuantum pipeline’ından **ayırın** (ayrı yetkili servis)  \n- Ham görüntüleri yalnızca klasik özellik çıkarımı için kullanın  \n- Gerçek IBM Quantum backend’ine geçmeden önce noise model ile test edin  \n- Klinik validasyon ve etik kurul onayı olmadan üretim kararı vermeyin  \n\n**Colab’da çalıştırma sırası:** Yukarıdan aşağıya hücreleri sırayla Run edin.  \nSeçim aracındaki `n_features` / PCA hedefini Aşama 5b’deki `N_COMPONENTS` ile uyumlu tutun.\n"
  }
 ]
}