tahamajs/ML / Files /machine_learning_ /Project /codes /Classification.ipynb
tahamajs's picture
download
raw
115 kB
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# Import Libraries\n",
"\n"
],
"metadata": {
"id": "gq6xsMEotO3X"
}
},
{
"cell_type": "code",
"source": [
"!pip install lazypredict\n",
"!pip install h2o\n",
"!pip install hdbscan"
],
"metadata": {
"id": "89wFPluq_nOw"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import os\n",
"import cv2\n",
"import random\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from skimage import feature\n",
"from sklearn.preprocessing import LabelEncoder\n",
"from sklearn.svm import SVC\n",
"from sklearn.metrics import accuracy_score, confusion_matrix\n",
"from sklearn.model_selection import train_test_split,cross_val_score\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from sklearn.impute import SimpleImputer\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.cluster import KMeans\n",
"from sklearn.mixture import BayesianGaussianMixture\n",
"from sklearn.metrics import classification_report,confusion_matrix,accuracy_score, precision_score, recall_score, f1_score\n",
"from sklearn.preprocessing import LabelEncoder\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.neighbors import KNeighborsClassifier\n",
"from sklearn.svm import SVC\n",
"from sklearn.naive_bayes import GaussianNB\n",
"from sklearn.pipeline import Pipeline\n",
"from sklearn.model_selection import GridSearchCV\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.metrics.pairwise import pairwise_distances\n",
"from sklearn.neighbors import kneighbors_graph\n",
"from sklearn.decomposition import PCA\n",
"from sklearn.cluster import SpectralClustering\n",
"from sklearn.metrics import silhouette_score\n",
"from sklearn.model_selection import ParameterGrid\n",
"import h2o\n",
"from h2o.automl import H2OAutoML\n",
"import random\n",
"from imblearn.over_sampling import SMOTE\n",
"from tqdm import tqdm\n",
"import lightgbm as lgb\n",
"import time\n",
"from skimage.feature import graycomatrix, graycoprops\n",
"from lazypredict.Supervised import LazyClassifier"
],
"metadata": {
"id": "9HTeRoQ3zziR"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"cd '/content/drive/MyDrive/ML/final_project2'"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5vqOOfICfA1H",
"outputId": "790dde89-c971-46da-947a-b8d093fe4924"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"/content/drive/MyDrive/ML/final_project2\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Classification"
],
"metadata": {
"id": "G8dEIq1lFazb"
}
},
{
"cell_type": "markdown",
"source": [
"### classification"
],
"metadata": {
"id": "sXkP4CsIKN1l"
}
},
{
"cell_type": "code",
"source": [
"def preprocess_dataframe(df):\n",
" # Copy the original dataframe to avoid modifying the original data\n",
" preprocessed_df = df.copy()\n",
"\n",
" # Normalize the last column using Min-Max scaling\n",
" scaler = MinMaxScaler()\n",
" preprocessed_df.iloc[:, -1:] = scaler.fit_transform(preprocessed_df.iloc[:, -1:])\n",
"\n",
"\n",
" return preprocessed_df"
],
"metadata": {
"id": "csZ9WY3jUDRD"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"train_df = pd.read_csv('image_features_train5_64_64_normalized_.csv')\n",
"test_df = pd.read_csv('image_features_test5_64_64_normalized_.csv')"
],
"metadata": {
"id": "Y6hAogpBmeGQ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Separate the features (X) and the labels (y) in the train dataframe\n",
"X_train = train_df.iloc[:, :-1] # All columns except the last one\n",
"y_train = train_df.iloc[:, -1] # Last column\n",
"\n",
"# Separate the features (X) and the labels (y) in the test dataframe\n",
"X_test = test_df.iloc[:, :-1] # All columns except the last one\n",
"y_test = test_df.iloc[:, -1] # Last column"
],
"metadata": {
"id": "hPP5Kv-u6Hx3"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"**SVM-Kernel Linear**"
],
"metadata": {
"id": "nsXsIvRy5uLn"
}
},
{
"cell_type": "code",
"source": [
"# Train the SVM model\n",
"svm_model = SVC(kernel='linear', random_state=42)\n",
"svm_model.fit(X_train, y_train)\n",
"\n",
"# Predict the labels for training and testing sets\n",
"y_train_pred = svm_model.predict(X_train)\n",
"y_test_pred = svm_model.predict(X_test)\n",
"\n",
"# Calculate the accuracy of the model\n",
"train_accuracy = accuracy_score(y_train, y_train_pred)\n",
"test_accuracy = accuracy_score(y_test, y_test_pred)\n",
"\n",
"# Print the accuracy of the model\n",
"print(f\"Training Accuracy: {train_accuracy}\")\n",
"print(f\"Testing Accuracy: {test_accuracy}\")\n",
"\n",
"# Calculate the confusion matrix for the testing set\n",
"confusion_matrix_test = confusion_matrix(y_test, y_test_pred)\n",
"print(\"Confusion Matrix (Testing Set):\")\n",
"print(confusion_matrix_test)"
],
"metadata": {
"id": "sXPyUEjMFfEh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"**SVM-Kernel RBF**"
],
"metadata": {
"id": "JY8av7916PU_"
}
},
{
"cell_type": "code",
"source": [
"# Train the SVM model\n",
"svm_model = SVC(kernel='rbf', random_state=42)\n",
"svm_model.fit(X_train, y_train)\n",
"\n",
"# Predict the labels for training and testing sets\n",
"y_train_pred = svm_model.predict(X_train)\n",
"y_test_pred = svm_model.predict(X_test)\n",
"\n",
"# Calculate the accuracy of the model\n",
"train_accuracy = accuracy_score(y_train, y_train_pred)\n",
"test_accuracy = accuracy_score(y_test, y_test_pred)\n",
"\n",
"# Print the accuracy of the model\n",
"print(f\"Training Accuracy: {train_accuracy}\")\n",
"print(f\"Testing Accuracy: {test_accuracy}\")\n",
"\n",
"# Calculate the confusion matrix for the testing set\n",
"confusion_matrix_test = confusion_matrix(y_test, y_test_pred)\n",
"print(\"Confusion Matrix (Testing Set):\")\n",
"print(confusion_matrix_test)"
],
"metadata": {
"id": "gktctznxHuZh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"**Random Forrest**"
],
"metadata": {
"id": "l-7MU1Wc6SWH"
}
},
{
"cell_type": "code",
"source": [
"# Train the Random Forest model\n",
"rf_model = RandomForestClassifier(random_state=42)\n",
"rf_model.fit(X_train, y_train)\n",
"\n",
"# Predict the labels for training and testing sets\n",
"y_train_pred = rf_model.predict(X_train)\n",
"y_test_pred = rf_model.predict(X_test)\n",
"\n",
"# Calculate the accuracy of the model on the training set\n",
"train_accuracy = accuracy_score(y_train, y_train_pred)\n",
"print(f\"Training Accuracy: {train_accuracy}\")\n",
"\n",
"# Calculate the accuracy of the model on the testing set\n",
"test_accuracy = accuracy_score(y_test, y_test_pred)\n",
"print(f\"Testing Accuracy: {test_accuracy}\")\n",
"\n",
"# Calculate the confusion matrix for the testing set\n",
"confusion_matrix_test = confusion_matrix(y_test, y_test_pred)\n",
"print(\"Confusion Matrix (Testing Set):\")\n",
"print(confusion_matrix_test)"
],
"metadata": {
"id": "Vcgv7fRXLFqS"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### Classification on 29 Classification model\n",
"In this part we use lazy-predict package"
],
"metadata": {
"id": "o0BoTHRn6XUv"
}
},
{
"cell_type": "markdown",
"source": [
"**Our Features**"
],
"metadata": {
"id": "WVG1stPy689o"
}
},
{
"cell_type": "code",
"source": [
"train_df = pd.read_csv('image_features_train5_64_64_normalized_.csv')\n",
"test_df = pd.read_csv('image_features_test5_64_64_normalized_.csv')"
],
"metadata": {
"id": "YpzNcLofT7uN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# Assuming you have train_df and test_df as your train and test DataFrames\n",
"\n",
"# Separate the features (X) and the labels (y) in the train dataframe\n",
"X_train = train_df.iloc[:, :-1] # All columns except the last one\n",
"y_train = train_df.iloc[:, -1] # Last column\n",
"\n",
"# Separate the features (X) and the labels (y) in the test dataframe\n",
"X_test = test_df.iloc[:, :-1] # All columns except the last one\n",
"y_test = test_df.iloc[:, -1] # Last column\n",
"\n",
"# Split the train dataset into train and validation sets (optional)\n",
"X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n",
"\n",
"# Initialize the LazyClassifier\n",
"clf = LazyClassifier(verbose=0, ignore_warnings=True, custom_metric=None)\n",
"\n",
"# Fit and predict using multiple classifiers\n",
"models, predictions = clf.fit(X_train, X_val, y_train, y_val)\n",
"\n",
"# Compare the performance of the models\n",
"print(models)\n",
"\n",
"# Evaluate the accuracy of the best model on the test set\n",
"best_model = models[0]\n",
"y_pred = best_model.predict(X_test)\n",
"accuracy = accuracy_score(y_test, y_pred)\n",
"print(\"Accuracy:\", accuracy)\n"
],
"metadata": {
"id": "xeD1rxcaU1Ir"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Classification with H2O.ai"
],
"metadata": {
"id": "in--S7zkKFnl"
}
},
{
"cell_type": "code",
"source": [
"df = pd.read_csv('image_features_train5_64_64.csv')\n",
"df_ = preprocess_dataframe(df)\n",
"df_.to_csv('image_features_train5_64_64_normalized_.csv')"
],
"metadata": {
"id": "giJEkLVsP3Ie"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df = pd.read_csv('image_features_val5_64_64.csv')\n",
"df_ = preprocess_dataframe(df)\n",
"df_.to_csv('image_features_val5_64_64_normalized_.csv')"
],
"metadata": {
"id": "OsmtgXOOQJaN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df = pd.read_csv('image_features_test5_64_64.csv')\n",
"df_ = preprocess_dataframe(df)\n",
"df_.to_csv('image_features_test5_64_64_normalized_.csv')"
],
"metadata": {
"id": "19Xz1hH6QN5p"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "Hqf7jOMeP283"
}
},
{
"cell_type": "code",
"source": [
"\n",
"def select_best_classification_model(train, validation, test, max_runtime_sec=300, max_models=None, nfolds=0):\n",
"\n",
" # Start H2O cluster\n",
" h2o.init()\n",
"\n",
" # Convert dataframes to H2O frames\n",
" train_h2o = h2o.H2OFrame(train)\n",
" validation_h2o = h2o.H2OFrame(validation)\n",
" test_h2o = h2o.H2OFrame(test)\n",
"\n",
" # Set the last column as the label\n",
" label_index = train_h2o.ncols - 1\n",
" train_h2o[label_index] = train_h2o[label_index].asfactor()\n",
" validation_h2o[label_index] = validation_h2o[label_index].asfactor()\n",
" test_h2o[label_index] = test_h2o[label_index].asfactor()\n",
"\n",
"\n",
" # Train H2O AutoML\n",
" if max_models:\n",
" aml = H2OAutoML(max_models=max_models, seed=1, nfolds=nfolds, exclude_algos=[\"DeepLearning\"])\n",
" else:\n",
" aml = H2OAutoML(max_runtime_secs=max_runtime_sec, seed=1, nfolds=nfolds, exclude_algos=[\"DeepLearning\"])\n",
" aml.train(x=train_h2o.columns[:-1], y=train_h2o.columns[label_index], training_frame=train_h2o, validation_frame=validation_h2o)\n",
"\n",
" # Get the best model\n",
" best_model = aml.leader\n",
"\n",
" # Print the accuracy on train, validation, and test data\n",
" train_accuracy = best_model.model_performance(train_h2o).accuracy()\n",
" validation_accuracy = best_model.model_performance(validation_h2o).accuracy()\n",
" test_accuracy = best_model.model_performance(test_h2o).accuracy()\n",
" print(f\"Train Accuracy: {train_accuracy}\")\n",
" print(f\"Validation Accuracy: {validation_accuracy}\")\n",
" print(f\"Test Accuracy: {test_accuracy}\")\n",
"\n",
" return best_model\n"
],
"metadata": {
"id": "x-i-VJDvMUic"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"train_df = pd.read_csv('image_features_train5_64_64.csv')\n",
"validation_df = pd.read_csv('image_features_val5_64_64.csv')\n",
"test_df = pd.read_csv('image_features_test5_64_64.csv')"
],
"metadata": {
"id": "fP5l05lFMYSl"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"train_df['Label']"
],
"metadata": {
"id": "OfGNbUKbK1Zk"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"best_model = select_best_classification_model(train_df, validation_df, test_df, max_runtime_sec=300)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "1nQp7nu8MZgt",
"outputId": "23d570c4-dc09-4a02-8298-6805942de04b"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Checking whether there is an H2O instance running at http://localhost:54321..... not found.\n",
"Attempting to start a local H2O server...\n",
" Java Version: openjdk version \"11.0.19\" 2023-04-18; OpenJDK Runtime Environment (build 11.0.19+7-post-Ubuntu-0ubuntu120.04.1); OpenJDK 64-Bit Server VM (build 11.0.19+7-post-Ubuntu-0ubuntu120.04.1, mixed mode, sharing)\n",
" Starting server from /usr/local/lib/python3.10/dist-packages/h2o/backend/bin/h2o.jar\n",
" Ice root: /tmp/tmpqjn7qi5l\n",
" JVM stdout: /tmp/tmpqjn7qi5l/h2o_unknownUser_started_from_python.out\n",
" JVM stderr: /tmp/tmpqjn7qi5l/h2o_unknownUser_started_from_python.err\n",
" Server is running at http://127.0.0.1:54321\n",
"Connecting to H2O server at http://127.0.0.1:54321 ... successful.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"-------------------------- -----------------------------------------------------------------------------------------\n",
"H2O_cluster_uptime: 05 secs\n",
"H2O_cluster_timezone: Etc/UTC\n",
"H2O_data_parsing_timezone: UTC\n",
"H2O_cluster_version: 3.40.0.4\n",
"H2O_cluster_version_age: 2 months and 5 days\n",
"H2O_cluster_name: H2O_from_python_unknownUser_84nhlb\n",
"H2O_cluster_total_nodes: 1\n",
"H2O_cluster_free_memory: 3.170 Gb\n",
"H2O_cluster_total_cores: 2\n",
"H2O_cluster_allowed_cores: 2\n",
"H2O_cluster_status: locked, healthy\n",
"H2O_connection_url: http://127.0.0.1:54321\n",
"H2O_connection_proxy: {\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}\n",
"H2O_internal_security: False\n",
"Python_version: 3.10.12 final\n",
"-------------------------- -----------------------------------------------------------------------------------------"
],
"text/html": [
"\n",
"<style>\n",
"\n",
"#h2o-table-1.h2o-container {\n",
" overflow-x: auto;\n",
"}\n",
"#h2o-table-1 .h2o-table {\n",
" /* width: 100%; */\n",
" margin-top: 1em;\n",
" margin-bottom: 1em;\n",
"}\n",
"#h2o-table-1 .h2o-table caption {\n",
" white-space: nowrap;\n",
" caption-side: top;\n",
" text-align: left;\n",
" /* margin-left: 1em; */\n",
" margin: 0;\n",
" font-size: larger;\n",
"}\n",
"#h2o-table-1 .h2o-table thead {\n",
" white-space: nowrap; \n",
" position: sticky;\n",
" top: 0;\n",
" box-shadow: 0 -1px inset;\n",
"}\n",
"#h2o-table-1 .h2o-table tbody {\n",
" overflow: auto;\n",
"}\n",
"#h2o-table-1 .h2o-table th,\n",
"#h2o-table-1 .h2o-table td {\n",
" text-align: right;\n",
" /* border: 1px solid; */\n",
"}\n",
"#h2o-table-1 .h2o-table tr:nth-child(even) {\n",
" /* background: #F5F5F5 */\n",
"}\n",
"\n",
"</style> \n",
"<div id=\"h2o-table-1\" class=\"h2o-container\">\n",
" <table class=\"h2o-table\">\n",
" <caption></caption>\n",
" <thead></thead>\n",
" <tbody><tr><td>H2O_cluster_uptime:</td>\n",
"<td>05 secs</td></tr>\n",
"<tr><td>H2O_cluster_timezone:</td>\n",
"<td>Etc/UTC</td></tr>\n",
"<tr><td>H2O_data_parsing_timezone:</td>\n",
"<td>UTC</td></tr>\n",
"<tr><td>H2O_cluster_version:</td>\n",
"<td>3.40.0.4</td></tr>\n",
"<tr><td>H2O_cluster_version_age:</td>\n",
"<td>2 months and 5 days</td></tr>\n",
"<tr><td>H2O_cluster_name:</td>\n",
"<td>H2O_from_python_unknownUser_84nhlb</td></tr>\n",
"<tr><td>H2O_cluster_total_nodes:</td>\n",
"<td>1</td></tr>\n",
"<tr><td>H2O_cluster_free_memory:</td>\n",
"<td>3.170 Gb</td></tr>\n",
"<tr><td>H2O_cluster_total_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_allowed_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_status:</td>\n",
"<td>locked, healthy</td></tr>\n",
"<tr><td>H2O_connection_url:</td>\n",
"<td>http://127.0.0.1:54321</td></tr>\n",
"<tr><td>H2O_connection_proxy:</td>\n",
"<td>{\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}</td></tr>\n",
"<tr><td>H2O_internal_security:</td>\n",
"<td>False</td></tr>\n",
"<tr><td>Python_version:</td>\n",
"<td>3.10.12 final</td></tr></tbody>\n",
" </table>\n",
"</div>\n"
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Parse progress: |█████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"AutoML progress: |\n",
"18:54:24.100: _train param, Dropping bad and constant columns: [2180, 2188, 2243, 2187, 2253, 2186, 2241, 2252, 2251, 2261, 2051, 2260, 2259, 2115, 2258, 2114, 2179, 2245, 2123, 2178, 2244]\n",
"\n",
"██████████████\n",
"18:55:27.533: _train param, Dropping bad and constant columns: [2180, 2188, 2243, 2187, 2253, 2186, 2241, 2252, 2251, 2261, 2051, 2260, 2259, 2115, 2258, 2114, 2179, 2245, 2123, 2178, 2244]\n",
"\n",
"████████████████████\n",
"18:57:06.755: _train param, Dropping bad and constant columns: [2180, 2188, 2243, 2187, 2253, 2186, 2241, 2252, 2251, 2261, 2051, 2260, 2259, 2115, 2258, 2114, 2179, 2245, 2123, 2178, 2244]\n",
"\n",
"███████████████████████\n",
"18:58:56.409: _train param, Dropping bad and constant columns: [2180, 2188, 2243, 2187, 2253, 2186, 2241, 2252, 2251, 2261, 2051, 2260, 2259, 2115, 2258, 2114, 2179, 2245, 2123, 2178, 2244]\n",
"\n",
"██\n",
"18:59:04.307: _train param, Dropping bad and constant columns: [2180, 2188, 2243, 2187, 2253, 2186, 2241, 2252, 2251, 2261, 2051, 2260, 2259, 2115, 2258, 2114, 2179, 2245, 2123, 2178, 2244]\n",
"\n",
"██\n",
"18:59:14.24: _train param, Dropping bad and constant columns: [2180, 2188, 2243, 2187, 2253, 2186, 2241, 2252, 2251, 2261, 2051, 2260, 2259, 2115, 2258, 2114, 2179, 2245, 2123, 2178, 2244]\n",
"\n",
"██| (done) 100%\n",
"Train Accuracy: [[0.49898651242256165, 0.9897721989772199]]\n",
"Validation Accuracy: [[0.41796985268592834, 0.725]]\n",
"Test Accuracy: [[0.6860666275024414, 0.732943469785575]]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"print(best_model)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "OabuNGQMMbDT",
"outputId": "9e5fcca5-ac18-4896-9f10-d343a4c4d804"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Model Details\n",
"=============\n",
"H2OXGBoostEstimator : XGBoost\n",
"Model Key: XGBoost_1_AutoML_1_20230703_185422\n",
"\n",
"\n",
"Model Summary: \n",
" number_of_trees\n",
"-- -----------------\n",
" 35\n",
"\n",
"ModelMetricsBinomial: xgboost\n",
"** Reported on train data. **\n",
"\n",
"MSE: 0.029040139078203256\n",
"RMSE: 0.1704116752989749\n",
"LogLoss: 0.1485164790433812\n",
"Mean Per-Class Error: 0.010252758711926662\n",
"AUC: 0.999236933623169\n",
"AUCPR: 0.9992514550815524\n",
"Gini: 0.998473867246338\n",
"\n",
"Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.48749709129333496\n",
" 0 1 Error Rate\n",
"----- ---- ---- ------- -------------\n",
"0 1049 13 0.0122 (13.0/1062.0)\n",
"1 9 1080 0.0083 (9.0/1089.0)\n",
"Total 1058 1093 0.0102 (22.0/2151.0)\n",
"\n",
"Maximum Metrics: Maximum metrics at their respective thresholds\n",
"metric threshold value idx\n",
"--------------------------- ----------- -------- -----\n",
"max f1 0.487497 0.989918 200\n",
"max f2 0.438429 0.991584 209\n",
"max f0point5 0.586806 0.993093 184\n",
"max accuracy 0.498987 0.989772 199\n",
"max precision 0.998202 1 0\n",
"max recall 0.253771 1 257\n",
"max specificity 0.998202 1 0\n",
"max absolute_mcc 0.487497 0.979547 200\n",
"max min_per_class_accuracy 0.514463 0.988701 198\n",
"max mean_per_class_accuracy 0.498987 0.989759 199\n",
"max tns 0.998202 1062 0\n",
"max fns 0.998202 1087 0\n",
"max fps 0.00240075 1062 399\n",
"max tps 0.253771 1089 257\n",
"max tnr 0.998202 1 0\n",
"max fnr 0.998202 0.998163 0\n",
"max fpr 0.00240075 1 399\n",
"max tpr 0.253771 1 257\n",
"\n",
"Gains/Lift Table: Avg response rate: 50.63 %, avg score: 50.73 %\n",
"group cumulative_data_fraction lower_threshold lift cumulative_lift response_rate score cumulative_response_rate cumulative_score capture_rate cumulative_capture_rate gain cumulative_gain kolmogorov_smirnov\n",
"------- -------------------------- ----------------- ------- ----------------- --------------- --------- -------------------------- ------------------ -------------- ------------------------- ------- ----------------- --------------------\n",
"1 0.0111576 0.992682 1.97521 1.97521 1 0.995074 1 0.995074 0.0220386 0.0220386 97.5207 97.5207 0.0220386\n",
"2 0.0204556 0.988855 1.97521 1.97521 1 0.990505 1 0.992997 0.0183655 0.040404 97.5207 97.5207 0.040404\n",
"3 0.0302185 0.985758 1.97521 1.97521 1 0.987441 1 0.991202 0.0192837 0.0596878 97.5207 97.5207 0.0596878\n",
"4 0.0404463 0.982896 1.97521 1.97521 1 0.98434 1 0.989467 0.020202 0.0798898 97.5207 97.5207 0.0798898\n",
"5 0.0502092 0.979626 1.97521 1.97521 1 0.981365 1 0.987891 0.0192837 0.0991736 97.5207 97.5207 0.0991736\n",
"6 0.100418 0.962458 1.97521 1.97521 1 0.970626 1 0.979259 0.0991736 0.198347 97.5207 97.5207 0.198347\n",
"7 0.150163 0.947135 1.97521 1.97521 1 0.955607 1 0.971424 0.0982553 0.296602 97.5207 97.5207 0.296602\n",
"8 0.200372 0.927338 1.97521 1.97521 1 0.937333 1 0.962881 0.0991736 0.395776 97.5207 97.5207 0.395776\n",
"9 0.300325 0.881112 1.97521 1.97521 1 0.906778 1 0.944209 0.197429 0.593205 97.5207 97.5207 0.593205\n",
"10 0.400279 0.804222 1.96602 1.97291 0.995349 0.844734 0.998839 0.919369 0.196511 0.789715 96.602 97.2913 0.788774\n",
"11 0.500232 0.559756 1.92008 1.96236 0.972093 0.718489 0.993494 0.879231 0.191919 0.981635 92.0085 96.2357 0.975043\n",
"12 0.600186 0.210492 0.18374 1.66615 0.0930233 0.321034 0.843532 0.78627 0.0183655 1 -81.626 66.615 0.809793\n",
"13 0.700139 0.129488 0 1.42829 0 0.167591 0.723108 0.697946 0 1 -100 42.8287 0.607345\n",
"14 0.800093 0.0798181 0 1.24985 0 0.101392 0.632772 0.62342 0 1 -100 24.9855 0.404896\n",
"15 0.900046 0.0410367 0 1.11105 0 0.0606021 0.5625 0.560917 0 1 -100 11.1054 0.202448\n",
"16 1 0.00194884 0 1 0 0.0242891 0.506276 0.507279 0 1 -100 0 0\n",
"\n",
"ModelMetricsBinomial: xgboost\n",
"** Reported on validation data. **\n",
"\n",
"MSE: 0.19177176262261972\n",
"RMSE: 0.43791752947629276\n",
"LogLoss: 0.5819253876100278\n",
"Mean Per-Class Error: 0.27095652173913043\n",
"AUC: 0.7842086956521739\n",
"AUCPR: 0.7534831414895838\n",
"Gini: 0.5684173913043478\n",
"\n",
"Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.41796985268592834\n",
" 0 1 Error Rate\n",
"----- --- --- ------- ------------\n",
"0 79 46 0.368 (46.0/125.0)\n",
"1 20 95 0.1739 (20.0/115.0)\n",
"Total 99 141 0.275 (66.0/240.0)\n",
"\n",
"Maximum Metrics: Maximum metrics at their respective thresholds\n",
"metric threshold value idx\n",
"--------------------------- ----------- -------- -----\n",
"max f1 0.41797 0.742188 139\n",
"max f2 0.0473843 0.838192 224\n",
"max f0point5 0.709394 0.723514 66\n",
"max accuracy 0.41797 0.725 139\n",
"max precision 0.995058 1 0\n",
"max recall 0.0473843 1 224\n",
"max specificity 0.995058 1 0\n",
"max absolute_mcc 0.41797 0.464863 139\n",
"max min_per_class_accuracy 0.488725 0.704 116\n",
"max mean_per_class_accuracy 0.41797 0.729043 139\n",
"max tns 0.995058 125 0\n",
"max fns 0.995058 114 0\n",
"max fps 0.0142553 125 238\n",
"max tps 0.0473843 115 224\n",
"max tnr 0.995058 1 0\n",
"max fnr 0.995058 0.991304 0\n",
"max fpr 0.0142553 1 238\n",
"max tpr 0.0473843 1 224\n",
"\n",
"Gains/Lift Table: Avg response rate: 47.92 %, avg score: 49.57 %\n",
"group cumulative_data_fraction lower_threshold lift cumulative_lift response_rate score cumulative_response_rate cumulative_score capture_rate cumulative_capture_rate gain cumulative_gain kolmogorov_smirnov\n",
"------- -------------------------- ----------------- -------- ----------------- --------------- --------- -------------------------- ------------------ -------------- ------------------------- -------- ----------------- --------------------\n",
"1 0.0125 0.985501 2.08696 2.08696 1 0.988928 1 0.988928 0.026087 0.026087 108.696 108.696 0.026087\n",
"2 0.0208333 0.976676 1.04348 1.66957 0.5 0.98205 0.8 0.986177 0.00869565 0.0347826 4.34783 66.9565 0.0267826\n",
"3 0.0333333 0.966807 2.08696 1.82609 1 0.970299 0.875 0.980223 0.026087 0.0608696 108.696 82.6087 0.0528696\n",
"4 0.0416667 0.962841 2.08696 1.87826 1 0.965093 0.9 0.977197 0.0173913 0.0782609 108.696 87.8261 0.0702609\n",
"5 0.05 0.955575 2.08696 1.91304 1 0.959619 0.916667 0.974267 0.0173913 0.0956522 108.696 91.3043 0.0876522\n",
"6 0.1 0.932078 1.3913 1.65217 0.666667 0.945779 0.791667 0.960023 0.0695652 0.165217 39.1304 65.2174 0.125217\n",
"7 0.15 0.883276 1.73913 1.68116 0.833333 0.913566 0.805556 0.944537 0.0869565 0.252174 73.913 68.1159 0.196174\n",
"8 0.2 0.844238 1.91304 1.73913 0.916667 0.862545 0.833333 0.924039 0.0956522 0.347826 91.3043 73.913 0.283826\n",
"9 0.3 0.702915 1.47826 1.65217 0.708333 0.780983 0.791667 0.876354 0.147826 0.495652 47.8261 65.2174 0.375652\n",
"10 0.4 0.598655 1.21739 1.54348 0.583333 0.649252 0.739583 0.819578 0.121739 0.617391 21.7391 54.3478 0.417391\n",
"11 0.5 0.484203 0.956522 1.42609 0.458333 0.52814 0.683333 0.761291 0.0956522 0.713043 -4.34783 42.6087 0.409043\n",
"12 0.6 0.383452 1.13043 1.37681 0.541667 0.446644 0.659722 0.70885 0.113043 0.826087 13.0435 37.6812 0.434087\n",
"13 0.7 0.249309 0.695652 1.2795 0.333333 0.312986 0.613095 0.652298 0.0695652 0.895652 -30.4348 27.9503 0.375652\n",
"14 0.8 0.173995 0.434783 1.17391 0.208333 0.212553 0.5625 0.59733 0.0434783 0.93913 -56.5217 17.3913 0.26713\n",
"15 0.9 0.0934742 0.347826 1.08213 0.166667 0.133516 0.518519 0.545795 0.0347826 0.973913 -65.2174 8.21256 0.141913\n",
"16 1 0.0142553 0.26087 1 0.125 0.0444045 0.479167 0.495656 0.026087 1 -73.913 0 0\n",
"\n",
"Scoring History: \n",
" timestamp duration number_of_trees training_rmse training_logloss training_auc training_pr_auc training_lift training_classification_error validation_rmse validation_logloss validation_auc validation_pr_auc validation_lift validation_classification_error\n",
"-- ------------------- ---------------- ----------------- --------------- ------------------ -------------- ----------------- --------------- ------------------------------- ----------------- -------------------- ---------------- ------------------- ----------------- ---------------------------------\n",
" 2023-07-03 18:54:24 0.363 sec 0 0.5 0.693147 0.5 0.506276 1 0.493724 0.5 0.693147 0.5 0.479167 1 0.520833\n",
" 2023-07-03 18:54:38 14.151 sec 5 0.374383 0.452703 0.919961 0.918351 1.97521 0.155277 0.458128 0.606802 0.725913 0.682885 2.08696 0.3375\n",
" 2023-07-03 18:54:46 22.507 sec 10 0.314498 0.34566 0.962464 0.965011 1.97521 0.0985588 0.444785 0.578499 0.762713 0.728484 2.08696 0.308333\n",
" 2023-07-03 18:54:56 32.620 sec 15 0.272095 0.278293 0.981934 0.98332 1.97521 0.0692701 0.432648 0.552977 0.787965 0.765633 2.08696 0.291667\n",
" 2023-07-03 18:55:04 40.025 sec 20 0.238084 0.23 0.991556 0.992201 1.97521 0.0446304 0.425155 0.546224 0.802435 0.763971 2.08696 0.2375\n",
" 2023-07-03 18:55:12 47.949 sec 25 0.21139 0.194828 0.995489 0.995727 1.97521 0.0288238 0.431027 0.561146 0.796452 0.756522 2.08696 0.275\n",
" 2023-07-03 18:55:17 53.046 sec 30 0.188813 0.168572 0.998113 0.998238 1.97521 0.0158066 0.428432 0.557833 0.802017 0.765885 2.08696 0.266667\n",
" 2023-07-03 18:55:25 1 min 1.126 sec 35 0.170412 0.148516 0.999237 0.999251 1.97521 0.0102278 0.437918 0.581925 0.784209 0.753483 2.08696 0.275\n",
"\n",
"Variable Importances: \n",
"variable relative_importance scaled_importance percentage\n",
"---------- --------------------- ---------------------- ----------------------\n",
"1968 195.6201171875 1.0 0.045245795399663814\n",
"2255 86.996826171875 0.4447233107855128 0.020121859929262416\n",
"1390 65.54590606689453 0.3350673080523176 0.01516038686525129\n",
"455 51.98220443725586 0.2657303613995457 0.01202318156336257\n",
"1579 46.01121139526367 0.2352069513953024 0.010642125599410523\n",
"506 45.04158020019531 0.23025024648678333 0.01041785554326316\n",
"2737 40.458457946777344 0.20682156072935126 0.009357806020999372\n",
"1471 35.54043960571289 0.18168090335846043 0.008220296981382994\n",
"1521 35.26609420776367 0.18027846376332277 0.008156842486401009\n",
"176 31.788936614990234 0.1625034125939146 0.007352596157971411\n",
"--- --- --- ---\n",
"1387 1.8206892013549805 0.009307269761063825 0.00042111482333857174\n",
"1374 1.604644775390625 0.00820286174275516 0.00037114500410442977\n",
"976 1.349569320678711 0.006898929108529067 0.0003121475349212912\n",
"1532 1.3007698059082031 0.0066494684933729375 0.00030086049096766275\n",
"5983 0.8919868469238281 0.00455979098544792 0.00020631136999280802\n",
"2728 0.6874923706054688 0.0035144257169957317 0.00015901298693850568\n",
"798 0.6767730712890625 0.0034596292089958316 0.00015653367534892616\n",
"5426 0.518524169921875 0.0026506689464094054 0.0001199316248214824\n",
"194 0.1791229248046875 0.0009156671991613209 4.143009074743635e-05\n",
"1351 0.023181915283203125 0.00011850476125102962 5.361842181450095e-06\n",
"[443 rows x 4 columns]\n",
"\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"train_df = pd.read_csv('image_features_train5_64_64_normalized_.csv')\n",
"validation_df = pd.read_csv('image_features_val5_64_64_normalized_.csv')\n",
"test_df = pd.read_csv('image_features_test5_64_64_normalized_.csv')"
],
"metadata": {
"id": "RmicJGjvQhe1"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"best_model = select_best_classification_model(train_df, validation_df, test_df, max_runtime_sec=300)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 735
},
"id": "aaAwzyKIJaHi",
"outputId": "09609dc9-f878-4fe8-abfa-3785d3f1d4d2"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Checking whether there is an H2O instance running at http://localhost:54321. connected.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"-------------------------- -----------------------------------------------------------------------------------------\n",
"H2O_cluster_uptime: 1 hour 2 mins\n",
"H2O_cluster_timezone: Etc/UTC\n",
"H2O_data_parsing_timezone: UTC\n",
"H2O_cluster_version: 3.40.0.4\n",
"H2O_cluster_version_age: 2 months and 6 days\n",
"H2O_cluster_name: H2O_from_python_unknownUser_4vayef\n",
"H2O_cluster_total_nodes: 1\n",
"H2O_cluster_free_memory: 2.761 Gb\n",
"H2O_cluster_total_cores: 2\n",
"H2O_cluster_allowed_cores: 2\n",
"H2O_cluster_status: locked, healthy\n",
"H2O_connection_url: http://localhost:54321\n",
"H2O_connection_proxy: {\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}\n",
"H2O_internal_security: False\n",
"Python_version: 3.10.12 final\n",
"-------------------------- -----------------------------------------------------------------------------------------"
],
"text/html": [
"\n",
"<style>\n",
"\n",
"#h2o-table-10.h2o-container {\n",
" overflow-x: auto;\n",
"}\n",
"#h2o-table-10 .h2o-table {\n",
" /* width: 100%; */\n",
" margin-top: 1em;\n",
" margin-bottom: 1em;\n",
"}\n",
"#h2o-table-10 .h2o-table caption {\n",
" white-space: nowrap;\n",
" caption-side: top;\n",
" text-align: left;\n",
" /* margin-left: 1em; */\n",
" margin: 0;\n",
" font-size: larger;\n",
"}\n",
"#h2o-table-10 .h2o-table thead {\n",
" white-space: nowrap; \n",
" position: sticky;\n",
" top: 0;\n",
" box-shadow: 0 -1px inset;\n",
"}\n",
"#h2o-table-10 .h2o-table tbody {\n",
" overflow: auto;\n",
"}\n",
"#h2o-table-10 .h2o-table th,\n",
"#h2o-table-10 .h2o-table td {\n",
" text-align: right;\n",
" /* border: 1px solid; */\n",
"}\n",
"#h2o-table-10 .h2o-table tr:nth-child(even) {\n",
" /* background: #F5F5F5 */\n",
"}\n",
"\n",
"</style> \n",
"<div id=\"h2o-table-10\" class=\"h2o-container\">\n",
" <table class=\"h2o-table\">\n",
" <caption></caption>\n",
" <thead></thead>\n",
" <tbody><tr><td>H2O_cluster_uptime:</td>\n",
"<td>1 hour 2 mins</td></tr>\n",
"<tr><td>H2O_cluster_timezone:</td>\n",
"<td>Etc/UTC</td></tr>\n",
"<tr><td>H2O_data_parsing_timezone:</td>\n",
"<td>UTC</td></tr>\n",
"<tr><td>H2O_cluster_version:</td>\n",
"<td>3.40.0.4</td></tr>\n",
"<tr><td>H2O_cluster_version_age:</td>\n",
"<td>2 months and 6 days</td></tr>\n",
"<tr><td>H2O_cluster_name:</td>\n",
"<td>H2O_from_python_unknownUser_4vayef</td></tr>\n",
"<tr><td>H2O_cluster_total_nodes:</td>\n",
"<td>1</td></tr>\n",
"<tr><td>H2O_cluster_free_memory:</td>\n",
"<td>2.761 Gb</td></tr>\n",
"<tr><td>H2O_cluster_total_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_allowed_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_status:</td>\n",
"<td>locked, healthy</td></tr>\n",
"<tr><td>H2O_connection_url:</td>\n",
"<td>http://localhost:54321</td></tr>\n",
"<tr><td>H2O_connection_proxy:</td>\n",
"<td>{\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}</td></tr>\n",
"<tr><td>H2O_internal_security:</td>\n",
"<td>False</td></tr>\n",
"<tr><td>Python_version:</td>\n",
"<td>3.10.12 final</td></tr></tbody>\n",
" </table>\n",
"</div>\n"
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n"
]
},
{
"output_type": "error",
"ename": "H2OValueError",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mH2OValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-88-e3621e078f2b>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbest_model\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mselect_best_classification_model\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_df\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidation_df\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_df\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_models\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-26-ed87648708b2>\u001b[0m in \u001b[0;36mselect_best_classification_model\u001b[0;34m(train, validation, test, max_runtime_sec, max_models, nfolds)\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mlabel_index\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrain_h2o\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mncols\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0mtrain_h2o\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabel_index\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtrain_h2o\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabel_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masfactor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mvalidation_h2o\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabel_index\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalidation_h2o\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabel_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masfactor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 17\u001b[0m \u001b[0mtest_h2o\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabel_index\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtest_h2o\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlabel_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masfactor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/usr/local/lib/python3.10/dist-packages/h2o/frame.py\u001b[0m in \u001b[0;36masfactor\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 3273\u001b[0m \u001b[0mt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtypes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcolname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3274\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mt\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"bool\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"int\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"string\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"enum\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3275\u001b[0;31m raise H2OValueError(\"Only 'int' or 'string' are allowed for \"\n\u001b[0m\u001b[1;32m 3276\u001b[0m \"asfactor(), got %s:%s \" % (colname, t))\n\u001b[1;32m 3277\u001b[0m \u001b[0mfr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mH2OFrame\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_expr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexpr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mExprNode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"as.factor\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcache\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_ex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_cache\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mH2OValueError\u001b[0m: Only 'int' or 'string' are allowed for asfactor(), got 1279:real "
]
}
]
},
{
"cell_type": "code",
"source": [
"print(best_model)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TedzjVaATJfn",
"outputId": "cd8c38d6-67c6-43b3-91e2-870948aca12d"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Model Details\n",
"=============\n",
"H2OXGBoostEstimator : XGBoost\n",
"Model Key: XGBoost_1_AutoML_2_20230703_194251\n",
"\n",
"\n",
"Model Summary: \n",
" number_of_trees\n",
"-- -----------------\n",
" 30\n",
"\n",
"ModelMetricsBinomial: xgboost\n",
"** Reported on train data. **\n",
"\n",
"MSE: 0.035013150290913626\n",
"RMSE: 0.18711801166887604\n",
"LogLoss: 0.16789481004134213\n",
"Mean Per-Class Error: 0.013536754291761995\n",
"AUC: 0.9980411026892795\n",
"AUCPR: 0.9981716889368415\n",
"Gini: 0.996082205378559\n",
"\n",
"Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.46746154874563217\n",
" 0 1 Error Rate\n",
"----- ---- ---- ------- -------------\n",
"0 1043 19 0.0179 (19.0/1062.0)\n",
"1 10 1079 0.0092 (10.0/1089.0)\n",
"Total 1053 1098 0.0135 (29.0/2151.0)\n",
"\n",
"Maximum Metrics: Maximum metrics at their respective thresholds\n",
"metric threshold value idx\n",
"--------------------------- ----------- -------- -----\n",
"max f1 0.467462 0.98674 208\n",
"max f2 0.467462 0.989182 208\n",
"max f0point5 0.607012 0.985755 181\n",
"max accuracy 0.467462 0.986518 208\n",
"max precision 0.994214 1 0\n",
"max recall 0.171864 1 298\n",
"max specificity 0.994214 1 0\n",
"max absolute_mcc 0.467462 0.973063 208\n",
"max min_per_class_accuracy 0.485484 0.983471 204\n",
"max mean_per_class_accuracy 0.467462 0.986463 208\n",
"max tns 0.994214 1062 0\n",
"max fns 0.994214 1084 0\n",
"max fps 0.00207406 1062 399\n",
"max tps 0.171864 1089 298\n",
"max tnr 0.994214 1 0\n",
"max fnr 0.994214 0.995409 0\n",
"max fpr 0.00207406 1 399\n",
"max tpr 0.171864 1 298\n",
"\n",
"Gains/Lift Table: Avg response rate: 50.63 %, avg score: 50.53 %\n",
"group cumulative_data_fraction lower_threshold lift cumulative_lift response_rate score cumulative_response_rate cumulative_score capture_rate cumulative_capture_rate gain cumulative_gain kolmogorov_smirnov\n",
"------- -------------------------- ----------------- -------- ----------------- --------------- --------- -------------------------- ------------------ -------------- ------------------------- -------- ----------------- --------------------\n",
"1 0.0102278 0.988707 1.97521 1.97521 1 0.991056 1 0.991056 0.020202 0.020202 97.5207 97.5207 0.020202\n",
"2 0.0204556 0.984869 1.97521 1.97521 1 0.986312 1 0.988684 0.020202 0.040404 97.5207 97.5207 0.040404\n",
"3 0.0302185 0.980752 1.97521 1.97521 1 0.982844 1 0.986797 0.0192837 0.0596878 97.5207 97.5207 0.0596878\n",
"4 0.0404463 0.976219 1.97521 1.97521 1 0.978321 1 0.984654 0.020202 0.0798898 97.5207 97.5207 0.0798898\n",
"5 0.0506741 0.971763 1.97521 1.97521 1 0.973817 1 0.982467 0.020202 0.100092 97.5207 97.5207 0.100092\n",
"6 0.100418 0.955931 1.97521 1.97521 1 0.963699 1 0.97317 0.0982553 0.198347 97.5207 97.5207 0.198347\n",
"7 0.150163 0.936395 1.97521 1.97521 1 0.946813 1 0.964439 0.0982553 0.296602 97.5207 97.5207 0.296602\n",
"8 0.200372 0.914714 1.97521 1.97521 1 0.925795 1 0.954755 0.0991736 0.395776 97.5207 97.5207 0.395776\n",
"9 0.300325 0.861343 1.97521 1.97521 1 0.891779 1 0.933796 0.197429 0.593205 97.5207 97.5207 0.593205\n",
"10 0.400279 0.787975 1.96602 1.97291 0.995349 0.828632 0.998839 0.907535 0.196511 0.789715 96.602 97.2913 0.788774\n",
"11 0.500232 0.527964 1.85578 1.94951 0.939535 0.693916 0.986989 0.864851 0.185491 0.975207 85.5776 94.9507 0.962024\n",
"12 0.600186 0.222557 0.229675 1.66309 0.116279 0.329479 0.841983 0.775691 0.0229568 0.998163 -77.0325 66.309 0.806073\n",
"13 0.700139 0.148664 0.018374 1.42829 0.00930233 0.181898 0.723108 0.69092 0.00183655 1 -98.1626 42.8287 0.607345\n",
"14 0.800093 0.091073 0 1.24985 0 0.117334 0.632772 0.619264 0 1 -100 24.9855 0.404896\n",
"15 0.900046 0.0480732 0 1.11105 0 0.0699872 0.5625 0.558264 0 1 -100 11.1054 0.202448\n",
"16 1 0.00207406 0 1 0 0.0279845 0.506276 0.505261 0 1 -100 0 0\n",
"\n",
"ModelMetricsBinomial: xgboost\n",
"** Reported on validation data. **\n",
"\n",
"MSE: 0.19231614049251572\n",
"RMSE: 0.43853864196044995\n",
"LogLoss: 0.5897306530456264\n",
"Mean Per-Class Error: 0.2603478260869565\n",
"AUC: 0.784695652173913\n",
"AUCPR: 0.7522259458650904\n",
"Gini: 0.569391304347826\n",
"\n",
"Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.399491548538208\n",
" 0 1 Error Rate\n",
"----- --- --- ------- ------------\n",
"0 86 39 0.312 (39.0/125.0)\n",
"1 24 91 0.2087 (24.0/115.0)\n",
"Total 110 130 0.2625 (63.0/240.0)\n",
"\n",
"Maximum Metrics: Maximum metrics at their respective thresholds\n",
"metric threshold value idx\n",
"--------------------------- ----------- -------- -----\n",
"max f1 0.399492 0.742857 128\n",
"max f2 0.0822024 0.839525 211\n",
"max f0point5 0.492631 0.73913 113\n",
"max accuracy 0.492631 0.75 113\n",
"max precision 0.992499 1 0\n",
"max recall 0.0331505 1 230\n",
"max specificity 0.992499 1 0\n",
"max absolute_mcc 0.492631 0.49913 113\n",
"max min_per_class_accuracy 0.492631 0.73913 113\n",
"max mean_per_class_accuracy 0.492631 0.749565 113\n",
"max tns 0.992499 125 0\n",
"max fns 0.992499 114 0\n",
"max fps 0.0113229 125 238\n",
"max tps 0.0331505 115 230\n",
"max tnr 0.992499 1 0\n",
"max fnr 0.992499 0.991304 0\n",
"max fpr 0.0113229 1 238\n",
"max tpr 0.0331505 1 230\n",
"\n",
"Gains/Lift Table: Avg response rate: 47.92 %, avg score: 48.37 %\n",
"group cumulative_data_fraction lower_threshold lift cumulative_lift response_rate score cumulative_response_rate cumulative_score capture_rate cumulative_capture_rate gain cumulative_gain kolmogorov_smirnov\n",
"------- -------------------------- ----------------- -------- ----------------- --------------- --------- -------------------------- ------------------ -------------- ------------------------- -------- ----------------- --------------------\n",
"1 0.0125 0.988734 2.08696 2.08696 1 0.990932 1 0.990932 0.026087 0.026087 108.696 108.696 0.026087\n",
"2 0.0208333 0.983947 2.08696 2.08696 1 0.987498 1 0.989558 0.0173913 0.0434783 108.696 108.696 0.0434783\n",
"3 0.0333333 0.977962 0.695652 1.56522 0.333333 0.980005 0.75 0.985976 0.00869565 0.0521739 -30.4348 56.5217 0.0361739\n",
"4 0.0416667 0.97026 2.08696 1.66957 1 0.973729 0.8 0.983526 0.0173913 0.0695652 108.696 66.9565 0.0535652\n",
"5 0.05 0.949281 1.04348 1.56522 0.5 0.95985 0.75 0.97958 0.00869565 0.0782609 4.34783 56.5217 0.0542609\n",
"6 0.1 0.911866 1.73913 1.65217 0.833333 0.928775 0.791667 0.954178 0.0869565 0.165217 73.913 65.2174 0.125217\n",
"7 0.15 0.875325 1.91304 1.73913 0.916667 0.895177 0.833333 0.934511 0.0956522 0.26087 91.3043 73.913 0.21287\n",
"8 0.2 0.84728 1.73913 1.73913 0.833333 0.857978 0.833333 0.915378 0.0869565 0.347826 73.913 73.913 0.283826\n",
"9 0.3 0.713594 1.65217 1.71014 0.791667 0.78283 0.819444 0.871195 0.165217 0.513043 65.2174 71.0145 0.409043\n",
"10 0.4 0.580836 0.956522 1.52174 0.458333 0.656115 0.729167 0.817425 0.0956522 0.608696 -4.34783 52.1739 0.400696\n",
"11 0.5 0.45093 1.3913 1.49565 0.666667 0.524271 0.716667 0.758794 0.13913 0.747826 39.1304 49.5652 0.475826\n",
"12 0.6 0.366138 0.695652 1.36232 0.333333 0.400876 0.652778 0.699141 0.0695652 0.817391 -30.4348 36.2319 0.417391\n",
"13 0.7 0.262157 0.521739 1.24224 0.25 0.315548 0.595238 0.644342 0.0521739 0.869565 -47.8261 24.2236 0.325565\n",
"14 0.8 0.126078 0.608696 1.16304 0.291667 0.185322 0.557292 0.586965 0.0608696 0.930435 -39.1304 16.3043 0.250435\n",
"15 0.9 0.0757316 0.521739 1.09179 0.25 0.100735 0.523148 0.532939 0.0521739 0.982609 -47.8261 9.17874 0.158609\n",
"16 1 0.0113229 0.173913 1 0.0833333 0.0406689 0.479167 0.483712 0.0173913 1 -82.6087 0 0\n",
"\n",
"Scoring History: \n",
" timestamp duration number_of_trees training_rmse training_logloss training_auc training_pr_auc training_lift training_classification_error validation_rmse validation_logloss validation_auc validation_pr_auc validation_lift validation_classification_error\n",
"-- ------------------- ---------------- ----------------- --------------- ------------------ -------------- ----------------- --------------- ------------------------------- ----------------- -------------------- ---------------- ------------------- ----------------- ---------------------------------\n",
" 2023-07-03 19:42:55 0.956 sec 0 0.5 0.693147 0.5 0.506276 1 0.493724 0.5 0.693147 0.5 0.479167 1 0.520833\n",
" 2023-07-03 19:43:14 19.464 sec 5 0.378134 0.457902 0.916565 0.916152 1.97521 0.165504 0.445335 0.583343 0.76727 0.697079 0.695652 0.304167\n",
" 2023-07-03 19:43:23 29.421 sec 10 0.318005 0.352761 0.96038 0.960035 1.97521 0.100418 0.434656 0.563772 0.786435 0.727032 2.08696 0.291667\n",
" 2023-07-03 19:43:32 38.386 sec 15 0.273605 0.282401 0.982473 0.983257 1.97521 0.0627615 0.430238 0.554131 0.794017 0.753533 1.3913 0.266667\n",
" 2023-07-03 19:43:41 46.570 sec 20 0.239103 0.232592 0.99117 0.990917 1.97521 0.0390516 0.42943 0.556635 0.796452 0.772178 2.08696 0.25\n",
" 2023-07-03 19:43:46 52.370 sec 25 0.210936 0.195728 0.995615 0.995715 1.97521 0.023245 0.436222 0.578375 0.788174 0.748148 2.08696 0.266667\n",
" 2023-07-03 19:43:56 1 min 1.592 sec 30 0.187118 0.167895 0.998041 0.998172 1.97521 0.0134821 0.438539 0.589731 0.784696 0.752226 2.08696 0.2625\n",
"\n",
"Variable Importances: \n",
"variable relative_importance scaled_importance percentage\n",
"---------- --------------------- --------------------- ----------------------\n",
"1968 230.16693115234375 1.0 0.055581620549461655\n",
"1606 65.45631408691406 0.28438626591232424 0.01580664952141711\n",
"1381 64.61123657226562 0.2807146806397679 0.015602576861982891\n",
"2255 42.069740295410156 0.18277925540730644 0.010159167218362044\n",
"1082 41.69380187988281 0.18114592600744353 0.010068384123426585\n",
"25 39.22028350830078 0.17039929807441154 0.009471069127466555\n",
"995 38.76097869873047 0.16840376897181292 0.009360154386090511\n",
"1705 37.382694244384766 0.16241557402371484 0.00902732080670912\n",
"2737 37.26341247558594 0.16189733376999274 0.00899851617357328\n",
"417 36.818626403808594 0.15996488383224322 0.008891107474402457\n",
"--- --- --- ---\n",
"1193 2.05181884765625 0.008914481491253774 0.0004954813276420663\n",
"689 2.048356056213379 0.008899436795538649 0.0004946451190735462\n",
"572 1.9759674072265625 0.008584931802903963 0.00047716442191201376\n",
"1106 1.9596729278564453 0.008514137621965207 0.0004732295666099659\n",
"266 1.7786426544189453 0.007727620321103776 0.0004295136604378991\n",
"2338 1.7677936553955078 0.007680484970386271 0.000426893801259853\n",
"29 1.2128877639770508 0.005269600450006696 0.00029289293265954454\n",
"965 0.7809429168701172 0.0033929414315092194 0.0001885851831926927\n",
"778 0.6238937377929688 0.002710614138483793 0.0001506603265012121\n",
"1283 0.348968505859375 0.001516153967523677 8.427029451746183e-05\n",
"[389 rows x 4 columns]\n",
"\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Classification Using CNN method Feature-Extraction"
],
"metadata": {
"id": "e-Nz2wOi3A5N"
}
},
{
"cell_type": "code",
"source": [
"# Separate the features from the labels\n",
"features = pd.read_csv('Features/features.csv', header=None)\n",
"labels = pd.read_csv('new_labels.csv')\n",
"\n",
"# Apply Min-Max scaling to the features\n",
"scaler = MinMaxScaler()\n",
"normalized_features = scaler.fit_transform(features)\n",
"\n",
"# Create a new DataFrame with the normalized features and labels\n",
"normalized_df = pd.DataFrame(normalized_features, columns=features.columns)\n",
"normalized_df['Label'] = labels['real_fake']\n",
"\n",
"# Split the normalized DataFrame into train, validation, and test sets\n",
"train_val_df, test_df = train_test_split(normalized_df, test_size=0.3, random_state=42)\n",
"train_df, val_df = train_test_split(train_val_df, test_size=0.2, random_state=42)\n",
"\n",
"# Create a LabelEncoder object\n",
"label_encoder = LabelEncoder()\n",
"\n",
"# Fit and transform the \"Label\" column in train_df\n",
"train_df['Label'] = label_encoder.fit_transform(train_df['Label'])\n",
"\n",
"# Transform the \"Label\" column in val_df and test_df using the fitted encoder\n",
"val_df['Label'] = label_encoder.transform(val_df['Label'])\n",
"test_df['Label'] = label_encoder.transform(test_df['Label'])\n"
],
"metadata": {
"id": "_4UBInuvKoYF"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"best_model = select_best_classification_model(train_df, val_df, test_df, max_models=10)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 500
},
"id": "OpYcBdF6P10-",
"outputId": "a28a19ff-93b2-48e8-e078-79259c549aae"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Checking whether there is an H2O instance running at http://localhost:54321. connected.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"-------------------------- -----------------------------------------------------------------------------------------\n",
"H2O_cluster_uptime: 1 hour 20 mins\n",
"H2O_cluster_timezone: Etc/UTC\n",
"H2O_data_parsing_timezone: UTC\n",
"H2O_cluster_version: 3.40.0.4\n",
"H2O_cluster_version_age: 2 months and 6 days\n",
"H2O_cluster_name: H2O_from_python_unknownUser_4vayef\n",
"H2O_cluster_total_nodes: 1\n",
"H2O_cluster_free_memory: 2.526 Gb\n",
"H2O_cluster_total_cores: 2\n",
"H2O_cluster_allowed_cores: 2\n",
"H2O_cluster_status: locked, healthy\n",
"H2O_connection_url: http://localhost:54321\n",
"H2O_connection_proxy: {\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}\n",
"H2O_internal_security: False\n",
"Python_version: 3.10.12 final\n",
"-------------------------- -----------------------------------------------------------------------------------------"
],
"text/html": [
"\n",
"<style>\n",
"\n",
"#h2o-table-15.h2o-container {\n",
" overflow-x: auto;\n",
"}\n",
"#h2o-table-15 .h2o-table {\n",
" /* width: 100%; */\n",
" margin-top: 1em;\n",
" margin-bottom: 1em;\n",
"}\n",
"#h2o-table-15 .h2o-table caption {\n",
" white-space: nowrap;\n",
" caption-side: top;\n",
" text-align: left;\n",
" /* margin-left: 1em; */\n",
" margin: 0;\n",
" font-size: larger;\n",
"}\n",
"#h2o-table-15 .h2o-table thead {\n",
" white-space: nowrap; \n",
" position: sticky;\n",
" top: 0;\n",
" box-shadow: 0 -1px inset;\n",
"}\n",
"#h2o-table-15 .h2o-table tbody {\n",
" overflow: auto;\n",
"}\n",
"#h2o-table-15 .h2o-table th,\n",
"#h2o-table-15 .h2o-table td {\n",
" text-align: right;\n",
" /* border: 1px solid; */\n",
"}\n",
"#h2o-table-15 .h2o-table tr:nth-child(even) {\n",
" /* background: #F5F5F5 */\n",
"}\n",
"\n",
"</style> \n",
"<div id=\"h2o-table-15\" class=\"h2o-container\">\n",
" <table class=\"h2o-table\">\n",
" <caption></caption>\n",
" <thead></thead>\n",
" <tbody><tr><td>H2O_cluster_uptime:</td>\n",
"<td>1 hour 20 mins</td></tr>\n",
"<tr><td>H2O_cluster_timezone:</td>\n",
"<td>Etc/UTC</td></tr>\n",
"<tr><td>H2O_data_parsing_timezone:</td>\n",
"<td>UTC</td></tr>\n",
"<tr><td>H2O_cluster_version:</td>\n",
"<td>3.40.0.4</td></tr>\n",
"<tr><td>H2O_cluster_version_age:</td>\n",
"<td>2 months and 6 days</td></tr>\n",
"<tr><td>H2O_cluster_name:</td>\n",
"<td>H2O_from_python_unknownUser_4vayef</td></tr>\n",
"<tr><td>H2O_cluster_total_nodes:</td>\n",
"<td>1</td></tr>\n",
"<tr><td>H2O_cluster_free_memory:</td>\n",
"<td>2.526 Gb</td></tr>\n",
"<tr><td>H2O_cluster_total_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_allowed_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_status:</td>\n",
"<td>locked, healthy</td></tr>\n",
"<tr><td>H2O_connection_url:</td>\n",
"<td>http://localhost:54321</td></tr>\n",
"<tr><td>H2O_connection_proxy:</td>\n",
"<td>{\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}</td></tr>\n",
"<tr><td>H2O_internal_security:</td>\n",
"<td>False</td></tr>\n",
"<tr><td>Python_version:</td>\n",
"<td>3.10.12 final</td></tr></tbody>\n",
" </table>\n",
"</div>\n"
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"AutoML progress: |███████████████████████████████████████████████████████████████| (done) 100%\n",
"Train Accuracy: [[0.4931986763581697, 0.9576581285938317]]\n",
"Validation Accuracy: [[0.4859916131839799, 0.5386221294363257]]\n",
"Test Accuracy: [[0.47645825229692235, 0.5175438596491229]]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"best_model = select_best_classification_model(train_df, val_df, test_df, max_runtime_sec=300)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 500
},
"id": "wgwbrtl7EC_7",
"outputId": "33d499e8-4737-4d8e-ae77-5baa8672f060"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Checking whether there is an H2O instance running at http://localhost:54321. connected.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"-------------------------- -----------------------------------------------------------------------------------------\n",
"H2O_cluster_uptime: 1 hour 47 mins\n",
"H2O_cluster_timezone: Etc/UTC\n",
"H2O_data_parsing_timezone: UTC\n",
"H2O_cluster_version: 3.40.0.4\n",
"H2O_cluster_version_age: 2 months and 6 days\n",
"H2O_cluster_name: H2O_from_python_unknownUser_4vayef\n",
"H2O_cluster_total_nodes: 1\n",
"H2O_cluster_free_memory: 2.353 Gb\n",
"H2O_cluster_total_cores: 2\n",
"H2O_cluster_allowed_cores: 2\n",
"H2O_cluster_status: locked, healthy\n",
"H2O_connection_url: http://localhost:54321\n",
"H2O_connection_proxy: {\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}\n",
"H2O_internal_security: False\n",
"Python_version: 3.10.12 final\n",
"-------------------------- -----------------------------------------------------------------------------------------"
],
"text/html": [
"\n",
"<style>\n",
"\n",
"#h2o-table-17.h2o-container {\n",
" overflow-x: auto;\n",
"}\n",
"#h2o-table-17 .h2o-table {\n",
" /* width: 100%; */\n",
" margin-top: 1em;\n",
" margin-bottom: 1em;\n",
"}\n",
"#h2o-table-17 .h2o-table caption {\n",
" white-space: nowrap;\n",
" caption-side: top;\n",
" text-align: left;\n",
" /* margin-left: 1em; */\n",
" margin: 0;\n",
" font-size: larger;\n",
"}\n",
"#h2o-table-17 .h2o-table thead {\n",
" white-space: nowrap; \n",
" position: sticky;\n",
" top: 0;\n",
" box-shadow: 0 -1px inset;\n",
"}\n",
"#h2o-table-17 .h2o-table tbody {\n",
" overflow: auto;\n",
"}\n",
"#h2o-table-17 .h2o-table th,\n",
"#h2o-table-17 .h2o-table td {\n",
" text-align: right;\n",
" /* border: 1px solid; */\n",
"}\n",
"#h2o-table-17 .h2o-table tr:nth-child(even) {\n",
" /* background: #F5F5F5 */\n",
"}\n",
"\n",
"</style> \n",
"<div id=\"h2o-table-17\" class=\"h2o-container\">\n",
" <table class=\"h2o-table\">\n",
" <caption></caption>\n",
" <thead></thead>\n",
" <tbody><tr><td>H2O_cluster_uptime:</td>\n",
"<td>1 hour 47 mins</td></tr>\n",
"<tr><td>H2O_cluster_timezone:</td>\n",
"<td>Etc/UTC</td></tr>\n",
"<tr><td>H2O_data_parsing_timezone:</td>\n",
"<td>UTC</td></tr>\n",
"<tr><td>H2O_cluster_version:</td>\n",
"<td>3.40.0.4</td></tr>\n",
"<tr><td>H2O_cluster_version_age:</td>\n",
"<td>2 months and 6 days</td></tr>\n",
"<tr><td>H2O_cluster_name:</td>\n",
"<td>H2O_from_python_unknownUser_4vayef</td></tr>\n",
"<tr><td>H2O_cluster_total_nodes:</td>\n",
"<td>1</td></tr>\n",
"<tr><td>H2O_cluster_free_memory:</td>\n",
"<td>2.353 Gb</td></tr>\n",
"<tr><td>H2O_cluster_total_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_allowed_cores:</td>\n",
"<td>2</td></tr>\n",
"<tr><td>H2O_cluster_status:</td>\n",
"<td>locked, healthy</td></tr>\n",
"<tr><td>H2O_connection_url:</td>\n",
"<td>http://localhost:54321</td></tr>\n",
"<tr><td>H2O_connection_proxy:</td>\n",
"<td>{\"http\": null, \"https\": null, \"colab_language_server\": \"/usr/colab/bin/language_service\"}</td></tr>\n",
"<tr><td>H2O_internal_security:</td>\n",
"<td>False</td></tr>\n",
"<tr><td>Python_version:</td>\n",
"<td>3.10.12 final</td></tr></tbody>\n",
" </table>\n",
"</div>\n"
]
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%\n",
"AutoML progress: |███████████████████████████████████████████████████████████████| (done) 100%\n",
"Train Accuracy: [[0.7961747948643494, 0.9989545216936748]]\n",
"Validation Accuracy: [[0.5378054739570671, 0.9874739039665971]]\n",
"Test Accuracy: [[0.4194223474405893, 0.9892787524366472]]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"print(best_model)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "gXzu4u7KbLlb",
"outputId": "9f8460be-015a-4c96-9780-1337a343bd02"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Model Details\n",
"=============\n",
"H2OGradientBoostingEstimator : Gradient Boosting Machine\n",
"Model Key: GBM_1_AutoML_8_20230704_145749\n",
"\n",
"\n",
"Model Summary: \n",
" number_of_trees number_of_internal_trees model_size_in_bytes min_depth max_depth mean_depth min_leaves max_leaves mean_leaves\n",
"-- ----------------- -------------------------- --------------------- ----------- ----------- ------------ ------------ ------------ -------------\n",
" 80 80 17420 4 10 7.6875 6 14 12.775\n",
"\n",
"ModelMetricsBinomial: gbm\n",
"** Reported on train data. **\n",
"\n",
"MSE: 0.0018978032399366424\n",
"RMSE: 0.04356378358151002\n",
"LogLoss: 0.009632680261227435\n",
"Mean Per-Class Error: 0.0010504201680672268\n",
"AUC: 0.9999945347545885\n",
"AUCPR: 0.9999944956018948\n",
"Gini: 0.9999890695091771\n",
"\n",
"Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.796174778178021\n",
" 0 1 Error Rate\n",
"----- --- --- ------- ------------\n",
"0 961 0 0 (0.0/961.0)\n",
"1 2 950 0.0021 (2.0/952.0)\n",
"Total 963 950 0.001 (2.0/1913.0)\n",
"\n",
"Maximum Metrics: Maximum metrics at their respective thresholds\n",
"metric threshold value idx\n",
"--------------------------- ----------- -------- -----\n",
"max f1 0.796175 0.998948 276\n",
"max f2 0.53274 0.99916 280\n",
"max f0point5 0.796175 0.999579 276\n",
"max accuracy 0.796175 0.998955 276\n",
"max precision 0.999437 1 0\n",
"max recall 0.53274 1 280\n",
"max specificity 0.999437 1 0\n",
"max absolute_mcc 0.796175 0.997911 276\n",
"max min_per_class_accuracy 0.563091 0.997919 278\n",
"max mean_per_class_accuracy 0.796175 0.99895 276\n",
"max tns 0.999437 961 0\n",
"max fns 0.999437 950 0\n",
"max fps 0.000162984 961 399\n",
"max tps 0.53274 952 280\n",
"max tnr 0.999437 1 0\n",
"max fnr 0.999437 0.997899 0\n",
"max fpr 0.000162984 1 399\n",
"max tpr 0.53274 1 280\n",
"\n",
"Gains/Lift Table: Avg response rate: 49.76 %, avg score: 49.77 %\n",
"group cumulative_data_fraction lower_threshold lift cumulative_lift response_rate score cumulative_response_rate cumulative_score capture_rate cumulative_capture_rate gain cumulative_gain kolmogorov_smirnov\n",
"------- -------------------------- ----------------- ------- ----------------- --------------- ----------- -------------------------- ------------------ -------------- ------------------------- ------- ----------------- --------------------\n",
"1 0.0104548 0.999092 2.00945 2.00945 1 0.999203 1 0.999203 0.0210084 0.0210084 100.945 100.945 0.0210084\n",
"2 0.0203868 0.998926 2.00945 2.00945 1 0.999 1 0.999104 0.019958 0.0409664 100.945 100.945 0.0409664\n",
"3 0.0303189 0.998809 2.00945 2.00945 1 0.998873 1 0.999028 0.019958 0.0609244 100.945 100.945 0.0609244\n",
"4 0.0402509 0.998668 2.00945 2.00945 1 0.998744 1 0.998958 0.019958 0.0808824 100.945 100.945 0.0808824\n",
"5 0.050183 0.998531 2.00945 2.00945 1 0.998611 1 0.998889 0.019958 0.10084 100.945 100.945 0.10084\n",
"6 0.100366 0.998007 2.00945 2.00945 1 0.998292 1 0.998591 0.10084 0.201681 100.945 100.945 0.201681\n",
"7 0.150026 0.997353 2.00945 2.00945 1 0.997693 1 0.998294 0.0997899 0.301471 100.945 100.945 0.301471\n",
"8 0.200209 0.996644 2.00945 2.00945 1 0.99701 1 0.997972 0.10084 0.402311 100.945 100.945 0.402311\n",
"9 0.300052 0.994766 2.00945 2.00945 1 0.995787 1 0.997245 0.20063 0.602941 100.945 100.945 0.602941\n",
"10 0.399895 0.990712 2.00945 2.00945 1 0.993086 1 0.996207 0.20063 0.803571 100.945 100.945 0.803571\n",
"11 0.500261 0.516895 1.95712 1.99896 0.973958 0.962901 0.994775 0.989525 0.196429 1 95.7124 99.8955 0.994797\n",
"12 0.600105 0.000791126 0 1.66638 0 0.0256578 0.829268 0.82916 0 1 -100 66.6376 0.796046\n",
"13 0.699948 0.000408477 0 1.42868 0 0.000552177 0.710978 0.710964 0 1 -100 42.8678 0.597294\n",
"14 0.799791 0.000310229 0 1.25033 0 0.000352305 0.622222 0.622254 0 1 -100 25.0327 0.398543\n",
"15 0.899634 0.000244486 0 1.11156 0 0.000275593 0.553167 0.553225 0 1 -100 11.1563 0.199792\n",
"16 1 0.000153834 0 1 0 0.000211829 0.497648 0.497722 0 1 -100 0 0\n",
"\n",
"ModelMetricsBinomial: gbm\n",
"** Reported on validation data. **\n",
"\n",
"MSE: 0.011986886066822104\n",
"RMSE: 0.1094846384970152\n",
"LogLoss: 0.05296850582186085\n",
"Mean Per-Class Error: 0.012\n",
"AUC: 0.9967772925764192\n",
"AUCPR: 0.9960742592552965\n",
"Gini: 0.9935545851528385\n",
"\n",
"Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.41439140869202146\n",
" 0 1 Error Rate\n",
"----- --- --- ------- -----------\n",
"0 244 6 0.024 (6.0/250.0)\n",
"1 0 229 0 (0.0/229.0)\n",
"Total 244 235 0.0125 (6.0/479.0)\n",
"\n",
"Maximum Metrics: Maximum metrics at their respective thresholds\n",
"metric threshold value idx\n",
"--------------------------- ----------- -------- -----\n",
"max f1 0.414391 0.987069 224\n",
"max f2 0.414391 0.994787 224\n",
"max f0point5 0.853864 0.983464 219\n",
"max accuracy 0.537805 0.987474 222\n",
"max precision 0.999399 1 0\n",
"max recall 0.414391 1 224\n",
"max specificity 0.999399 1 0\n",
"max absolute_mcc 0.414391 0.975234 224\n",
"max min_per_class_accuracy 0.853864 0.984 219\n",
"max mean_per_class_accuracy 0.414391 0.988 224\n",
"max tns 0.999399 250 0\n",
"max fns 0.999399 228 0\n",
"max fps 0.000145583 250 399\n",
"max tps 0.414391 229 224\n",
"max tnr 0.999399 1 0\n",
"max fnr 0.999399 0.995633 0\n",
"max fpr 0.000145583 1 399\n",
"max tpr 0.414391 1 224\n",
"\n",
"Gains/Lift Table: Avg response rate: 47.81 %, avg score: 48.48 %\n",
"group cumulative_data_fraction lower_threshold lift cumulative_lift response_rate score cumulative_response_rate cumulative_score capture_rate cumulative_capture_rate gain cumulative_gain kolmogorov_smirnov\n",
"------- -------------------------- ----------------- ------- ----------------- --------------- ----------- -------------------------- ------------------ -------------- ------------------------- ------- ----------------- --------------------\n",
"1 0.0104384 0.999036 2.0917 2.0917 1 0.999209 1 0.999209 0.0218341 0.0218341 109.17 109.17 0.0218341\n",
"2 0.0208768 0.998808 2.0917 2.0917 1 0.998931 1 0.99907 0.0218341 0.0436681 109.17 109.17 0.0436681\n",
"3 0.0313152 0.998642 2.0917 2.0917 1 0.998723 1 0.998954 0.0218341 0.0655022 109.17 109.17 0.0655022\n",
"4 0.0417537 0.998534 2.0917 2.0917 1 0.998594 1 0.998864 0.0218341 0.0873362 109.17 109.17 0.0873362\n",
"5 0.0501044 0.998391 2.0917 2.0917 1 0.99841 1 0.998788 0.0174672 0.104803 109.17 109.17 0.104803\n",
"6 0.100209 0.997854 2.0917 2.0917 1 0.998117 1 0.998453 0.104803 0.209607 109.17 109.17 0.209607\n",
"7 0.150313 0.997189 2.0917 2.0917 1 0.997517 1 0.998141 0.104803 0.31441 109.17 109.17 0.31441\n",
"8 0.200418 0.996687 2.0917 2.0917 1 0.996914 1 0.997834 0.104803 0.419214 109.17 109.17 0.419214\n",
"9 0.300626 0.994957 2.0917 2.0917 1 0.995942 1 0.997203 0.209607 0.628821 109.17 109.17 0.628821\n",
"10 0.400835 0.988488 2.00455 2.06991 0.958333 0.992312 0.989583 0.995981 0.200873 0.829694 100.455 106.991 0.821694\n",
"11 0.501044 0.0143402 1.69951 1.99583 0.8125 0.850247 0.954167 0.966834 0.170306 1 69.9509 99.5833 0.956\n",
"12 0.599165 0.000661908 0 1.66899 0 0.00227792 0.797909 0.808875 0 1 -100 66.899 0.768\n",
"13 0.699374 0.00037297 0 1.42985 0 0.000471475 0.683582 0.693044 0 1 -100 42.9851 0.576\n",
"14 0.799582 0.000294053 0 1.25065 0 0.000328139 0.597911 0.606229 0 1 -100 25.0653 0.384\n",
"15 0.899791 0.000233619 0 1.11137 0 0.000262132 0.531323 0.538743 0 1 -100 11.1369 0.192\n",
"16 1 0.000145583 0 1 0 0.000202737 0.478079 0.484776 0 1 -100 0 0\n",
"\n",
"Scoring History: \n",
" timestamp duration number_of_trees training_rmse training_logloss training_auc training_pr_auc training_lift training_classification_error validation_rmse validation_logloss validation_auc validation_pr_auc validation_lift validation_classification_error\n",
"-- ------------------- ---------- ----------------- --------------- ------------------ -------------- ----------------- --------------- ------------------------------- ----------------- -------------------- ---------------- ------------------- ----------------- ---------------------------------\n",
" 2023-07-04 14:59:52 0.010 sec 0 0.499994 0.693136 0.5 0.497648 1 0.502352 0.499902 0.692952 0.5 0.478079 1 0.521921\n",
" 2023-07-04 14:59:54 1.918 sec 5 0.317001 0.379458 0.997135 0.996714 2.00945 0.0146367 0.319118 0.382218 0.996742 0.996138 2.0917 0.0146138\n",
" 2023-07-04 14:59:56 4.088 sec 10 0.214609 0.233623 0.998206 0.998114 2.00945 0.0151594 0.221098 0.239548 0.997424 0.997032 2.0917 0.0146138\n",
" 2023-07-04 14:59:58 6.101 sec 15 0.157768 0.154888 0.998722 0.998675 2.00945 0.0125457 0.168889 0.1631 0.997039 0.996402 2.0917 0.0146138\n",
" 2023-07-04 15:00:02 9.930 sec 20 0.126215 0.108731 0.9991 0.999075 2.00945 0.0109775 0.140928 0.118223 0.996498 0.995323 2.0917 0.0146138\n",
" 2023-07-04 15:00:05 13.496 sec 25 0.11046 0.0815081 0.999224 0.99921 2.00945 0.00993204 0.127196 0.0916478 0.996865 0.995727 2.0917 0.0146138\n",
" 2023-07-04 15:00:07 15.525 sec 30 0.101352 0.0634996 0.999387 0.999374 2.00945 0.00993204 0.119332 0.0752788 0.997476 0.996986 2.0917 0.0125261\n",
" 2023-07-04 15:00:09 17.573 sec 35 0.0945492 0.0503921 0.999611 0.999608 2.00945 0.00888657 0.114573 0.0650235 0.996585 0.995229 2.0917 0.0104384\n",
" 2023-07-04 15:00:12 20.340 sec 40 0.0889221 0.0407836 0.999754 0.999752 2.00945 0.00888657 0.1115 0.0592395 0.995563 0.993609 2.0917 0.0104384\n",
" 2023-07-04 15:00:17 25.257 sec 45 0.0829407 0.0329961 0.999832 0.999831 2.00945 0.00784109 0.108017 0.0559146 0.994865 0.992609 2.0917 0.0104384\n",
" 2023-07-04 15:00:20 28.121 sec 50 0.0771245 0.0271945 0.99988 0.99988 2.00945 0.00627287 0.106927 0.0545321 0.99386 0.990723 2.0917 0.0104384\n",
" 2023-07-04 15:00:22 30.210 sec 55 0.071184 0.0224691 0.999931 0.999931 2.00945 0.00418191 0.108548 0.0538512 0.995293 0.993756 2.0917 0.0104384\n",
" 2023-07-04 15:00:25 33.090 sec 60 0.0636146 0.0183855 0.999968 0.999968 2.00945 0.0026137 0.108028 0.0527046 0.995607 0.994313 2.0917 0.0104384\n",
" 2023-07-04 15:00:29 37.689 sec 65 0.057888 0.0153107 0.999986 0.999986 2.00945 0.00156822 0.106962 0.0509253 0.99676 0.996044 2.0917 0.0104384\n",
" 2023-07-04 15:00:34 42.179 sec 70 0.0536202 0.013226 0.999989 0.999989 2.00945 0.00104548 0.108914 0.0530892 0.996166 0.995218 2.0917 0.0104384\n",
" 2023-07-04 15:00:36 44.307 sec 75 0.0479302 0.0112575 0.999991 0.999991 2.00945 0.00104548 0.109103 0.0528091 0.996638 0.99596 2.0917 0.0125261\n",
" 2023-07-04 15:00:38 46.507 sec 80 0.0435638 0.00963268 0.999995 0.999994 2.00945 0.00104548 0.109485 0.0529685 0.996777 0.996074 2.0917 0.0125261\n",
"\n",
"Variable Importances: \n",
"variable relative_importance scaled_importance percentage\n",
"---------- --------------------- -------------------- --------------------\n",
"178 1383.4979248046875 1.0 0.5584763797165689\n",
"28 436.0515441894531 0.3151804830144663 0.17602085511123866\n",
"1039 133.7706756591797 0.09669018887618823 0.05399918663768487\n",
"1036 127.7828369140625 0.09236214570549643 0.0515820767564599\n",
"445 105.94847106933594 0.0765801445522898 0.042768201887734336\n",
"849 78.66011047363281 0.056855965638501045 0.0317527138550797\n",
"481 49.12392044067383 0.035507043097017146 0.019829844883262327\n",
"88 30.747364044189453 0.022224365857672068 0.012411783385689216\n",
"333 22.4294376373291 0.016212122356812013 0.009054087401354423\n",
"1129 10.975905418395996 0.007933445523559781 0.004430641934676287\n",
"--- --- --- ---\n",
"1263 0.0 0.0 0.0\n",
"1265 0.0 0.0 0.0\n",
"1268 0.0 0.0 0.0\n",
"1271 0.0 0.0 0.0\n",
"1272 0.0 0.0 0.0\n",
"1273 0.0 0.0 0.0\n",
"1274 0.0 0.0 0.0\n",
"1275 0.0 0.0 0.0\n",
"1276 0.0 0.0 0.0\n",
"1279 0.0 0.0 0.0\n",
"[1280 rows x 4 columns]\n",
"\n"
]
}
]
}
]
}

Xet Storage Details

Size:
115 kB
·
Xet hash:
1631b1c56d8c61394439886be89566d5fd02f8b6a1e1cafe819b91c1a5ffad08

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.