{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "ddf867c1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2.3.4'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from pycaret.utils import version\n",
"version()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fbccb83d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" cycle | \n",
" state | \n",
" dem_poll_avg | \n",
" dem_poll_avg_margin | \n",
" incumbent_party | \n",
" incumbent_running | \n",
" party_winner | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1976 | \n",
" California | \n",
" 42.797994 | \n",
" -3.270222 | \n",
" republican | \n",
" 1 | \n",
" republican | \n",
"
\n",
" \n",
" 1 | \n",
" 1976 | \n",
" Colorado | \n",
" 42.180101 | \n",
" -1.373191 | \n",
" republican | \n",
" 1 | \n",
" republican | \n",
"
\n",
" \n",
" 2 | \n",
" 1976 | \n",
" Connecticut | \n",
" 41.698014 | \n",
" -1.469654 | \n",
" republican | \n",
" 1 | \n",
" republican | \n",
"
\n",
" \n",
" 3 | \n",
" 1976 | \n",
" Delaware | \n",
" 33.370748 | \n",
" 2.445322 | \n",
" republican | \n",
" 1 | \n",
" democrat | \n",
"
\n",
" \n",
" 4 | \n",
" 1976 | \n",
" Georgia | \n",
" 59.796546 | \n",
" 29.379760 | \n",
" republican | \n",
" 1 | \n",
" democrat | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" cycle state dem_poll_avg dem_poll_avg_margin incumbent_party \\\n",
"0 1976 California 42.797994 -3.270222 republican \n",
"1 1976 Colorado 42.180101 -1.373191 republican \n",
"2 1976 Connecticut 41.698014 -1.469654 republican \n",
"3 1976 Delaware 33.370748 2.445322 republican \n",
"4 1976 Georgia 59.796546 29.379760 republican \n",
"\n",
" incumbent_running party_winner \n",
"0 1 republican \n",
"1 1 republican \n",
"2 1 republican \n",
"3 1 democrat \n",
"4 1 democrat "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from pycaret.datasets import get_data\n",
"data = get_data('us_presidential_election_results')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "5cb4297f",
"metadata": {},
"outputs": [],
"source": [
"data.cycle = data.cycle.astype('float64')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c69bed71",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZ4AAAD4CAYAAADcpoD8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAN4ElEQVR4nO3cf4xlZ13H8feH3bIFW0vLVrIWZFqyUquU2q5IsRREQaBqMaApGG0i2iiYKEn/qGkgbTRxMdEgkRZLRH6IUKkQKgQFoQg0FLq7dLtby9JKl2CtrRVYkF9C+/WP+wxc1p3Zmdnd790Z3q9kMueec+65zzNndt89595uqgpJkro8ZNYDkCR9bzE8kqRWhkeS1MrwSJJaGR5JUqv1sx7A0WTjxo01Nzc362FI0qqyffv2+6vq5KXub3imzM3NsW3btlkPQ5JWlSSfXc7+3mqTJLUyPJKkVoZHktTK8EiSWhkeSVIrwyNJamV4JEmtDI8kqZXhkSS1MjySpFaGR5LUyvBIkloZHklSK8MjSWpleCRJrQyPJKmV4ZEktTI8kqRWhkeS1MrwSJJaGR5JUivDI0lqZXgkSa0MjySpleGRJLUyPJKkVutnPYCjya679zF32XtmPQxJw96tF8x6CDoCvOKRJLUyPJKkVoZHktTK8EiSWhkeSVIrwyNJamV4JEmtDI8kqZXhkSS1MjySpFaGR5LUyvBIkloZHklSK8MjSWpleCRJrQyPJKmV4ZEktTI8kqRWhkeS1MrwSJJa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BN5WVd+oqruAO5n8/h6Vquqeqtoxlr8M3A6cwho4d4vMbSGr5tyNn///jIfHjK8CngFcN9bvf97mz+d1wM8kyWKvYXgmvyyfm3r87yz+C7QaFPC+JNuTXDLWPaqq7hnL/wk8ajZDO2wWms9aOZ+/O243vX7qtuiqndu4/fLjTP7reU2du/3mBmvg3CVZl+QW4D7g/Uyu0L5YVd8au0yP/9tzG9v3AY9c7PiGZ206r6rOBp4DvDTJ+dMba3JNvGY+R7/W5gNcDTwOOAu4B/jTmY7mECU5Dvh74Per6kvT21b7uTvA3NbEuauqB6rqLODRTK7MTj+cxzc8cDfwmKnHjx7rVq2qunt8vw94J5NfnHvnb1uM7/fNboSHxULzWfXns6ruHX/wHwRex3duyay6uSU5hslfzG+pqneM1Wvi3B1obmvp3AFU1ReBG4Bzmdz6nP/3PafH/+25je0nAP+92HEND9wMbB6f2HgokzfHrp/xmFYsyfclOX5+GXgWsJvJnC4eu10MvGs2IzxsFprP9cCvj09IPRnYN3VbZ1XY732NX2Jy/mAyt4vGp4hOBTYDn+ge31KN+/x/BdxeVX82tWnVn7uF5rYWzl2Sk5M8Yiw/DHgmk/ewbgBeMHbb/7zNn88XAB8cV7ILm/UnKI6GLyafpvk0k/uYl896PIc4l9OYfHpmJ3Db/HyY3HP9AHAH8M/ASbMe6zLm9FYmty2+yeTe8osXmg+TT+S8ZpzLXcCWWY9/BXN78xj7reMP9aap/S8fc9sDPGfW4z/I3M5jchvtVuCW8fXctXDuFpnbqj93wJnAJ8ccdgOvGOtPYxLLO4G3AxvG+mPH4zvH9tMO9hr+kzmSpFbeapMktTI8kqRWhkeS1MrwSJJaGR5JUivDI0lqZXgkSa3+DzLrLt6H174nAAAAAElFTkSuQmCC\n",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"data.party_winner.value_counts().plot.barh()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "104383c7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | \n",
" Description | \n",
" Value | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" session_id | \n",
" 123 | \n",
"
\n",
" \n",
" 1 | \n",
" Target | \n",
" party_winner | \n",
"
\n",
" \n",
" 2 | \n",
" Target Type | \n",
" Binary | \n",
"
\n",
" \n",
" 3 | \n",
" Label Encoded | \n",
" democrat: 0, republican: 1 | \n",
"
\n",
" \n",
" 4 | \n",
" Original Data | \n",
" (497, 7) | \n",
"
\n",
" \n",
" 5 | \n",
" Missing Values | \n",
" False | \n",
"
\n",
" \n",
" 6 | \n",
" Numeric Features | \n",
" 3 | \n",
"
\n",
" \n",
" 7 | \n",
" Categorical Features | \n",
" 3 | \n",
"
\n",
" \n",
" 8 | \n",
" Ordinal Features | \n",
" False | \n",
"
\n",
" \n",
" 9 | \n",
" High Cardinality Features | \n",
" False | \n",
"
\n",
" \n",
" 10 | \n",
" High Cardinality Method | \n",
" None | \n",
"
\n",
" \n",
" 11 | \n",
" Transformed Train Set | \n",
" (347, 56) | \n",
"
\n",
" \n",
" 12 | \n",
" Transformed Test Set | \n",
" (150, 56) | \n",
"
\n",
" \n",
" 13 | \n",
" Shuffle Train-Test | \n",
" True | \n",
"
\n",
" \n",
" 14 | \n",
" Stratify Train-Test | \n",
" False | \n",
"
\n",
" \n",
" 15 | \n",
" Fold Generator | \n",
" StratifiedKFold | \n",
"
\n",
" \n",
" 16 | \n",
" Fold Number | \n",
" 10 | \n",
"
\n",
" \n",
" 17 | \n",
" CPU Jobs | \n",
" -1 | \n",
"
\n",
" \n",
" 18 | \n",
" Use GPU | \n",
" False | \n",
"
\n",
" \n",
" 19 | \n",
" Log Experiment | \n",
" True | \n",
"
\n",
" \n",
" 20 | \n",
" Experiment Name | \n",
" us_election_model | \n",
"
\n",
" \n",
" 21 | \n",
" USI | \n",
" 581f | \n",
"
\n",
" \n",
" 22 | \n",
" Imputation Type | \n",
" simple | \n",
"
\n",
" \n",
" 23 | \n",
" Iterative Imputation Iteration | \n",
" None | \n",
"
\n",
" \n",
" 24 | \n",
" Numeric Imputer | \n",
" mean | \n",
"
\n",
" \n",
" 25 | \n",
" Iterative Imputation Numeric Model | \n",
" None | \n",
"
\n",
" \n",
" 26 | \n",
" Categorical Imputer | \n",
" constant | \n",
"
\n",
" \n",
" 27 | \n",
" Iterative Imputation Categorical Model | \n",
" None | \n",
"
\n",
" \n",
" 28 | \n",
" Unknown Categoricals Handling | \n",
" least_frequent | \n",
"
\n",
" \n",
" 29 | \n",
" Normalize | \n",
" False | \n",
"
\n",
" \n",
" 30 | \n",
" Normalize Method | \n",
" None | \n",
"
\n",
" \n",
" 31 | \n",
" Transformation | \n",
" False | \n",
"
\n",
" \n",
" 32 | \n",
" Transformation Method | \n",
" None | \n",
"
\n",
" \n",
" 33 | \n",
" PCA | \n",
" False | \n",
"
\n",
" \n",
" 34 | \n",
" PCA Method | \n",
" None | \n",
"
\n",
" \n",
" 35 | \n",
" PCA Components | \n",
" None | \n",
"
\n",
" \n",
" 36 | \n",
" Ignore Low Variance | \n",
" False | \n",
"
\n",
" \n",
" 37 | \n",
" Combine Rare Levels | \n",
" False | \n",
"
\n",
" \n",
" 38 | \n",
" Rare Level Threshold | \n",
" None | \n",
"
\n",
" \n",
" 39 | \n",
" Numeric Binning | \n",
" False | \n",
"
\n",
" \n",
" 40 | \n",
" Remove Outliers | \n",
" False | \n",
"
\n",
" \n",
" 41 | \n",
" Outliers Threshold | \n",
" None | \n",
"
\n",
" \n",
" 42 | \n",
" Remove Multicollinearity | \n",
" False | \n",
"
\n",
" \n",
" 43 | \n",
" Multicollinearity Threshold | \n",
" None | \n",
"
\n",
" \n",
" 44 | \n",
" Remove Perfect Collinearity | \n",
" True | \n",
"
\n",
" \n",
" 45 | \n",
" Clustering | \n",
" False | \n",
"
\n",
" \n",
" 46 | \n",
" Clustering Iteration | \n",
" None | \n",
"
\n",
" \n",
" 47 | \n",
" Polynomial Features | \n",
" False | \n",
"
\n",
" \n",
" 48 | \n",
" Polynomial Degree | \n",
" None | \n",
"
\n",
" \n",
" 49 | \n",
" Trignometry Features | \n",
" False | \n",
"
\n",
" \n",
" 50 | \n",
" Polynomial Threshold | \n",
" None | \n",
"
\n",
" \n",
" 51 | \n",
" Group Features | \n",
" False | \n",
"
\n",
" \n",
" 52 | \n",
" Feature Selection | \n",
" False | \n",
"
\n",
" \n",
" 53 | \n",
" Feature Selection Method | \n",
" classic | \n",
"
\n",
" \n",
" 54 | \n",
" Features Selection Threshold | \n",
" None | \n",
"
\n",
" \n",
" 55 | \n",
" Feature Interaction | \n",
" False | \n",
"
\n",
" \n",
" 56 | \n",
" Feature Ratio | \n",
" False | \n",
"
\n",
" \n",
" 57 | \n",
" Interaction Threshold | \n",
" None | \n",
"
\n",
" \n",
" 58 | \n",
" Fix Imbalance | \n",
" False | \n",
"
\n",
" \n",
" 59 | \n",
" Fix Imbalance Method | \n",
" SMOTE | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from pycaret.classification import *\n",
"s = setup(data, target = 'party_winner', session_id = 123,\n",
" log_experiment=True, log_plots=True, experiment_name = 'us_election_model')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "06771216",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | \n",
" Model | \n",
" Accuracy | \n",
" AUC | \n",
" Recall | \n",
" Prec. | \n",
" F1 | \n",
" Kappa | \n",
" MCC | \n",
" TT (Sec) | \n",
"
\n",
" \n",
" \n",
" \n",
" catboost | \n",
" CatBoost Classifier | \n",
" 0.9366 | \n",
" 0.9907 | \n",
" 0.9462 | \n",
" 0.9511 | \n",
" 0.9465 | \n",
" 0.8680 | \n",
" 0.8737 | \n",
" 0.5080 | \n",
"
\n",
" \n",
" xgboost | \n",
" Extreme Gradient Boosting | \n",
" 0.9363 | \n",
" 0.9857 | \n",
" 0.9405 | \n",
" 0.9552 | \n",
" 0.9445 | \n",
" 0.8693 | \n",
" 0.8771 | \n",
" 0.0640 | \n",
"
\n",
" \n",
" rf | \n",
" Random Forest Classifier | \n",
" 0.9307 | \n",
" 0.9887 | \n",
" 0.9314 | \n",
" 0.9543 | \n",
" 0.9403 | \n",
" 0.8572 | \n",
" 0.8634 | \n",
" 0.0680 | \n",
"
\n",
" \n",
" gbc | \n",
" Gradient Boosting Classifier | \n",
" 0.9219 | \n",
" 0.9823 | \n",
" 0.9169 | \n",
" 0.9525 | \n",
" 0.9318 | \n",
" 0.8403 | \n",
" 0.8461 | \n",
" 0.0280 | \n",
"
\n",
" \n",
" lightgbm | \n",
" Light Gradient Boosting Machine | \n",
" 0.9219 | \n",
" 0.9752 | \n",
" 0.9260 | \n",
" 0.9461 | \n",
" 0.9327 | \n",
" 0.8390 | \n",
" 0.8466 | \n",
" 0.0450 | \n",
"
\n",
" \n",
" dt | \n",
" Decision Tree Classifier | \n",
" 0.9191 | \n",
" 0.9171 | \n",
" 0.9267 | \n",
" 0.9419 | \n",
" 0.9314 | \n",
" 0.8321 | \n",
" 0.8388 | \n",
" 0.0040 | \n",
"
\n",
" \n",
" knn | \n",
" K Neighbors Classifier | \n",
" 0.9166 | \n",
" 0.9776 | \n",
" 0.9512 | \n",
" 0.9193 | \n",
" 0.9318 | \n",
" 0.8235 | \n",
" 0.8344 | \n",
" 0.0090 | \n",
"
\n",
" \n",
" et | \n",
" Extra Trees Classifier | \n",
" 0.9135 | \n",
" 0.9773 | \n",
" 0.9174 | \n",
" 0.9400 | \n",
" 0.9267 | \n",
" 0.8209 | \n",
" 0.8262 | \n",
" 0.0620 | \n",
"
\n",
" \n",
" lr | \n",
" Logistic Regression | \n",
" 0.9108 | \n",
" 0.9842 | \n",
" 0.9319 | \n",
" 0.9244 | \n",
" 0.9254 | \n",
" 0.8139 | \n",
" 0.8216 | \n",
" 0.0100 | \n",
"
\n",
" \n",
" ada | \n",
" Ada Boost Classifier | \n",
" 0.9021 | \n",
" 0.9513 | \n",
" 0.9171 | \n",
" 0.9237 | \n",
" 0.9168 | \n",
" 0.7968 | \n",
" 0.8060 | \n",
" 0.0260 | \n",
"
\n",
" \n",
" lda | \n",
" Linear Discriminant Analysis | \n",
" 0.8934 | \n",
" 0.9455 | \n",
" 0.8971 | \n",
" 0.9273 | \n",
" 0.9087 | \n",
" 0.7793 | \n",
" 0.7881 | \n",
" 0.0050 | \n",
"
\n",
" \n",
" ridge | \n",
" Ridge Classifier | \n",
" 0.8933 | \n",
" 0.0000 | \n",
" 0.9019 | \n",
" 0.9220 | \n",
" 0.9088 | \n",
" 0.7790 | \n",
" 0.7870 | \n",
" 0.0040 | \n",
"
\n",
" \n",
" nb | \n",
" Naive Bayes | \n",
" 0.6741 | \n",
" 0.8407 | \n",
" 0.4895 | \n",
" 0.9340 | \n",
" 0.6353 | \n",
" 0.3921 | \n",
" 0.4623 | \n",
" 0.0040 | \n",
"
\n",
" \n",
" svm | \n",
" SVM - Linear Kernel | \n",
" 0.6690 | \n",
" 0.0000 | \n",
" 0.7857 | \n",
" 0.5749 | \n",
" 0.6567 | \n",
" 0.3088 | \n",
" 0.3635 | \n",
" 0.0050 | \n",
"
\n",
" \n",
" qda | \n",
" Quadratic Discriminant Analysis | \n",
" 0.6626 | \n",
" 0.7844 | \n",
" 0.4700 | \n",
" 0.9315 | \n",
" 0.6158 | \n",
" 0.3735 | \n",
" 0.4464 | \n",
" 0.0050 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"best = compare_models()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "0fa76e08",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ccd5c31bec374416892c4c93781703aa",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(ToggleButtons(description='Plot Type:', icons=('',), options=(('Hyperparameters', 'param…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"evaluate_model(best)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "964429f6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | \n",
" Accuracy | \n",
" AUC | \n",
" Recall | \n",
" Prec. | \n",
" F1 | \n",
" Kappa | \n",
" MCC | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.9429 | \n",
" 0.9796 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.8810 | \n",
" 0.8810 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.8857 | \n",
" 0.9864 | \n",
" 0.9524 | \n",
" 0.8696 | \n",
" 0.9091 | \n",
" 0.7561 | \n",
" 0.7618 | \n",
"
\n",
" \n",
" 2 | \n",
" 0.9714 | \n",
" 0.9932 | \n",
" 1.0000 | \n",
" 0.9545 | \n",
" 0.9767 | \n",
" 0.9398 | \n",
" 0.9415 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.9143 | \n",
" 0.9320 | \n",
" 1.0000 | \n",
" 0.8750 | \n",
" 0.9333 | \n",
" 0.8148 | \n",
" 0.8292 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.9143 | \n",
" 0.9728 | \n",
" 0.9048 | \n",
" 0.9500 | \n",
" 0.9268 | \n",
" 0.8235 | \n",
" 0.8250 | \n",
"
\n",
" \n",
" 5 | \n",
" 0.9714 | \n",
" 0.9456 | \n",
" 1.0000 | \n",
" 0.9545 | \n",
" 0.9767 | \n",
" 0.9398 | \n",
" 0.9415 | \n",
"
\n",
" \n",
" 6 | \n",
" 0.9429 | \n",
" 1.0000 | \n",
" 0.9000 | \n",
" 1.0000 | \n",
" 0.9474 | \n",
" 0.8852 | \n",
" 0.8911 | \n",
"
\n",
" \n",
" 7 | \n",
" 0.8824 | \n",
" 0.9821 | \n",
" 0.8000 | \n",
" 1.0000 | \n",
" 0.8889 | \n",
" 0.7671 | \n",
" 0.7888 | \n",
"
\n",
" \n",
" 8 | \n",
" 0.8824 | \n",
" 0.9821 | \n",
" 0.8000 | \n",
" 1.0000 | \n",
" 0.8889 | \n",
" 0.7671 | \n",
" 0.7888 | \n",
"
\n",
" \n",
" 9 | \n",
" 0.9118 | \n",
" 0.9786 | \n",
" 0.9500 | \n",
" 0.9048 | \n",
" 0.9268 | \n",
" 0.8159 | \n",
" 0.8174 | \n",
"
\n",
" \n",
" Mean | \n",
" 0.9219 | \n",
" 0.9752 | \n",
" 0.9260 | \n",
" 0.9461 | \n",
" 0.9327 | \n",
" 0.8390 | \n",
" 0.8466 | \n",
"
\n",
" \n",
" SD | \n",
" 0.0323 | \n",
" 0.0199 | \n",
" 0.0716 | \n",
" 0.0464 | \n",
" 0.0299 | \n",
" 0.0654 | \n",
" 0.0605 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lightgbm = create_model('lightgbm')"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "aba9e706",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | \n",
" Accuracy | \n",
" AUC | \n",
" Recall | \n",
" Prec. | \n",
" F1 | \n",
" Kappa | \n",
" MCC | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.8571 | \n",
" 0.8333 | \n",
" 0.9524 | \n",
" 0.8333 | \n",
" 0.8889 | \n",
" 0.6914 | \n",
" 0.7035 | \n",
"
\n",
" \n",
" 2 | \n",
" 0.9714 | \n",
" 0.9762 | \n",
" 0.9524 | \n",
" 1.0000 | \n",
" 0.9756 | \n",
" 0.9412 | \n",
" 0.9428 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.8857 | \n",
" 0.8690 | \n",
" 0.9524 | \n",
" 0.8696 | \n",
" 0.9091 | \n",
" 0.7561 | \n",
" 0.7618 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.8857 | \n",
" 0.8929 | \n",
" 0.8571 | \n",
" 0.9474 | \n",
" 0.9000 | \n",
" 0.7674 | \n",
" 0.7727 | \n",
"
\n",
" \n",
" 5 | \n",
" 0.9429 | \n",
" 0.9405 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.8810 | \n",
" 0.8810 | \n",
"
\n",
" \n",
" 6 | \n",
" 0.9714 | \n",
" 0.9667 | \n",
" 1.0000 | \n",
" 0.9524 | \n",
" 0.9756 | \n",
" 0.9412 | \n",
" 0.9428 | \n",
"
\n",
" \n",
" 7 | \n",
" 0.8824 | \n",
" 0.9000 | \n",
" 0.8000 | \n",
" 1.0000 | \n",
" 0.8889 | \n",
" 0.7671 | \n",
" 0.7888 | \n",
"
\n",
" \n",
" 8 | \n",
" 0.9118 | \n",
" 0.9250 | \n",
" 0.8500 | \n",
" 1.0000 | \n",
" 0.9189 | \n",
" 0.8235 | \n",
" 0.8367 | \n",
"
\n",
" \n",
" 9 | \n",
" 0.8824 | \n",
" 0.8679 | \n",
" 0.9500 | \n",
" 0.8636 | \n",
" 0.9048 | \n",
" 0.7518 | \n",
" 0.7577 | \n",
"
\n",
" \n",
" Mean | \n",
" 0.9191 | \n",
" 0.9171 | \n",
" 0.9267 | \n",
" 0.9419 | \n",
" 0.9314 | \n",
" 0.8321 | \n",
" 0.8388 | \n",
"
\n",
" \n",
" SD | \n",
" 0.0463 | \n",
" 0.0510 | \n",
" 0.0638 | \n",
" 0.0607 | \n",
" 0.0388 | \n",
" 0.0974 | \n",
" 0.0933 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dt = create_model('dt')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "4d38de73",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | \n",
" Accuracy | \n",
" AUC | \n",
" Recall | \n",
" Prec. | \n",
" F1 | \n",
" Kappa | \n",
" MCC | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.9714 | \n",
" 0.9949 | \n",
" 0.9524 | \n",
" 1.0000 | \n",
" 0.9756 | \n",
" 0.9412 | \n",
" 0.9428 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.8857 | \n",
" 0.9847 | \n",
" 0.9524 | \n",
" 0.8696 | \n",
" 0.9091 | \n",
" 0.7561 | \n",
" 0.7618 | \n",
"
\n",
" \n",
" 2 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
" 1.0000 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.8857 | \n",
" 0.8827 | \n",
" 0.9524 | \n",
" 0.8696 | \n",
" 0.9091 | \n",
" 0.7561 | \n",
" 0.7618 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.8571 | \n",
" 0.9320 | \n",
" 0.8095 | \n",
" 0.9444 | \n",
" 0.8718 | \n",
" 0.7126 | \n",
" 0.7235 | \n",
"
\n",
" \n",
" 5 | \n",
" 0.9429 | \n",
" 0.9609 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.8810 | \n",
" 0.8810 | \n",
"
\n",
" \n",
" 6 | \n",
" 0.8571 | \n",
" 0.9517 | \n",
" 0.9000 | \n",
" 0.8571 | \n",
" 0.8780 | \n",
" 0.7059 | \n",
" 0.7071 | \n",
"
\n",
" \n",
" 7 | \n",
" 0.9118 | \n",
" 0.9518 | \n",
" 0.8500 | \n",
" 1.0000 | \n",
" 0.9189 | \n",
" 0.8235 | \n",
" 0.8367 | \n",
"
\n",
" \n",
" 8 | \n",
" 0.9118 | \n",
" 0.9250 | \n",
" 0.8500 | \n",
" 1.0000 | \n",
" 0.9189 | \n",
" 0.8235 | \n",
" 0.8367 | \n",
"
\n",
" \n",
" 9 | \n",
" 0.8824 | \n",
" 0.9839 | \n",
" 0.9500 | \n",
" 0.8636 | \n",
" 0.9048 | \n",
" 0.7518 | \n",
" 0.7577 | \n",
"
\n",
" \n",
" Mean | \n",
" 0.9106 | \n",
" 0.9567 | \n",
" 0.9169 | \n",
" 0.9357 | \n",
" 0.9239 | \n",
" 0.8152 | \n",
" 0.8209 | \n",
"
\n",
" \n",
" SD | \n",
" 0.0453 | \n",
" 0.0347 | \n",
" 0.0581 | \n",
" 0.0608 | \n",
" 0.0387 | \n",
" 0.0938 | \n",
" 0.0919 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tuned_dt = tune_model(dt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb389034",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 35,
"id": "05990fcd",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | \n",
" Accuracy | \n",
" AUC | \n",
" Recall | \n",
" Prec. | \n",
" F1 | \n",
" Kappa | \n",
" MCC | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0.8857 | \n",
" 0.9694 | \n",
" 0.9048 | \n",
" 0.9048 | \n",
" 0.9048 | \n",
" 0.7619 | \n",
" 0.7619 | \n",
"
\n",
" \n",
" 1 | \n",
" 0.8571 | \n",
" 0.9320 | \n",
" 0.9524 | \n",
" 0.8333 | \n",
" 0.8889 | \n",
" 0.6914 | \n",
" 0.7035 | \n",
"
\n",
" \n",
" 2 | \n",
" 0.9429 | \n",
" 0.9966 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.9524 | \n",
" 0.8810 | \n",
" 0.8810 | \n",
"
\n",
" \n",
" 3 | \n",
" 0.9143 | \n",
" 0.9490 | \n",
" 1.0000 | \n",
" 0.8750 | \n",
" 0.9333 | \n",
" 0.8148 | \n",
" 0.8292 | \n",
"
\n",
" \n",
" 4 | \n",
" 0.9143 | \n",
" 0.9728 | \n",
" 0.9048 | \n",
" 0.9500 | \n",
" 0.9268 | \n",
" 0.8235 | \n",
" 0.8250 | \n",
"
\n",
" \n",
" 5 | \n",
" 0.9714 | \n",
" 0.9354 | \n",
" 1.0000 | \n",
" 0.9545 | \n",
" 0.9767 | \n",
" 0.9398 | \n",
" 0.9415 | \n",
"
\n",
" \n",
" 6 | \n",
" 0.9429 | \n",
" 1.0000 | \n",
" 0.9000 | \n",
" 1.0000 | \n",
" 0.9474 | \n",
" 0.8852 | \n",
" 0.8911 | \n",
"
\n",
" \n",
" 7 | \n",
" 0.9118 | \n",
" 0.9857 | \n",
" 0.8500 | \n",
" 1.0000 | \n",
" 0.9189 | \n",
" 0.8235 | \n",
" 0.8367 | \n",
"
\n",
" \n",
" 8 | \n",
" 0.8824 | \n",
" 0.9786 | \n",
" 0.8000 | \n",
" 1.0000 | \n",
" 0.8889 | \n",
" 0.7671 | \n",
" 0.7888 | \n",
"
\n",
" \n",
" 9 | \n",
" 0.9412 | \n",
" 0.9607 | \n",
" 1.0000 | \n",
" 0.9091 | \n",
" 0.9524 | \n",
" 0.8759 | \n",
" 0.8827 | \n",
"
\n",
" \n",
" Mean | \n",
" 0.9164 | \n",
" 0.9680 | \n",
" 0.9264 | \n",
" 0.9379 | \n",
" 0.9290 | \n",
" 0.8264 | \n",
" 0.8341 | \n",
"
\n",
" \n",
" SD | \n",
" 0.0327 | \n",
" 0.0225 | \n",
" 0.0641 | \n",
" 0.0539 | \n",
" 0.0276 | \n",
" 0.0691 | \n",
" 0.0662 | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lgbs = []\n",
"for i in [0.1,0.2,0.3,0.4,0.5]:\n",
" lgbs.append(create_model('lightgbm', learning_rate = i))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f6b5fd9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b048aba",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 26,
"id": "f943727d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"^C\n"
]
}
],
"source": [
"!mlflow ui"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6bb40f21",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "pycaret-new",
"language": "python",
"name": "pycaret-new"
},
"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.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}