{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# GeoPython Lab 06 — First Machine Learning Model\n",
        "**Στόχος:** ένα απλό classification workflow με scikit-learn.\n",
        "\n",
        "Το dataset είναι συνθετικό και προσομοιώνει τρεις φασματικές μεταβλητές.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn.ensemble import RandomForestClassifier\n",
        "from sklearn.metrics import accuracy_score, classification_report\n",
        "\n",
        "np.random.seed(10)\n",
        "n = 400\n",
        "\n",
        "X = pd.DataFrame({\n",
        "    \"red\": np.random.uniform(0.05, 0.5, n),\n",
        "    \"nir\": np.random.uniform(0.1, 0.9, n),\n",
        "    \"swir\": np.random.uniform(0.05, 0.6, n),\n",
        "})\n",
        "\n",
        "X[\"ndvi\"] = (X[\"nir\"] - X[\"red\"]) / (X[\"nir\"] + X[\"red\"])\n",
        "y = np.where(X[\"ndvi\"] > 0.35, \"vegetation\", \"other\")\n",
        "X.head()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "X_train, X_test, y_train, y_test = train_test_split(\n",
        "    X, y, test_size=0.25, random_state=42, stratify=y\n",
        ")\n",
        "\n",
        "model = RandomForestClassifier(n_estimators=150, random_state=42)\n",
        "model.fit(X_train, y_train)\n",
        "\n",
        "pred = model.predict(X_test)\n",
        "print(\"Accuracy:\", accuracy_score(y_test, pred))\n",
        "print(classification_report(y_test, pred))\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "importance = pd.Series(model.feature_importances_, index=X.columns).sort_values(ascending=False)\n",
        "importance\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Μικρή άσκηση\n",
        "Αφαίρεσε το `ndvi` από τα features και σύγκρινε την επίδοση του μοντέλου.\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}