Files
Mastering-Python-2e-code_2/CH_16_machine_learning/T_08_tpot.ipynb
T
2022-05-05 18:25:55 +02:00

77 lines
1.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "1583265b",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ab87f56987a44663ae7c8fd3192247b6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Optimization Progress: 0%| | 0/100 [00:00<?, ?pipeline/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"TPOT closed during evaluation in one generation.\n",
"WARNING: TPOT may not provide a good pipeline if TPOT is stopped/interrupted in a early generation.\n",
"\n",
"\n",
"TPOT closed prematurely. Will use the current best pipeline.\n",
"\n",
"Best pipeline: MultinomialNB(VarianceThreshold(input_matrix, threshold=0.2), alpha=0.01, fit_prior=False)\n",
"0.9473684210526315\n"
]
}
],
"source": [
"import tpot\n",
"from sklearn.datasets import load_iris\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"iris = load_iris()\n",
"X_train, X_test, y_train, y_test = train_test_split(\n",
" iris.data, iris.target, train_size=0.75, test_size=0.25)\n",
"\n",
"tpot = tpot.TPOTClassifier(verbosity=2, max_time_mins=10)\n",
"tpot.fit(X_train, y_train)\n",
"print(tpot.score(X_test, y_test))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}