164 lines
5.0 KiB
Plaintext
164 lines
5.0 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "6c3666d4-5898-4253-90ed-a4750c2e1306",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
" precision recall f1-score support\n",
|
||
"\n",
|
||
" 0 1.00 1.00 1.00 12\n",
|
||
" 1 1.00 0.89 0.94 9\n",
|
||
" 2 0.90 1.00 0.95 9\n",
|
||
"\n",
|
||
" accuracy 0.97 30\n",
|
||
" macro avg 0.97 0.96 0.96 30\n",
|
||
"weighted avg 0.97 0.97 0.97 30\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"name": "stderr",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"C:\\Users\\timsh\\PycharmProjects\\4444\\.venv\\Lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:785: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (500) reached and the optimization hasn't converged yet.\n",
|
||
" warnings.warn(\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"from sklearn.datasets import load_iris\n",
|
||
"from sklearn.model_selection import train_test_split\n",
|
||
"from sklearn.neural_network import MLPClassifier\n",
|
||
"from sklearn.metrics import classification_report\n",
|
||
"\n",
|
||
"# Загрузка и разбиение данных\n",
|
||
"X, y = load_iris(return_X_y=True)\n",
|
||
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||
"\n",
|
||
"# Модель MLP — многослойный перцептрон\n",
|
||
"clf = MLPClassifier(hidden_layer_sizes=(10,), activation='relu', max_iter=500)\n",
|
||
"clf.fit(X_train, y_train)\n",
|
||
"\n",
|
||
"# Отчёт о точности\n",
|
||
"print(classification_report(y_test, clf.predict(X_test)))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"id": "182f69f2-a498-4adc-b06d-f8cbc6979c1d",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"ename": "NameError",
|
||
"evalue": "name 'sd' is not defined",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
||
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
|
||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m sd\n",
|
||
"\u001b[31mNameError\u001b[39m: name 'sd' is not defined"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"sd"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"id": "96a73d41-6a38-4608-9f77-bd442dfcafd1",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdin",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"Once deleted, variables cannot be recovered. Proceed (y/[n])? y\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"reset\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 7,
|
||
"id": "51de2ae0-7584-47c2-a5a3-27f546bc6f1d",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
" precision recall f1-score support\n",
|
||
"\n",
|
||
" 0 1.00 1.00 1.00 9\n",
|
||
" 1 1.00 0.91 0.95 11\n",
|
||
" 2 0.91 1.00 0.95 10\n",
|
||
"\n",
|
||
" accuracy 0.97 30\n",
|
||
" macro avg 0.97 0.97 0.97 30\n",
|
||
"weighted avg 0.97 0.97 0.97 30\n",
|
||
"\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"from sklearn.datasets import load_iris\n",
|
||
"from sklearn.model_selection import train_test_split\n",
|
||
"from sklearn.neural_network import MLPClassifier\n",
|
||
"from sklearn.metrics import classification_report\n",
|
||
"\n",
|
||
"# Загрузка и разбиение данных\n",
|
||
"X, y = load_iris(return_X_y=True)\n",
|
||
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||
"\n",
|
||
"# Модель MLP — многослойный перцептрон\n",
|
||
"clf = MLPClassifier(hidden_layer_sizes=(10,), activation='relu', max_iter=2500)\n",
|
||
"clf.fit(X_train, y_train)\n",
|
||
"\n",
|
||
"# Отчёт о точности\n",
|
||
"print(classification_report(y_test, clf.predict(X_test)))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "9f58322b-0064-4173-88fd-1c173a9bf3a9",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3 (ipykernel)",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.13.7"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|