{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "**Note:** This notebook is designed for **Google Colab**.\n",
        "\n",
        "If you see the Colab logo <span style='vertical-align:bottom;'><img src='https://colab.research.google.com/img/colab_favicon_256px.png' width='40' alt='Colab logo'></span> in the top-left corner, you're all set! Please **continue**.\n",
        "\n",
        "If you don't see the logo (e.g., you are on GitHub), please click the button below to open it in the correct environment:\n",
        "\n",
        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mparrott-at-wiris/aimodelshare/blob/master/notebooks/justice_and_equity_advance_notebook_en.ipynb)"
      ],
      "metadata": {
        "id": "pjnUTfUOGMX3"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Advanced Justice & Equity Challenge: Build & Submit Custom Models**\n",
        "\n",
        "Welcome to the **Advanced Pathway** of the Ethics at Play (Ètica en Joc) Justice Challenge.\n",
        "\n",
        "**Who is this for?**\n",
        "This notebook is designed for participants with Python experience (e.g., Scikit-Learn, TensorFlow, PyTorch). Instead of using the gamified apps, you will build, train, and submit your own machine learning models directly to the competition leaderboard.\n",
        "\n",
        "**The Goal:**\n",
        "Train a model to predict recidivism risk (the likelihood of re-offending) using the COMPAS dataset, while balancing accuracy and fairness."
      ],
      "metadata": {
        "id": "intro_advanced"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 🚀 **Quick Start Guide**\n",
        "\n",
        "To participate in the challenge, complete these 5 steps:\n",
        "\n",
        "1.  **Install Libraries:** Run the setup cell to install `aimodelshare`.\n",
        "2.  **Get the Data:** Run the data loading cell to retrieve the pre-split training and testing data.\n",
        "3.  **Train Your Model:** Use the provided Scikit-Learn Pipeline example or write your own custom training code.\n",
        "4.  **Connect:** Link this notebook to the Justice Challenge Leaderboard.\n",
        "5.  **Submit:** Send your predictions to the leaderboard to see your score.\n",
        "\n",
        "**Ready? Click the ▶ Play Button on the first cell below to get started.**"
      ],
      "metadata": {
        "id": "quick_start_guide"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Step 1: Installation**\n",
        "\n",
        "We need to install the `aimodelshare` library to connect to the competition backend."
      ],
      "metadata": {
        "id": "step1_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Install the aimodelshare library\n",
        "print(\"Installing required libraries...\")\n",
        "!pip install aimodelshare --upgrade -q --no-warn-script-location > /dev/null 2>&1\n",
        "print(\"✅ Installation complete!\")"
      ],
      "metadata": {
        "id": "step1_code"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Step 2: Load Data**\n",
        "\n",
        "We will load the training and testing data directly from the official competition URLs.\n",
        "\n",
        "* **X_train:** Features for training.\n",
        "* **y_train:** Target labels (did recidivism occur?) for training.\n",
        "* **X_test:** Features for testing (you will generate predictions on this)."
      ],
      "metadata": {
        "id": "step2_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "\n",
        "# 1. Load Data from URLs\n",
        "X_train = pd.read_csv(\"https://raw.githubusercontent.com/AIModelShare/aimodelshare_tutorials/refs/heads/main/datasets/ethicsatplay/X_train.csv\")\n",
        "X_test = pd.read_csv(\"https://raw.githubusercontent.com/AIModelShare/aimodelshare_tutorials/refs/heads/main/datasets/ethicsatplay/X_test.csv\")\n",
        "y_train_labels = pd.read_csv(\"https://raw.githubusercontent.com/AIModelShare/aimodelshare_tutorials/refs/heads/main/datasets/ethicsatplay/y_train.csv\")\n",
        "\n",
        "# Ensure y_train is a 1D Series (required for sklearn)\n",
        "y_train = y_train_labels.squeeze()\n",
        "\n",
        "# 2. Define Feature Lists for the Pipeline\n",
        "# These lists match the columns present in X_train and X_test\n",
        "ALL_NUMERIC_COLS = [\"juv_fel_count\", \"juv_misd_count\", \"juv_other_count\", \"days_b_screening_arrest\", \"age\", \"length_of_stay\", \"priors_count\"]\n",
        "ALL_CATEGORICAL_COLS = [\"race\", \"sex\", \"c_charge_degree\", \"c_charge_desc\"]\n",
        "\n",
        "print(\"✅ Data loaded successfully!\")\n",
        "print(f\"Training data shape: {X_train.shape}\")\n",
        "print(f\"Testing data shape: {X_test.shape}\")\n",
        "print(\"\\nFirst 5 rows of training data:\")\n",
        "X_train.head()"
      ],
      "metadata": {
        "id": "step2_code",
        "outputId": "f48a66f7-7ace-4d28-b9e6-92162d8f74d3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 297
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Data loaded successfully!\n",
            "Training data shape: (7214, 11)\n",
            "Testing data shape: (1000, 11)\n",
            "\n",
            "First 5 rows of training data:\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "   juv_fel_count  juv_misd_count  juv_other_count  days_b_screening_arrest  \\\n",
              "0              0               0                0                     -1.0   \n",
              "1              0               0                0                     -1.0   \n",
              "2              0               0                1                     -1.0   \n",
              "3              0               1                0                      NaN   \n",
              "4              0               0                0                      NaN   \n",
              "\n",
              "   age  length_of_stay  priors_count              race   sex c_charge_degree  \\\n",
              "0   69        0.984468             0             Other  Male               F   \n",
              "1   34       10.077384             0  African-American  Male               F   \n",
              "2   24        1.085764             4  African-American  Male               F   \n",
              "3   23             NaN             1  African-American  Male               F   \n",
              "4   43             NaN             2             Other  Male               F   \n",
              "\n",
              "                    c_charge_desc  \n",
              "0    Aggravated Assault w/Firearm  \n",
              "1  Felony Battery w/Prior Convict  \n",
              "2           Possession of Cocaine  \n",
              "3          Possession of Cannabis  \n",
              "4           arrest case no charge  "
            ],
            "text/html": [
              "\n",
              "  <div id=\"df-778bc850-8575-4d3f-956f-a2b89bf37895\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>juv_fel_count</th>\n",
              "      <th>juv_misd_count</th>\n",
              "      <th>juv_other_count</th>\n",
              "      <th>days_b_screening_arrest</th>\n",
              "      <th>age</th>\n",
              "      <th>length_of_stay</th>\n",
              "      <th>priors_count</th>\n",
              "      <th>race</th>\n",
              "      <th>sex</th>\n",
              "      <th>c_charge_degree</th>\n",
              "      <th>c_charge_desc</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>-1.0</td>\n",
              "      <td>69</td>\n",
              "      <td>0.984468</td>\n",
              "      <td>0</td>\n",
              "      <td>Other</td>\n",
              "      <td>Male</td>\n",
              "      <td>F</td>\n",
              "      <td>Aggravated Assault w/Firearm</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>-1.0</td>\n",
              "      <td>34</td>\n",
              "      <td>10.077384</td>\n",
              "      <td>0</td>\n",
              "      <td>African-American</td>\n",
              "      <td>Male</td>\n",
              "      <td>F</td>\n",
              "      <td>Felony Battery w/Prior Convict</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>-1.0</td>\n",
              "      <td>24</td>\n",
              "      <td>1.085764</td>\n",
              "      <td>4</td>\n",
              "      <td>African-American</td>\n",
              "      <td>Male</td>\n",
              "      <td>F</td>\n",
              "      <td>Possession of Cocaine</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>23</td>\n",
              "      <td>NaN</td>\n",
              "      <td>1</td>\n",
              "      <td>African-American</td>\n",
              "      <td>Male</td>\n",
              "      <td>F</td>\n",
              "      <td>Possession of Cannabis</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>43</td>\n",
              "      <td>NaN</td>\n",
              "      <td>2</td>\n",
              "      <td>Other</td>\n",
              "      <td>Male</td>\n",
              "      <td>F</td>\n",
              "      <td>arrest case no charge</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-778bc850-8575-4d3f-956f-a2b89bf37895')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-778bc850-8575-4d3f-956f-a2b89bf37895 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-778bc850-8575-4d3f-956f-a2b89bf37895');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "dataframe",
              "variable_name": "X_train",
              "summary": "{\n  \"name\": \"X_train\",\n  \"rows\": 7214,\n  \"fields\": [\n    {\n      \"column\": \"juv_fel_count\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 0,\n        \"min\": 0,\n        \"max\": 20,\n        \"num_unique_values\": 11,\n        \"samples\": [\n          3,\n          0,\n          5\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"juv_misd_count\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 0,\n        \"min\": 0,\n        \"max\": 13,\n        \"num_unique_values\": 10,\n        \"samples\": [\n          5,\n          1,\n          4\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"juv_other_count\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 0,\n        \"min\": 0,\n        \"max\": 17,\n        \"num_unique_values\": 10,\n        \"samples\": [\n          6,\n          1,\n          17\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"days_b_screening_arrest\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 75.80950476450238,\n        \"min\": -414.0,\n        \"max\": 1057.0,\n        \"num_unique_values\": 423,\n        \"samples\": [\n          -95.0,\n          126.0,\n          -87.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"age\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 11,\n        \"min\": 18,\n        \"max\": 96,\n        \"num_unique_values\": 65,\n        \"samples\": [\n          83,\n          18,\n          69\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"length_of_stay\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 51.080642685588145,\n        \"min\": -0.4876967592592592,\n        \"max\": 799.7926388888889,\n        \"num_unique_values\": 6821,\n        \"samples\": [\n          4.24761574074074,\n          0.8220949074074074,\n          2.061145833333333\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"priors_count\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 4,\n        \"min\": 0,\n        \"max\": 38,\n        \"num_unique_values\": 37,\n        \"samples\": [\n          28,\n          20,\n          14\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"race\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 6,\n        \"samples\": [\n          \"Other\",\n          \"African-American\",\n          \"Asian\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"sex\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          \"Female\",\n          \"Male\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"c_charge_degree\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          \"M\",\n          \"F\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"c_charge_desc\",\n      \"properties\": {\n        \"dtype\": \"category\",\n        \"num_unique_values\": 51,\n        \"samples\": [\n          \"DUI Property Damage/Injury\",\n          \"Burglary Unoccupied Dwelling\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}"
            }
          },
          "metadata": {},
          "execution_count": 47
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Step 3: Train Model with Preferred Library (Sklearn, Tensorflow, Pytorch, Etc.)**\n",
        "\n",
        "We will use a **Scikit-Learn Pipeline** to streamline preprocessing and modeling.\n",
        "\n",
        "This pipeline will:\n",
        "1.  **Impute Missing Values** (Fill NaNs with median for numbers, most frequent for categories).\n",
        "2.  **One-Hot Encode** categorical columns (Race, Sex, Charge Degree, Charge Desc).\n",
        "3.  **Scale** numerical columns (Age, Priors, Length of Stay, etc.).\n",
        "4.  **Train** a Logistic Regression classifier."
      ],
      "metadata": {
        "id": "step3_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn.pipeline import Pipeline\n",
        "from sklearn.compose import ColumnTransformer\n",
        "from sklearn.preprocessing import OneHotEncoder, StandardScaler\n",
        "from sklearn.impute import SimpleImputer\n",
        "from sklearn.linear_model import LogisticRegression\n",
        "\n",
        "# 1. Define feature groups using constants from Step 2\n",
        "# Numerical features will be imputed and scaled\n",
        "numeric_features = ALL_NUMERIC_COLS\n",
        "\n",
        "# Categorical features will be imputed and One-Hot Encoded\n",
        "categorical_features = ALL_CATEGORICAL_COLS\n",
        "\n",
        "# 2. Define Transformers with Imputation\n",
        "# Numeric: Impute missing values with the median, then scale\n",
        "numeric_transformer = Pipeline(steps=[\n",
        "    ('imputer', SimpleImputer(strategy='median')),\n",
        "    ('scaler', StandardScaler())\n",
        "])\n",
        "\n",
        "# Categorical: Impute missing values with the most frequent value, then one-hot encode\n",
        "categorical_transformer = Pipeline(steps=[\n",
        "    ('imputer', SimpleImputer(strategy='most_frequent')),\n",
        "    ('encoder', OneHotEncoder(handle_unknown='ignore'))\n",
        "])\n",
        "\n",
        "# 3. Create Preprocessor using the transformers\n",
        "preprocessor = ColumnTransformer(\n",
        "    transformers=[\n",
        "        ('num', numeric_transformer, numeric_features),\n",
        "        ('cat', categorical_transformer, categorical_features)\n",
        "    ])\n",
        "\n",
        "# 4. Create Pipeline (Preprocessor + Model)\n",
        "# You can replace LogisticRegression with any other sklearn model (e.g., RandomForestClassifier)\n",
        "pipeline = Pipeline(steps=[\n",
        "    ('preprocessor', preprocessor),\n",
        "    ('classifier', LogisticRegression(max_iter=1000))\n",
        "])\n",
        "\n",
        "# 5. Train the pipeline\n",
        "pipeline.fit(X_train, y_train)\n",
        "\n",
        "# 6. Generate predictions on the test set\n",
        "predictions = pipeline.predict(X_test)\n",
        "\n",
        "print(f\"✅ Model Trained! Predictions generated for {len(predictions)} samples.\")\n",
        "print(\"Proceed to the next step to submit your predictions to the leaderboard.\")"
      ],
      "metadata": {
        "id": "step3_code",
        "outputId": "38b35415-c1c7-46c1-8832-01c8dff318dc",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Model Trained! Predictions generated for 1000 samples.\n",
            "Proceed to the next step to submit your predictions to the leaderboard.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Step 4: Connect to the Leaderboard**\n",
        "\n",
        "This step connects your notebook to the specific backend for the Justice & Equity Challenge.\n",
        "\n",
        "*Note: You will be prompted to enter a username and password. If you don't have one, you will need to create one at [modelshare.ai](https://www.modelshare.ai)"
      ],
      "metadata": {
        "id": "step4_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from aimodelshare.aws import set_credentials\n",
        "from aimodelshare.playground import Competition\n",
        "import os\n",
        "\n",
        "import warnings\n",
        "warnings.simplefilter(action='ignore', category=FutureWarning)\n",
        "\n",
        "\n",
        "# The specific Model Playground URL for the Justice Challenge\n",
        "my_playground_url = \"https://cf3wdpkg0d.execute-api.us-east-1.amazonaws.com/prod/m\"\n",
        "\n",
        "# Set your credentials (pop-up will appear)\n",
        "set_credentials(apiurl=my_playground_url)\n",
        "\n",
        "# Generate your session access token\n",
        "token=os.getenv(\"AWS_TOKEN\")\n",
        "\n",
        "# Connect to the competition\n",
        "playground = Competition(my_playground_url)"
      ],
      "metadata": {
        "id": "step4_code",
        "outputId": "ebc25b98-355d-45df-ab99-078db7eed43f",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Modelshare.ai Username:··········\n",
            "Modelshare.ai Password:··········\n",
            "Modelshare.ai login credentials set successfully.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "# **Step 5: Submit & Check Results**\n",
        "\n",
        "Submit your predictions to the leaderboard."
      ],
      "metadata": {
        "id": "step5_md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# 1. Submit your predictions\n",
        "# Note: We pass None for model and preprocessor because we are only submitting predictions for evaluation\n",
        "playground.submit_model(\n",
        "    model=None,\n",
        "    preprocessor=None,\n",
        "    prediction_submission=predictions, token=token,\n",
        "    input_dict={\n",
        "        \"Team\": \"The Ethical Explorers\", # Change team name manually as needed.\n",
        "        \"description\": \"Logistic Regression with Sklearn Pipeline\",\n",
        "        \"tags\": \"sklearn, logistic_regression, advanced_pathway, pipeline\"\n",
        "    }\n",
        ")\n",
        "\n",
        "print(\"✅ Predictions submitted successfully!\")\n",
        "\n",
        "# 2. Check the leaderboard\n",
        "print(\"Loading leaderboard...\")\n",
        "leaderboard = playground.get_leaderboard()\n",
        "playground.stylize_leaderboard(leaderboard)"
      ],
      "metadata": {
        "id": "step5_code"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}
