Выполнено задание для базовой нейросети

This commit is contained in:
Александр Свекровин 2025-05-14 01:53:05 +03:00
parent 472f1f1a07
commit ac41b0eb7a
2 changed files with 208 additions and 0 deletions

View File

@ -0,0 +1,104 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6af36011-9a8c-4dc1-85c5-910263c2d25e",
"metadata": {},
"source": [
"Базовая нейросеть"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2115d6e8-d6d0-4025-9ee0-32c46b20fe45",
"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 9\n",
" 2 1.00 1.00 1.00 11\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.preprocessing import StandardScaler\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, random_state=42)\n",
"\n",
"# Нормализация данных\n",
"scaler = StandardScaler()\n",
"X_train = scaler.fit_transform(X_train)\n",
"X_test = scaler.transform(X_test)\n",
"\n",
"# Модель MLP — многослойный перцептрон\n",
"clf = MLPClassifier(hidden_layer_sizes=(10,), activation='relu', max_iter=2500, learning_rate_init=0.001, random_state=42)\n",
"clf.fit(X_train, y_train)\n",
"\n",
"# Отчёт о точности\n",
"print(classification_report(y_test, clf.predict(X_test)))\n"
]
},
{
"cell_type": "markdown",
"id": "125b3f46-cc81-4341-94f3-9de6dee8aff5",
"metadata": {},
"source": [
"Модель работает очень хорошо и достигла 100% точности на тестовых данных, что является отличным результатом для этого набора данных."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d032afd-fc98-48cd-9ec8-7a742fcf8a50",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "62c7892d-b296-4f0c-8886-514b4ee2bad6",
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -0,0 +1,104 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6af36011-9a8c-4dc1-85c5-910263c2d25e",
"metadata": {},
"source": [
"Базовая нейросеть"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2115d6e8-d6d0-4025-9ee0-32c46b20fe45",
"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 9\n",
" 2 1.00 1.00 1.00 11\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.preprocessing import StandardScaler\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, random_state=42)\n",
"\n",
"# Нормализация данных\n",
"scaler = StandardScaler()\n",
"X_train = scaler.fit_transform(X_train)\n",
"X_test = scaler.transform(X_test)\n",
"\n",
"# Модель MLP — многослойный перцептрон\n",
"clf = MLPClassifier(hidden_layer_sizes=(10,), activation='relu', max_iter=2500, learning_rate_init=0.001, random_state=42)\n",
"clf.fit(X_train, y_train)\n",
"\n",
"# Отчёт о точности\n",
"print(classification_report(y_test, clf.predict(X_test)))\n"
]
},
{
"cell_type": "markdown",
"id": "125b3f46-cc81-4341-94f3-9de6dee8aff5",
"metadata": {},
"source": [
"Модель работает очень хорошо и достигла 100% точности на тестовых данных, что является отличным результатом для этого набора данных."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d032afd-fc98-48cd-9ec8-7a742fcf8a50",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "62c7892d-b296-4f0c-8886-514b4ee2bad6",
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}