HospitalCancerClassification/HospitalCancerClassification.ipynb
2026-05-02 20:36:49 +00:00

2047 lines
84 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"id": "c01ffe8d-3916-478f-a9c5-f3b480e5e293",
"metadata": {},
"source": [
"# Copyright Rayyan Hodges, TAFE NSW, Gelos Enterprises, Indigo Community Services and Health Hub © 2026"
]
},
{
"cell_type": "markdown",
"id": "b9f47b2c-6f01-479a-a87b-e698effc6edf",
"metadata": {},
"source": [
"# Contact: rayyan.hodges@studytafensw.edu.au, rayyan.hodges@gelosmail.com.au indigoCSHH@hmail.com"
]
},
{
"cell_type": "markdown",
"id": "c49336b7-8ec3-4a18-8590-4cd6c02917cb",
"metadata": {},
"source": [
"# Program Name: HopsitalCancerClassification.ipynb"
]
},
{
"cell_type": "markdown",
"id": "59691122-a537-4615-8a65-f408eb6fcffb",
"metadata": {},
"source": [
"# Purpose: To train and evaluate an ML model to automate the task of classifying clients as high, medium or low risk of developing cancer."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1092545b-8be3-487b-87df-d8829e0a00eb",
"metadata": {},
"outputs": [],
"source": [
"# Import required libraries\n",
"import joblib\n",
"import numpy\n",
"import pandas as pd\n",
"import sklearn # importing the scikit-learn project, different name due to syntax rules \n",
"import scipy\n",
"import threadpoolctl"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3a05014a-200c-4bc6-9667-568898547852",
"metadata": {},
"outputs": [],
"source": [
"# Set appropriate display options in Pandas\n",
"pd.set_option('display.max_rows', 10000)\n",
"pd.set_option('display.max_columns', 10000)\n",
"pd.set_option('display.width', 10000)"
]
},
{
"cell_type": "markdown",
"id": "95ffdbd6-b7e7-41b9-990f-932a05cae2e6",
"metadata": {},
"source": [
"# Identify any datapoints with missing labels and remove them"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "10d93e7f-9ba8-45a4-831d-7ba48046fea7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.int64(10)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Load the data set into memory and define it for further analysis.\n",
"df = pd.read_csv(\"data.csv\")\n",
"# Check for missing values in the target column, count them, and display them in a total number.\n",
"df['cancer_risk'].isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "3434f6bb-7cdb-4434-a948-1dc7d9e7d260",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.int64(0)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Remove the affected rows with missing data\n",
"df = df.dropna(subset=['cancer_risk'])\n",
"# Verify removal of said invalid data.\n",
"df['cancer_risk'].isnull().sum()"
]
},
{
"cell_type": "markdown",
"id": "44a9b1bc-0c6c-4e9e-95a7-03d3108b696b",
"metadata": {},
"source": [
"# Categorise ages as required."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a8887198-0dbd-471d-bd1e-836d34def83a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>age</th>\n",
" <th>age_group</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>51</td>\n",
" <td>45-54</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>92</td>\n",
" <td>85+</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>14</td>\n",
" <td>0-14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>71</td>\n",
" <td>65-74</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>60</td>\n",
" <td>55-64</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" age age_group\n",
"0 51 45-54\n",
"1 92 85+\n",
"2 14 0-14\n",
"3 71 65-74\n",
"4 60 55-64"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Define age bins and labels for the groups\n",
"# Bins meaning boundaries \n",
"bins = [0, 14, 24, 34, 44, 54, 64, 74, 84, 120]\n",
"labels = ['0-14', '15-24', '25-34', '35-44', \n",
" '45-54', '55-64', '65-74', '75-84', '85+']\n",
"\n",
"# Categorise ages into age groups\n",
"df['age_group'] = pd.cut(df['age'], bins=bins, labels=labels, right=True)\n",
"\n",
"# Display the results in a table\n",
"df[['age', 'age_group']].head()\n"
]
},
{
"cell_type": "markdown",
"id": "b2751d18-2580-453a-b0d9-70bc956f73cc",
"metadata": {},
"source": [
"# Standardise numerical features using appropriate scaling techniques."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f9beff06-ce08-479d-b63d-56ca8aaf6338",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>bmi</th>\n",
" <th>blood_pressure</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>9.900000e+02</td>\n",
" <td>9.900000e+02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>1.076580e-17</td>\n",
" <td>1.130409e-16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>1.000505e+00</td>\n",
" <td>1.000505e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>-1.679483e+00</td>\n",
" <td>-1.699762e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>-8.839714e-01</td>\n",
" <td>-8.598235e-01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>6.927133e-04</td>\n",
" <td>-1.794981e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>8.853568e-01</td>\n",
" <td>8.703721e-01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>1.735732e+00</td>\n",
" <td>1.772241e+00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" bmi blood_pressure\n",
"count 9.900000e+02 9.900000e+02\n",
"mean 1.076580e-17 1.130409e-16\n",
"std 1.000505e+00 1.000505e+00\n",
"min -1.679483e+00 -1.699762e+00\n",
"25% -8.839714e-01 -8.598235e-01\n",
"50% 6.927133e-04 -1.794981e-02\n",
"75% 8.853568e-01 8.703721e-01\n",
"max 1.735732e+00 1.772241e+00"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Import the scaling component from the SciKit Learning Library\n",
"from sklearn.preprocessing import StandardScaler\n",
"\n",
"# Select numerical features from the datasheet.\n",
"numerical_features = ['bmi', 'blood_pressure']\n",
"\n",
"# Initialise scaler component\n",
"scaler = StandardScaler()\n",
"\n",
"# Apply scaling and transformation to standardise the numbers.\n",
"df[numerical_features] = scaler.fit_transform(df[numerical_features])\n",
"\n",
"# Display results from the scaling and transformation.\n",
"df[numerical_features].describe()\n"
]
},
{
"cell_type": "markdown",
"id": "2616a37d-bffd-4a8d-b648-24673a543e7d",
"metadata": {},
"source": [
"# Encode categorical data using appropriate encoding techniques."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "8bc14115-e855-4233-9058-eff0ce5c9386",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<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>age</th>\n",
" <th>family_history</th>\n",
" <th>alcohol_consumption</th>\n",
" <th>bmi</th>\n",
" <th>blood_pressure</th>\n",
" <th>cholesterol_level</th>\n",
" <th>travelled_overseas</th>\n",
" <th>number_of_children</th>\n",
" <th>cancer_risk</th>\n",
" <th>age_group_15-24</th>\n",
" <th>age_group_25-34</th>\n",
" <th>age_group_35-44</th>\n",
" <th>age_group_45-54</th>\n",
" <th>age_group_55-64</th>\n",
" <th>age_group_65-74</th>\n",
" <th>age_group_75-84</th>\n",
" <th>age_group_85+</th>\n",
" <th>smoking_history_former</th>\n",
" <th>smoking_history_never</th>\n",
" <th>diet_good</th>\n",
" <th>diet_poor</th>\n",
" <th>exercise_frequency_low</th>\n",
" <th>exercise_frequency_moderate</th>\n",
" <th>exercise_frequency_none</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>51</td>\n",
" <td>no</td>\n",
" <td>low</td>\n",
" <td>0.487601</td>\n",
" <td>1.629026</td>\n",
" <td>226.4</td>\n",
" <td>no</td>\n",
" <td>5</td>\n",
" <td>moderate</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>92</td>\n",
" <td>no</td>\n",
" <td>moderate</td>\n",
" <td>-1.487463</td>\n",
" <td>1.396785</td>\n",
" <td>170.9</td>\n",
" <td>yes</td>\n",
" <td>2</td>\n",
" <td>low</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>14</td>\n",
" <td>no</td>\n",
" <td>none</td>\n",
" <td>0.528748</td>\n",
" <td>0.568459</td>\n",
" <td>279.9</td>\n",
" <td>yes</td>\n",
" <td>4</td>\n",
" <td>high</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>71</td>\n",
" <td>yes</td>\n",
" <td>low</td>\n",
" <td>1.667153</td>\n",
" <td>-0.101170</td>\n",
" <td>280.7</td>\n",
" <td>yes</td>\n",
" <td>0</td>\n",
" <td>moderate</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>60</td>\n",
" <td>no</td>\n",
" <td>none</td>\n",
" <td>-1.446316</td>\n",
" <td>0.649743</td>\n",
" <td>212.8</td>\n",
" <td>yes</td>\n",
" <td>5</td>\n",
" <td>moderate</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" age family_history alcohol_consumption bmi blood_pressure cholesterol_level travelled_overseas number_of_children cancer_risk age_group_15-24 age_group_25-34 age_group_35-44 age_group_45-54 age_group_55-64 age_group_65-74 age_group_75-84 age_group_85+ smoking_history_former smoking_history_never diet_good diet_poor exercise_frequency_low exercise_frequency_moderate exercise_frequency_none\n",
"0 51 no low 0.487601 1.629026 226.4 no 5 moderate False False False True False False False False False True False True False False True\n",
"1 92 no moderate -1.487463 1.396785 170.9 yes 2 low False False False False False False False True False True False True False False False\n",
"2 14 no none 0.528748 0.568459 279.9 yes 4 high False False False False False False False False False False False False False False True\n",
"3 71 yes low 1.667153 -0.101170 280.7 yes 0 moderate False False False False False True False False True False False True False False False\n",
"4 60 no none -1.446316 0.649743 212.8 yes 5 moderate False False False False True False False False True False False False False False True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Identify categorical features from the dataset file to be referenced.\n",
"categorical_features = ['age_group', 'smoking_history', 'diet', 'exercise_frequency']\n",
"\n",
"# Apply one-hot encoding to convert the text categories into dummy numerical categories (specifically true or false)\n",
"df_encoded = pd.get_dummies(df, columns=categorical_features, drop_first=True)\n",
"\n",
"# Print the results to ensure the categorical features have been converted to variables such as true or false correctly.\n",
"df_encoded.head()\n"
]
},
{
"cell_type": "markdown",
"id": "3b6926b7-31d0-4558-9695-c16570087104",
"metadata": {},
"source": [
"# Divide and randomise the dataset into training"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a5174be9-c40b-457e-afd5-1ec97c70ed0a",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"((693, 23), (148, 23), (149, 23))"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"# Remove rows with missing target labels (specifically, the 'cancer_risk' label, as it has missing data) \n",
"df_encoded = df_encoded.dropna(subset=['cancer_risk'])\n",
"\n",
"#Import the splitting model from the scikit-learn model.\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"# Separate features and target\n",
"X = df_encoded.drop('cancer_risk', axis=1)\n",
"y = df_encoded['cancer_risk']\n",
"\n",
"# First split: 70% training, 30% temp\n",
"X_train, X_temp, y_train, y_temp = train_test_split(\n",
" X, y, test_size=0.30, random_state=42, stratify=y\n",
")\n",
"\n",
"# Second split: 15% validation, 15% test\n",
"X_val, X_test, y_val, y_test = train_test_split(\n",
" X_temp, y_temp, test_size=0.50, random_state=42, stratify=y_temp\n",
")\n",
"\n",
"# Print the results of said sizes to ensure it is working correctly.\n",
"X_train.shape, X_val.shape, X_test.shape\n"
]
},
{
"cell_type": "markdown",
"id": "b4c21ba9-b730-4150-8b38-dfb5b00f87c1",
"metadata": {},
"source": [
"# Select the most important features in the training dataset that may influence cancer risk, dropping 2 unnecessary features."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "c94e2161-e95d-4a84-864d-bc1388bd4d48",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(693, 21)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Drop two unnecessary features/columns that aren't relevant to cancer risk evaluation and wouldn't affect if someone would be likely to have cancer.\n",
"X_train = X_train.drop(['travelled_overseas', 'number_of_children'], axis=1)\n",
"X_val = X_val.drop(['travelled_overseas', 'number_of_children'], axis=1)\n",
"X_test = X_test.drop(['travelled_overseas', 'number_of_children'], axis=1)\n",
"\n",
"# Print the results to allow the user to determine the changes have worked\n",
"X_train.shape\n"
]
},
{
"cell_type": "markdown",
"id": "49174e92-2e15-461a-844f-ffa90c0d7c99",
"metadata": {},
"source": [
"# Part 3: Train and evaluate ML model - Task 1: Train ML model 1"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b95cb28a-5312-4f55-8485-61c4e95e782e",
"metadata": {},
"outputs": [],
"source": [
"# Select an appropriate initial model size by setting the number of layers and neurons.\n",
"\n",
"\n",
"from sklearn.neural_network import MLPClassifier\n",
"\n",
"mlp_model_1 = MLPClassifier(\n",
" hidden_layer_sizes=(64, 32),\n",
" activation='relu',\n",
" solver='adam',\n",
" max_iter=300,\n",
" random_state=42\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "9a44bcdd-8605-4e21-9a7a-1a3296f46909",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"age int64\n",
"family_history str\n",
"alcohol_consumption str\n",
"bmi float64\n",
"blood_pressure float64\n",
"cholesterol_level float64\n",
"age_group_15-24 bool\n",
"age_group_25-34 bool\n",
"age_group_35-44 bool\n",
"age_group_45-54 bool\n",
"age_group_55-64 bool\n",
"age_group_65-74 bool\n",
"age_group_75-84 bool\n",
"age_group_85+ bool\n",
"smoking_history_former bool\n",
"smoking_history_never bool\n",
"diet_good bool\n",
"diet_poor bool\n",
"exercise_frequency_low bool\n",
"exercise_frequency_moderate bool\n",
"exercise_frequency_none bool\n",
"dtype: object"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# BUG FIXING: List any non numerical rows\n",
"X_train.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f16e2e40-e065-44ca-b944-e9a2921d89db",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_82/146862157.py:2: Pandas4Warning: For backward compatibility, 'str' dtypes are included by select_dtypes when 'object' dtype is specified. This behavior is deprecated and will be removed in a future version. Explicitly pass 'str' to `include` to select them, or to `exclude` to remove them and silence this warning.\n",
"See https://pandas.pydata.org/docs/user_guide/migration-3-strings.html#string-migration-select-dtypes for details on how to write code that works with pandas 2 and 3.\n",
" X_train.select_dtypes(include=['object']).head()\n"
]
},
{
"data": {
"text/html": [
"<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>family_history</th>\n",
" <th>alcohol_consumption</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>494</th>\n",
" <td>yes</td>\n",
" <td>none</td>\n",
" </tr>\n",
" <tr>\n",
" <th>379</th>\n",
" <td>yes</td>\n",
" <td>high</td>\n",
" </tr>\n",
" <tr>\n",
" <th>220</th>\n",
" <td>yes</td>\n",
" <td>none</td>\n",
" </tr>\n",
" <tr>\n",
" <th>732</th>\n",
" <td>yes</td>\n",
" <td>high</td>\n",
" </tr>\n",
" <tr>\n",
" <th>869</th>\n",
" <td>no</td>\n",
" <td>low</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" family_history alcohol_consumption\n",
"494 yes none\n",
"379 yes high\n",
"220 yes none\n",
"732 yes high\n",
"869 no low"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# BUG FIXING: Check if the text value exists\n",
"X_train.select_dtypes(include=['object']).head()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "f62a9503-664a-43d9-9afa-0029695acce8",
"metadata": {},
"outputs": [],
"source": [
"# BUG FIXING - Rayyan Hodges\n",
"\n",
"# Force all non-numeric columns to be one-hot encoded\n",
"X_train = pd.get_dummies(X_train)\n",
"X_val = pd.get_dummies(X_val)\n",
"X_test = pd.get_dummies(X_test)\n",
"\n",
"# Align columns so they match exactly\n",
"X_train, X_val = X_train.align(X_val, join=\"left\", axis=1, fill_value=0)\n",
"X_train, X_test = X_train.align(X_test, join=\"left\", axis=1, fill_value=0)\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "cfcddd52-1a78-4c07-8f5d-036682a8cad6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-1 {\n",
" /* Definition of color scheme common for light and dark mode */\n",
" --sklearn-color-text: #000;\n",
" --sklearn-color-text-muted: #666;\n",
" --sklearn-color-line: gray;\n",
" /* Definition of color scheme for unfitted estimators */\n",
" --sklearn-color-unfitted-level-0: #fff5e6;\n",
" --sklearn-color-unfitted-level-1: #f6e4d2;\n",
" --sklearn-color-unfitted-level-2: #ffe0b3;\n",
" --sklearn-color-unfitted-level-3: chocolate;\n",
" /* Definition of color scheme for fitted estimators */\n",
" --sklearn-color-fitted-level-0: #f0f8ff;\n",
" --sklearn-color-fitted-level-1: #d4ebff;\n",
" --sklearn-color-fitted-level-2: #b3dbfd;\n",
" --sklearn-color-fitted-level-3: cornflowerblue;\n",
"}\n",
"\n",
"#sk-container-id-1.light {\n",
" /* Specific color for light theme */\n",
" --sklearn-color-text-on-default-background: black;\n",
" --sklearn-color-background: white;\n",
" --sklearn-color-border-box: black;\n",
" --sklearn-color-icon: #696969;\n",
"}\n",
"\n",
"#sk-container-id-1.dark {\n",
" --sklearn-color-text-on-default-background: white;\n",
" --sklearn-color-background: #111;\n",
" --sklearn-color-border-box: white;\n",
" --sklearn-color-icon: #878787;\n",
"}\n",
"\n",
"#sk-container-id-1 {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"#sk-container-id-1 pre {\n",
" padding: 0;\n",
"}\n",
"\n",
"#sk-container-id-1 input.sk-hidden--visually {\n",
" border: 0;\n",
" clip: rect(1px 1px 1px 1px);\n",
" clip: rect(1px, 1px, 1px, 1px);\n",
" height: 1px;\n",
" margin: -1px;\n",
" overflow: hidden;\n",
" padding: 0;\n",
" position: absolute;\n",
" width: 1px;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-dashed-wrapped {\n",
" border: 1px dashed var(--sklearn-color-line);\n",
" margin: 0 0.4em 0.5em 0.4em;\n",
" box-sizing: border-box;\n",
" padding-bottom: 0.4em;\n",
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-container {\n",
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
" so we also need the `!important` here to be able to override the\n",
" default hidden behavior on the sphinx rendered scikit-learn.org.\n",
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
" display: inline-block !important;\n",
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-text-repr-fallback {\n",
" display: none;\n",
"}\n",
"\n",
"div.sk-parallel-item,\n",
"div.sk-serial,\n",
"div.sk-item {\n",
" /* draw centered vertical line to link estimators */\n",
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
" background-size: 2px 100%;\n",
" background-repeat: no-repeat;\n",
" background-position: center center;\n",
"}\n",
"\n",
"/* Parallel-specific style estimator block */\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item::after {\n",
" content: \"\";\n",
" width: 100%;\n",
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
" flex-grow: 1;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel {\n",
" display: flex;\n",
" align-items: stretch;\n",
" justify-content: center;\n",
" background-color: var(--sklearn-color-background);\n",
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item {\n",
" display: flex;\n",
" flex-direction: column;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
" align-self: flex-end;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
" align-self: flex-start;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
" width: 0;\n",
"}\n",
"\n",
"/* Serial-specific style estimator block */\n",
"\n",
"#sk-container-id-1 div.sk-serial {\n",
" display: flex;\n",
" flex-direction: column;\n",
" align-items: center;\n",
" background-color: var(--sklearn-color-background);\n",
" padding-right: 1em;\n",
" padding-left: 1em;\n",
"}\n",
"\n",
"\n",
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
"clickable and can be expanded/collapsed.\n",
"- Pipeline and ColumnTransformer use this feature and define the default style\n",
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
"*/\n",
"\n",
"/* Pipeline and ColumnTransformer style (default) */\n",
"\n",
"#sk-container-id-1 div.sk-toggleable {\n",
" /* Default theme specific background. It is overwritten whether we have a\n",
" specific estimator or a Pipeline/ColumnTransformer */\n",
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"/* Toggleable label */\n",
"#sk-container-id-1 label.sk-toggleable__label {\n",
" cursor: pointer;\n",
" display: flex;\n",
" width: 100%;\n",
" margin-bottom: 0;\n",
" padding: 0.5em;\n",
" box-sizing: border-box;\n",
" text-align: center;\n",
" align-items: center;\n",
" justify-content: center;\n",
" gap: 0.5em;\n",
"}\n",
"\n",
"#sk-container-id-1 label.sk-toggleable__label .caption {\n",
" font-size: 0.6rem;\n",
" font-weight: lighter;\n",
" color: var(--sklearn-color-text-muted);\n",
"}\n",
"\n",
"#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
" /* Arrow on the left of the label */\n",
" content: \"▸\";\n",
" float: left;\n",
" margin-right: 0.25em;\n",
" color: var(--sklearn-color-icon);\n",
"}\n",
"\n",
"#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"/* Toggleable content - dropdown */\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content {\n",
" display: none;\n",
" text-align: left;\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content pre {\n",
" margin: 0.2em;\n",
" border-radius: 0.25em;\n",
" color: var(--sklearn-color-text);\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
" /* Expand drop-down */\n",
" display: block;\n",
" width: 100%;\n",
" overflow: visible;\n",
"}\n",
"\n",
"#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
" content: \"▾\";\n",
"}\n",
"\n",
"/* Pipeline/ColumnTransformer-specific style */\n",
"\n",
"#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator-specific style */\n",
"\n",
"/* Colorize estimator box */\n",
"#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
"#sk-container-id-1 div.sk-label label {\n",
" /* The background is the default theme color */\n",
" color: var(--sklearn-color-text-on-default-background);\n",
"}\n",
"\n",
"/* On hover, darken the color of the background */\n",
"#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"/* Label box, darken color on hover, fitted */\n",
"#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator label */\n",
"\n",
"#sk-container-id-1 div.sk-label label {\n",
" font-family: monospace;\n",
" font-weight: bold;\n",
" line-height: 1.2em;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-label-container {\n",
" text-align: center;\n",
"}\n",
"\n",
"/* Estimator-specific */\n",
"#sk-container-id-1 div.sk-estimator {\n",
" font-family: monospace;\n",
" border: 1px dotted var(--sklearn-color-border-box);\n",
" border-radius: 0.25em;\n",
" box-sizing: border-box;\n",
" margin-bottom: 0.5em;\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-estimator.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"/* on hover */\n",
"#sk-container-id-1 div.sk-estimator:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
"\n",
"/* Common style for \"i\" and \"?\" */\n",
"\n",
".sk-estimator-doc-link,\n",
"a:link.sk-estimator-doc-link,\n",
"a:visited.sk-estimator-doc-link {\n",
" float: right;\n",
" font-size: smaller;\n",
" line-height: 1em;\n",
" font-family: monospace;\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
" border-radius: 1em;\n",
" height: 1em;\n",
" width: 1em;\n",
" text-decoration: none !important;\n",
" margin-left: 0.5em;\n",
" text-align: center;\n",
" /* unfitted */\n",
" border: var(--sklearn-color-unfitted-level-3) 1pt solid;\n",
" color: var(--sklearn-color-unfitted-level-3);\n",
"}\n",
"\n",
".sk-estimator-doc-link.fitted,\n",
"a:link.sk-estimator-doc-link.fitted,\n",
"a:visited.sk-estimator-doc-link.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
" border: var(--sklearn-color-fitted-level-3) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-3);\n",
"}\n",
"\n",
"/* On hover */\n",
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
".sk-estimator-doc-link:hover,\n",
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
".sk-estimator-doc-link:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-3);\n",
" border: var(--sklearn-color-fitted-level-0) 1pt solid;\n",
" color: var(--sklearn-color-unfitted-level-0);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
".sk-estimator-doc-link.fitted:hover,\n",
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
".sk-estimator-doc-link.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-3);\n",
" border: var(--sklearn-color-fitted-level-0) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-0);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"/* Span, style for the box shown on hovering the info icon */\n",
".sk-estimator-doc-link span {\n",
" display: none;\n",
" z-index: 9999;\n",
" position: relative;\n",
" font-weight: normal;\n",
" right: .2ex;\n",
" padding: .5ex;\n",
" margin: .5ex;\n",
" width: min-content;\n",
" min-width: 20ex;\n",
" max-width: 50ex;\n",
" color: var(--sklearn-color-text);\n",
" box-shadow: 2pt 2pt 4pt #999;\n",
" /* unfitted */\n",
" background: var(--sklearn-color-unfitted-level-0);\n",
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
"}\n",
"\n",
".sk-estimator-doc-link.fitted span {\n",
" /* fitted */\n",
" background: var(--sklearn-color-fitted-level-0);\n",
" border: var(--sklearn-color-fitted-level-3);\n",
"}\n",
"\n",
".sk-estimator-doc-link:hover span {\n",
" display: block;\n",
"}\n",
"\n",
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
"\n",
"#sk-container-id-1 a.estimator_doc_link {\n",
" float: right;\n",
" font-size: 1rem;\n",
" line-height: 1em;\n",
" font-family: monospace;\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
" border-radius: 1rem;\n",
" height: 1rem;\n",
" width: 1rem;\n",
" text-decoration: none;\n",
" /* unfitted */\n",
" color: var(--sklearn-color-unfitted-level-1);\n",
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
"}\n",
"\n",
"#sk-container-id-1 a.estimator_doc_link.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-1);\n",
"}\n",
"\n",
"/* On hover */\n",
"#sk-container-id-1 a.estimator_doc_link:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-3);\n",
" color: var(--sklearn-color-background);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-3);\n",
"}\n",
"\n",
".estimator-table {\n",
" font-family: monospace;\n",
"}\n",
"\n",
".estimator-table summary {\n",
" padding: .5rem;\n",
" cursor: pointer;\n",
"}\n",
"\n",
".estimator-table summary::marker {\n",
" font-size: 0.7rem;\n",
"}\n",
"\n",
".estimator-table details[open] {\n",
" padding-left: 0.1rem;\n",
" padding-right: 0.1rem;\n",
" padding-bottom: 0.3rem;\n",
"}\n",
"\n",
".estimator-table .parameters-table {\n",
" margin-left: auto !important;\n",
" margin-right: auto !important;\n",
" margin-top: 0;\n",
"}\n",
"\n",
".estimator-table .parameters-table tr:nth-child(odd) {\n",
" background-color: #fff;\n",
"}\n",
"\n",
".estimator-table .parameters-table tr:nth-child(even) {\n",
" background-color: #f6f6f6;\n",
"}\n",
"\n",
".estimator-table .parameters-table tr:hover {\n",
" background-color: #e0e0e0;\n",
"}\n",
"\n",
".estimator-table table td {\n",
" border: 1px solid rgba(106, 105, 104, 0.232);\n",
"}\n",
"\n",
"/*\n",
" `table td`is set in notebook with right text-align.\n",
" We need to overwrite it.\n",
"*/\n",
".estimator-table table td.param {\n",
" text-align: left;\n",
" position: relative;\n",
" padding: 0;\n",
"}\n",
"\n",
".user-set td {\n",
" color:rgb(255, 94, 0);\n",
" text-align: left !important;\n",
"}\n",
"\n",
".user-set td.value {\n",
" color:rgb(255, 94, 0);\n",
" background-color: transparent;\n",
"}\n",
"\n",
".default td {\n",
" color: black;\n",
" text-align: left !important;\n",
"}\n",
"\n",
".user-set td i,\n",
".default td i {\n",
" color: black;\n",
"}\n",
"\n",
"/*\n",
" Styles for parameter documentation links\n",
" We need styling for visited so jupyter doesn't overwrite it\n",
"*/\n",
"a.param-doc-link,\n",
"a.param-doc-link:link,\n",
"a.param-doc-link:visited {\n",
" text-decoration: underline dashed;\n",
" text-underline-offset: .3em;\n",
" color: inherit;\n",
" display: block;\n",
" padding: .5em;\n",
"}\n",
"\n",
"/* \"hack\" to make the entire area of the cell containing the link clickable */\n",
"a.param-doc-link::before {\n",
" position: absolute;\n",
" content: \"\";\n",
" inset: 0;\n",
"}\n",
"\n",
".param-doc-description {\n",
" display: none;\n",
" position: absolute;\n",
" z-index: 9999;\n",
" left: 0;\n",
" padding: .5ex;\n",
" margin-left: 1.5em;\n",
" color: var(--sklearn-color-text);\n",
" box-shadow: .3em .3em .4em #999;\n",
" width: max-content;\n",
" text-align: left;\n",
" max-height: 10em;\n",
" overflow-y: auto;\n",
"\n",
" /* unfitted */\n",
" background: var(--sklearn-color-unfitted-level-0);\n",
" border: thin solid var(--sklearn-color-unfitted-level-3);\n",
"}\n",
"\n",
"/* Fitted state for parameter tooltips */\n",
".fitted .param-doc-description {\n",
" /* fitted */\n",
" background: var(--sklearn-color-fitted-level-0);\n",
" border: thin solid var(--sklearn-color-fitted-level-3);\n",
"}\n",
"\n",
".param-doc-link:hover .param-doc-description {\n",
" display: block;\n",
"}\n",
"\n",
".copy-paste-icon {\n",
" background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);\n",
" background-repeat: no-repeat;\n",
" background-size: 14px 14px;\n",
" background-position: 0;\n",
" display: inline-block;\n",
" width: 14px;\n",
" height: 14px;\n",
" cursor: pointer;\n",
"}\n",
"</style><body><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>MLPClassifier(hidden_layer_sizes=(64, 32), max_iter=300, random_state=42)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>MLPClassifier</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html\">?<span>Documentation for MLPClassifier</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\" data-param-prefix=\"\">\n",
" <div class=\"estimator-table\">\n",
" <details>\n",
" <summary>Parameters</summary>\n",
" <table class=\"parameters-table\">\n",
" <tbody>\n",
" \n",
" <tr class=\"user-set\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('hidden_layer_sizes',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=hidden_layer_sizes,-array-like%20of%20shape%28n_layers%20-%202%2C%29%2C%20default%3D%28100%2C%29\">\n",
" hidden_layer_sizes\n",
" <span class=\"param-doc-description\">hidden_layer_sizes: array-like of shape(n_layers - 2,), default=(100,)<br><br>The ith element represents the number of neurons in the ith<br>hidden layer.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">(64, ...)</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('activation',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=activation,-%7B%27identity%27%2C%20%27logistic%27%2C%20%27tanh%27%2C%20%27relu%27%7D%2C%20default%3D%27relu%27\">\n",
" activation\n",
" <span class=\"param-doc-description\">activation: {'identity', 'logistic', 'tanh', 'relu'}, default='relu'<br><br>Activation function for the hidden layer.<br><br>- 'identity', no-op activation, useful to implement linear bottleneck,<br> returns f(x) = x<br><br>- 'logistic', the logistic sigmoid function,<br> returns f(x) = 1 / (1 + exp(-x)).<br><br>- 'tanh', the hyperbolic tan function,<br> returns f(x) = tanh(x).<br><br>- 'relu', the rectified linear unit function,<br> returns f(x) = max(0, x)</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">&#x27;relu&#x27;</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('solver',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27sgd%27%2C%20%27adam%27%7D%2C%20default%3D%27adam%27\">\n",
" solver\n",
" <span class=\"param-doc-description\">solver: {'lbfgs', 'sgd', 'adam'}, default='adam'<br><br>The solver for weight optimization.<br><br>- 'lbfgs' is an optimizer in the family of quasi-Newton methods.<br><br>- 'sgd' refers to stochastic gradient descent.<br><br>- 'adam' refers to a stochastic gradient-based optimizer proposed<br> by Kingma, Diederik, and Jimmy Ba<br><br>For a comparison between Adam optimizer and SGD, see<br>:ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_training_curves.py`.<br><br>Note: The default solver 'adam' works pretty well on relatively<br>large datasets (with thousands of training samples or more) in terms of<br>both training time and validation score.<br>For small datasets, however, 'lbfgs' can converge faster and perform<br>better.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">&#x27;adam&#x27;</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('alpha',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=alpha,-float%2C%20default%3D0.0001\">\n",
" alpha\n",
" <span class=\"param-doc-description\">alpha: float, default=0.0001<br><br>Strength of the L2 regularization term. The L2 regularization term<br>is divided by the sample size when added to the loss.<br><br>For an example usage and visualization of varying regularization, see<br>:ref:`sphx_glr_auto_examples_neural_networks_plot_mlp_alpha.py`.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.0001</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('batch_size',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=batch_size,-int%2C%20default%3D%27auto%27\">\n",
" batch_size\n",
" <span class=\"param-doc-description\">batch_size: int, default='auto'<br><br>Size of minibatches for stochastic optimizers.<br>If the solver is 'lbfgs', the classifier will not use minibatch.<br>When set to \"auto\", `batch_size=min(200, n_samples)`.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">&#x27;auto&#x27;</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('learning_rate',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=learning_rate,-%7B%27constant%27%2C%20%27invscaling%27%2C%20%27adaptive%27%7D%2C%20default%3D%27constant%27\">\n",
" learning_rate\n",
" <span class=\"param-doc-description\">learning_rate: {'constant', 'invscaling', 'adaptive'}, default='constant'<br><br>Learning rate schedule for weight updates.<br><br>- 'constant' is a constant learning rate given by<br> 'learning_rate_init'.<br><br>- 'invscaling' gradually decreases the learning rate at each<br> time step 't' using an inverse scaling exponent of 'power_t'.<br> effective_learning_rate = learning_rate_init / pow(t, power_t)<br><br>- 'adaptive' keeps the learning rate constant to<br> 'learning_rate_init' as long as training loss keeps decreasing.<br> Each time two consecutive epochs fail to decrease training loss by at<br> least tol, or fail to increase validation score by at least tol if<br> 'early_stopping' is on, the current learning rate is divided by 5.<br><br>Only used when ``solver='sgd'``.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">&#x27;constant&#x27;</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('learning_rate_init',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=learning_rate_init,-float%2C%20default%3D0.001\">\n",
" learning_rate_init\n",
" <span class=\"param-doc-description\">learning_rate_init: float, default=0.001<br><br>The initial learning rate used. It controls the step-size<br>in updating the weights. Only used when solver='sgd' or 'adam'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.001</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('power_t',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=power_t,-float%2C%20default%3D0.5\">\n",
" power_t\n",
" <span class=\"param-doc-description\">power_t: float, default=0.5<br><br>The exponent for inverse scaling learning rate.<br>It is used in updating effective learning rate when the learning_rate<br>is set to 'invscaling'. Only used when solver='sgd'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.5</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"user-set\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('max_iter',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=max_iter,-int%2C%20default%3D200\">\n",
" max_iter\n",
" <span class=\"param-doc-description\">max_iter: int, default=200<br><br>Maximum number of iterations. The solver iterates until convergence<br>(determined by 'tol') or this number of iterations. For stochastic<br>solvers ('sgd', 'adam'), note that this determines the number of epochs<br>(how many times each data point will be used), not the number of<br>gradient steps.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">300</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('shuffle',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=shuffle,-bool%2C%20default%3DTrue\">\n",
" shuffle\n",
" <span class=\"param-doc-description\">shuffle: bool, default=True<br><br>Whether to shuffle samples in each iteration. Only used when<br>solver='sgd' or 'adam'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">True</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"user-set\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('random_state',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone\">\n",
" random_state\n",
" <span class=\"param-doc-description\">random_state: int, RandomState instance, default=None<br><br>Determines random number generation for weights and bias<br>initialization, train-test split if early stopping is used, and batch<br>sampling when solver='sgd' or 'adam'.<br>Pass an int for reproducible results across multiple function calls.<br>See :term:`Glossary <random_state>`.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">42</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('tol',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=tol,-float%2C%20default%3D1e-4\">\n",
" tol\n",
" <span class=\"param-doc-description\">tol: float, default=1e-4<br><br>Tolerance for the optimization. When the loss or score is not improving<br>by at least ``tol`` for ``n_iter_no_change`` consecutive iterations,<br>unless ``learning_rate`` is set to 'adaptive', convergence is<br>considered to be reached and training stops.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.0001</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('verbose',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=verbose,-bool%2C%20default%3DFalse\">\n",
" verbose\n",
" <span class=\"param-doc-description\">verbose: bool, default=False<br><br>Whether to print progress messages to stdout.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">False</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('warm_start',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=warm_start,-bool%2C%20default%3DFalse\">\n",
" warm_start\n",
" <span class=\"param-doc-description\">warm_start: bool, default=False<br><br>When set to True, reuse the solution of the previous<br>call to fit as initialization, otherwise, just erase the<br>previous solution. See :term:`the Glossary <warm_start>`.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">False</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('momentum',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=momentum,-float%2C%20default%3D0.9\">\n",
" momentum\n",
" <span class=\"param-doc-description\">momentum: float, default=0.9<br><br>Momentum for gradient descent update. Should be between 0 and 1. Only<br>used when solver='sgd'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.9</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('nesterovs_momentum',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=nesterovs_momentum,-bool%2C%20default%3DTrue\">\n",
" nesterovs_momentum\n",
" <span class=\"param-doc-description\">nesterovs_momentum: bool, default=True<br><br>Whether to use Nesterov's momentum. Only used when solver='sgd' and<br>momentum > 0.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">True</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('early_stopping',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=early_stopping,-bool%2C%20default%3DFalse\">\n",
" early_stopping\n",
" <span class=\"param-doc-description\">early_stopping: bool, default=False<br><br>Whether to use early stopping to terminate training when validation<br>score is not improving. If set to True, it will automatically set<br>aside ``validation_fraction`` of training data as validation and<br>terminate training when validation score is not improving by at least<br>``tol`` for ``n_iter_no_change`` consecutive epochs. The split is<br>stratified, except in a multilabel setting.<br>If early stopping is False, then the training stops when the training<br>loss does not improve by more than ``tol`` for ``n_iter_no_change``<br>consecutive passes over the training set.<br>Only effective when solver='sgd' or 'adam'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">False</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('validation_fraction',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=validation_fraction,-float%2C%20default%3D0.1\">\n",
" validation_fraction\n",
" <span class=\"param-doc-description\">validation_fraction: float, default=0.1<br><br>The proportion of training data to set aside as validation set for<br>early stopping. Must be between 0 and 1.<br>Only used if early_stopping is True.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.1</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('beta_1',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=beta_1,-float%2C%20default%3D0.9\">\n",
" beta_1\n",
" <span class=\"param-doc-description\">beta_1: float, default=0.9<br><br>Exponential decay rate for estimates of first moment vector in adam,<br>should be in [0, 1). Only used when solver='adam'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.9</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('beta_2',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=beta_2,-float%2C%20default%3D0.999\">\n",
" beta_2\n",
" <span class=\"param-doc-description\">beta_2: float, default=0.999<br><br>Exponential decay rate for estimates of second moment vector in adam,<br>should be in [0, 1). Only used when solver='adam'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">0.999</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('epsilon',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=epsilon,-float%2C%20default%3D1e-8\">\n",
" epsilon\n",
" <span class=\"param-doc-description\">epsilon: float, default=1e-8<br><br>Value for numerical stability in adam. Only used when solver='adam'.</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">1e-08</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('n_iter_no_change',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=n_iter_no_change,-int%2C%20default%3D10\">\n",
" n_iter_no_change\n",
" <span class=\"param-doc-description\">n_iter_no_change: int, default=10<br><br>Maximum number of epochs to not meet ``tol`` improvement.<br>Only effective when solver='sgd' or 'adam'.<br><br>.. versionadded:: 0.20</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">10</td>\n",
" </tr>\n",
" \n",
"\n",
" <tr class=\"default\">\n",
" <td><i class=\"copy-paste-icon\"\n",
" onclick=\"copyToClipboard('max_fun',\n",
" this.parentElement.nextElementSibling)\"\n",
" ></i></td>\n",
" <td class=\"param\">\n",
" <a class=\"param-doc-link\"\n",
" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.8/modules/generated/sklearn.neural_network.MLPClassifier.html#:~:text=max_fun,-int%2C%20default%3D15000\">\n",
" max_fun\n",
" <span class=\"param-doc-description\">max_fun: int, default=15000<br><br>Only used when solver='lbfgs'. Maximum number of loss function calls.<br>The solver iterates until convergence (determined by 'tol'), number<br>of iterations reaches max_iter, or this number of loss function calls.<br>Note that number of loss function calls will be greater than or equal<br>to the number of iterations for the `MLPClassifier`.<br><br>.. versionadded:: 0.22</span>\n",
" </a>\n",
" </td>\n",
" <td class=\"value\">15000</td>\n",
" </tr>\n",
" \n",
" </tbody>\n",
" </table>\n",
" </details>\n",
" </div>\n",
" </div></div></div></div></div><script>function copyToClipboard(text, element) {\n",
" // Get the parameter prefix from the closest toggleable content\n",
" const toggleableContent = element.closest('.sk-toggleable__content');\n",
" const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
" const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;\n",
"\n",
" const originalStyle = element.style;\n",
" const computedStyle = window.getComputedStyle(element);\n",
" const originalWidth = computedStyle.width;\n",
" const originalHTML = element.innerHTML.replace('Copied!', '');\n",
"\n",
" navigator.clipboard.writeText(fullParamName)\n",
" .then(() => {\n",
" element.style.width = originalWidth;\n",
" element.style.color = 'green';\n",
" element.innerHTML = \"Copied!\";\n",
"\n",
" setTimeout(() => {\n",
" element.innerHTML = originalHTML;\n",
" element.style = originalStyle;\n",
" }, 2000);\n",
" })\n",
" .catch(err => {\n",
" console.error('Failed to copy:', err);\n",
" element.style.color = 'red';\n",
" element.innerHTML = \"Failed!\";\n",
" setTimeout(() => {\n",
" element.innerHTML = originalHTML;\n",
" element.style = originalStyle;\n",
" }, 2000);\n",
" });\n",
" return false;\n",
"}\n",
"\n",
"document.querySelectorAll('.copy-paste-icon').forEach(function(element) {\n",
" const toggleableContent = element.closest('.sk-toggleable__content');\n",
" const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
" const paramName = element.parentElement.nextElementSibling\n",
" .textContent.trim().split(' ')[0];\n",
" const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;\n",
"\n",
" element.setAttribute('title', fullParamName);\n",
"});\n",
"\n",
"\n",
"/**\n",
" * Adapted from Skrub\n",
" * https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/skrub/_reporting/_data/templates/report.js#L789\n",
" * @returns \"light\" or \"dark\"\n",
" */\n",
"function detectTheme(element) {\n",
" const body = document.querySelector('body');\n",
"\n",
" // Check VSCode theme\n",
" const themeKindAttr = body.getAttribute('data-vscode-theme-kind');\n",
" const themeNameAttr = body.getAttribute('data-vscode-theme-name');\n",
"\n",
" if (themeKindAttr && themeNameAttr) {\n",
" const themeKind = themeKindAttr.toLowerCase();\n",
" const themeName = themeNameAttr.toLowerCase();\n",
"\n",
" if (themeKind.includes(\"dark\") || themeName.includes(\"dark\")) {\n",
" return \"dark\";\n",
" }\n",
" if (themeKind.includes(\"light\") || themeName.includes(\"light\")) {\n",
" return \"light\";\n",
" }\n",
" }\n",
"\n",
" // Check Jupyter theme\n",
" if (body.getAttribute('data-jp-theme-light') === 'false') {\n",
" return 'dark';\n",
" } else if (body.getAttribute('data-jp-theme-light') === 'true') {\n",
" return 'light';\n",
" }\n",
"\n",
" // Guess based on a parent element's color\n",
" const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color');\n",
" const match = color.match(/^rgb\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/i);\n",
" if (match) {\n",
" const [r, g, b] = [\n",
" parseFloat(match[1]),\n",
" parseFloat(match[2]),\n",
" parseFloat(match[3])\n",
" ];\n",
"\n",
" // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness\n",
" const luma = 0.299 * r + 0.587 * g + 0.114 * b;\n",
"\n",
" if (luma > 180) {\n",
" // If the text is very bright we have a dark theme\n",
" return 'dark';\n",
" }\n",
" if (luma < 75) {\n",
" // If the text is very dark we have a light theme\n",
" return 'light';\n",
" }\n",
" // Otherwise fall back to the next heuristic.\n",
" }\n",
"\n",
" // Fallback to system preference\n",
" return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n",
"}\n",
"\n",
"\n",
"function forceTheme(elementId) {\n",
" const estimatorElement = document.querySelector(`#${elementId}`);\n",
" if (estimatorElement === null) {\n",
" console.error(`Element with id ${elementId} not found.`);\n",
" } else {\n",
" const theme = detectTheme(estimatorElement);\n",
" estimatorElement.classList.add(theme);\n",
" }\n",
"}\n",
"\n",
"forceTheme('sk-container-id-1');</script></body>"
],
"text/plain": [
"MLPClassifier(hidden_layer_sizes=(64, 32), max_iter=300, random_state=42)"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Train model 1 on generated data\n",
"mlp_model_1.fit(X_train, y_train)"
]
},
{
"cell_type": "markdown",
"id": "600e90f1-fc12-4300-ab60-76b4656bf5d8",
"metadata": {},
"source": [
"# Run the validation data through the ML model."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "4d08a5ac-93cf-4da5-a266-7052ea31ac6a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['low', 'high', 'high', 'moderate', 'low', 'high', 'high', 'high',\n",
" 'low', 'low'], dtype='<U8')"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Run validation data through the trained model\n",
"y_val_pred_1 = mlp_model_1.predict(X_val)\n",
"y_val_proba_1 = mlp_model_1.predict_proba(X_val)\n",
"\n",
"\n",
"# This script outputs nothing by default, so adding a line to display the first ten lines as evidence.\n",
"y_val_pred_1[:10]"
]
},
{
"cell_type": "markdown",
"id": "ef0f7e01-0fe2-4c66-86eb-734d59280e85",
"metadata": {},
"source": [
"# Metrics Calculation (Accuracy, ROC-AUC & Confusion matrix) - Rayyan Hodges"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "b6521a2a-d843-4788-854b-a025ba5f234c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.6216216216216216"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calculating accuracy\n",
"\n",
"from sklearn.metrics import accuracy_score\n",
"\n",
"accuracy_1 = accuracy_score(y_val, y_val_pred_1)\n",
"accuracy_1\n"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "a1c05820-0b69-4c8f-bfdd-5c51607c6b58",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.8328379028379028"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calculating ROC‑AUC (multi‑class)\n",
"\n",
"from sklearn.metrics import roc_auc_score\n",
"\n",
"roc_auc_1 = roc_auc_score(\n",
" y_val,\n",
" y_val_proba_1,\n",
" multi_class='ovr'\n",
")\n",
"roc_auc_1\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "99e73c34-5650-42cc-9ed2-36a1f2fb044c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[35, 1, 13],\n",
" [ 1, 40, 8],\n",
" [14, 19, 17]])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Calculating confusion matrix\n",
"\n",
"from sklearn.metrics import confusion_matrix\n",
"\n",
"conf_matrix_1 = confusion_matrix(y_val, y_val_pred_1)\n",
"conf_matrix_1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}