199 lines
7.4 KiB
Plaintext
199 lines
7.4 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "b90a9f64-8f6c-4766-949c-2d2b5b2f5cfb",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
" precision recall f1-score support\n",
|
||
"\n",
|
||
" 0 1.00 1.00 1.00 11\n",
|
||
" 1 1.00 0.50 0.67 12\n",
|
||
" 2 0.54 1.00 0.70 7\n",
|
||
"\n",
|
||
" accuracy 0.80 30\n",
|
||
" macro avg 0.85 0.83 0.79 30\n",
|
||
"weighted avg 0.89 0.80 0.80 30\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"name": "stderr",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"D:\\Practice4\\.venv\\Lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:691: 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": "31c17449-d620-449b-ad0d-12375f567a70",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
" precision recall f1-score support\n",
|
||
"\n",
|
||
" 0 0.89 1.00 0.94 8\n",
|
||
" 1 0.38 0.89 0.53 9\n",
|
||
" 2 0.00 0.00 0.00 13\n",
|
||
"\n",
|
||
" accuracy 0.53 30\n",
|
||
" macro avg 0.42 0.63 0.49 30\n",
|
||
"weighted avg 0.35 0.53 0.41 30\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"name": "stderr",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"D:\\Practice4\\.venv\\Lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn't converged yet.\n",
|
||
" warnings.warn(\n",
|
||
"D:\\Practice4\\.venv\\Lib\\site-packages\\sklearn\\metrics\\_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
|
||
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n",
|
||
"D:\\Practice4\\.venv\\Lib\\site-packages\\sklearn\\metrics\\_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
|
||
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\n",
|
||
"D:\\Practice4\\.venv\\Lib\\site-packages\\sklearn\\metrics\\_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
|
||
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", len(result))\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=100)\n",
|
||
"clf.fit(X_train, y_train)\n",
|
||
"\n",
|
||
"# Отчёт о точности\n",
|
||
"print(classification_report(y_test, clf.predict(X_test)))"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"id": "5642dd14-042f-4895-ad2c-e04c919db0ed",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
" precision recall f1-score support\n",
|
||
"\n",
|
||
" 0 1.00 1.00 1.00 10\n",
|
||
" 1 1.00 1.00 1.00 7\n",
|
||
" 2 1.00 1.00 1.00 13\n",
|
||
"\n",
|
||
" accuracy 1.00 30\n",
|
||
" macro avg 1.00 1.00 1.00 30\n",
|
||
"weighted avg 1.00 1.00 1.00 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": 1,
|
||
"id": "60f55406-d189-4b57-90d0-f0393235e99b",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import numpy as np\n",
|
||
"import matplotlib.pyplot as plt\n",
|
||
"import pandas as pd\n",
|
||
"import openml\n",
|
||
"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, accuracy_score\n",
|
||
"from sklearn.preprocessing import StandardScaler\n",
|
||
"from sklearn.pipeline import make_pipeline\n",
|
||
"from sklearn.inspection import PartialDependenceDisplay"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "662ac0f8-7b50-42f3-b372-7c41aea3619e",
|
||
"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.3"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|