AIM-PIbd-32-Shabunov-O-A/lab_1/lab1.ipynb

362 lines
176 KiB
Plaintext
Raw Permalink Normal View History

2024-09-20 21:07:57 +04:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Начало лабораторной работы №1\n",
"\n",
2024-09-21 01:11:22 +04:00
"*Набор данных для анализа и прогнозирования сердечного приступа*\n",
"\n",
2024-09-20 21:07:57 +04:00
"Выгрузка данных из CSV файла в датафрейм"
]
},
{
"cell_type": "code",
2024-09-21 01:11:22 +04:00
"execution_count": 22,
2024-09-20 21:07:57 +04:00
"metadata": {},
"outputs": [
{
2024-09-21 01:11:22 +04:00
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>HeartDisease</th>\n",
" <th>BMI</th>\n",
" <th>Smoking</th>\n",
" <th>AlcoholDrinking</th>\n",
" <th>Stroke</th>\n",
" <th>PhysicalHealth</th>\n",
" <th>MentalHealth</th>\n",
" <th>DiffWalking</th>\n",
" <th>Sex</th>\n",
" <th>AgeCategory</th>\n",
" <th>Race</th>\n",
" <th>Diabetic</th>\n",
" <th>PhysicalActivity</th>\n",
" <th>GenHealth</th>\n",
" <th>SleepTime</th>\n",
" <th>Asthma</th>\n",
" <th>KidneyDisease</th>\n",
" <th>SkinCancer</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>No</td>\n",
" <td>16.60</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>3.0</td>\n",
" <td>30.0</td>\n",
" <td>No</td>\n",
" <td>Female</td>\n",
" <td>55-59</td>\n",
" <td>White</td>\n",
" <td>Yes</td>\n",
" <td>Yes</td>\n",
" <td>Very good</td>\n",
" <td>5.0</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>Yes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>No</td>\n",
" <td>20.34</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>Yes</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>No</td>\n",
" <td>Female</td>\n",
" <td>80 or older</td>\n",
" <td>White</td>\n",
" <td>No</td>\n",
" <td>Yes</td>\n",
" <td>Very good</td>\n",
" <td>7.0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>No</td>\n",
" <td>26.58</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>20.0</td>\n",
" <td>30.0</td>\n",
" <td>No</td>\n",
" <td>Male</td>\n",
" <td>65-69</td>\n",
" <td>White</td>\n",
" <td>Yes</td>\n",
" <td>Yes</td>\n",
" <td>Fair</td>\n",
" <td>8.0</td>\n",
" <td>Yes</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>No</td>\n",
" <td>24.21</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>No</td>\n",
" <td>Female</td>\n",
" <td>75-79</td>\n",
" <td>White</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>Good</td>\n",
" <td>6.0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>Yes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>No</td>\n",
" <td>23.71</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>28.0</td>\n",
" <td>0.0</td>\n",
" <td>Yes</td>\n",
" <td>Female</td>\n",
" <td>40-44</td>\n",
" <td>White</td>\n",
" <td>No</td>\n",
" <td>Yes</td>\n",
" <td>Very good</td>\n",
" <td>8.0</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" <td>No</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" HeartDisease BMI Smoking AlcoholDrinking Stroke PhysicalHealth \\\n",
"0 No 16.60 Yes No No 3.0 \n",
"1 No 20.34 No No Yes 0.0 \n",
"2 No 26.58 Yes No No 20.0 \n",
"3 No 24.21 No No No 0.0 \n",
"4 No 23.71 No No No 28.0 \n",
"\n",
" MentalHealth DiffWalking Sex AgeCategory Race Diabetic \\\n",
"0 30.0 No Female 55-59 White Yes \n",
"1 0.0 No Female 80 or older White No \n",
"2 30.0 No Male 65-69 White Yes \n",
"3 0.0 No Female 75-79 White No \n",
"4 0.0 Yes Female 40-44 White No \n",
"\n",
" PhysicalActivity GenHealth SleepTime Asthma KidneyDisease SkinCancer \n",
"0 Yes Very good 5.0 Yes No Yes \n",
"1 Yes Very good 7.0 No No No \n",
"2 Yes Fair 8.0 Yes No No \n",
"3 No Good 6.0 No No Yes \n",
"4 Yes Very good 8.0 No No No "
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
2024-09-20 21:07:57 +04:00
}
],
"source": [
"import pandas as pd\n",
2024-09-21 01:11:22 +04:00
"import matplotlib.pyplot as plt\n",
2024-09-20 21:07:57 +04:00
"\n",
"df = pd.read_csv(\".//static//csv//heart_2020_cleaned.csv\")\n",
2024-09-21 01:11:22 +04:00
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Построение диаграмм\n",
"\n",
"## Распределение индекса массы тела"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1sAAAIjCAYAAAD1OgEdAAAAOXRFWHRTb2Z0d2FyZQBN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d+5c+7KMM5zXy+72vvnmG1ksFo0bN+6GtS9fvlw2m01jx461H8fXt8mQ8f12+vRph8ssXS0nx+yVK1duemxJsp/plmT//mjYsKEuXbqkAwcOmLIvAMzFZYQA8rxZs2apcuXKypcvn4oXL64qVao4/FGWcU/Ihx9+qNjYWIf7H679w/Xw4cOqUqWK/fIsV6lUqZLDa4vFoooVK9rvxYmJiZEk9ejR44Z9nD9/XoULF7a/TkhIyNTv9WJiYmQYxg3bXX+537lz5yQpU8C5vs/z588rKCgoy/Xx8fEOr1evXq1ixYrdtM7rjRs3TiEhIXrxxRf19ddfZ9p+dHT0Dfu8fvs3s2DBAu3bt09LlizRwoULs2zz6aef6tNPP820vGzZspmWZdwfFRAQcMNtHjp0SIZhaMyYMRozZkyWbeLj4+3/o0CSevbsqS1btsjHxyfLAHH48GF17NjxhtvM8Pnnn2vatGk6cOCAQ2DMuOQxO3r27Km6devqxIkT+vPPP3XixAl16tRJb7zxRo62d/jwYYWEhKhIkSI33Obhw4dltVpVrVq1W9Z37febh4eHatasqbfeesullxpKOTtmz58/f9NjS7p6ieno0aO1du1aJSYmZuoPQN5D2AKQ5z344IP2ezuyMnnyZI0ZM0a9evXSpEmTVKRIEVmtVg0ePDj
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10, 6))\n",
"plt.hist(df.head(15000)['BMI'], bins=30, color='skyblue', edgecolor='black')\n",
"plt.title('Распределение индекса массы тела')\n",
"plt.xlabel('Индекс массы тела')\n",
"plt.ylabel('Количество записей')\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Данная диаграмма отображает распределение индекса массы тела среди всех наблюдаемых. Это позволяет сделать вывод о том, что большинство участников имеют ИМТ **в диапазоне от 18 до 40**, что может коррелировать с риском сердечного приступа."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Соотношение людей с болезнями сердца по полу"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1sAAAJICAYAAACXCf6EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABmN0lEQVR4nO3deVwVZf//8fcB2QSB3EASEbUUXHKplNtcKgRzadEWy3LP3DKXsrxTc8k0y12z2yy1O600zbuyFNS0VFyyzDUzw6wUtBSPqOzz+8Mv5+cRREDGgXg9Hw8eea65zsxnzjnN8OaauY7NMAxDAAAAAIAi5WJ1AQAAAADwT0TYAgAAAAATELYAAAAAwASELQAAAAAwAWELAAAAAExA2AIAAAAAExC2AAAAAMAEhC0AAAAAMAFhCwBgufPnz+v333/XmTNnrC4FAIAiQ9gCAFhi+fLluvfee1WuXDn5+PioWrVqmjJlitVlFQtz5sxRUlKS4/GMGTN0/vx56woCABQKYQtAsXDkyBE988wzqlGjhjw9PeXr66vmzZtr5syZunjxotXloYi99NJLevTRR1WuXDm98847io2N1bp16zRgwACrSysWPv/8c40dO1a///67lixZotGjR8vLy8vqsgAABWQzDMOwuggApdvq1av1yCOPyMPDQ926dVO9evWUlpamzZs3a8WKFerRo4fmz59vdZkoIps2bVLr1q01adIkvfTSS1aXUyxt2rRJ999/v+x2u1xcXDR16lQNGTLE6rIAAAVE2AJgqfj4eDVo0EBVq1bVhg0bVKVKFaflv/zyi1avXq3nnnvOogpR1Dp27KjTp09ry5YtVpdSrCUlJengwYMKDg5W1apVrS4HAFAIXEYIwFJTpkxRcnKy3n333RxBS5Jq1arlFLQyMjI0YcIE1axZUx4eHqpevbr+/e9/KzU1Ncdz33rrLdWtW1ceHh4KCgrSwIEDne6Dad26tWw2W54/2Ww2mwYNGpRjGx06dFD16tWd2s6fP6/hw4crODhYHh4eql27tt58801d+bet3NaZ2/oWLFggm82mffv2ObV/9dVXatGihby9vVWuXDm1b99e+/fvd+rTo0cP+fj45Kj7k08+kc1m08aNG51ej9atWzv127lzZ47XItsHH3ygJk2ayMvLS+XLl1eXLl30+++/5+h3pW3btqlevXrq0qWLypcvLy8vL91xxx1atWpVjr4nT55U7969FRAQIE9PT912221avHhxrusdO3Zsru9hjx49nPr9+eef6tWrlwICAuTh4aG6devqvffec+qzefNm3XXXXapYsaI8PT1Vo0YNvfjii0pJSXH0WbRokWw2m7777jun5/7111+y2WwaO3Zsgbe7ceNGx/vi7++viIgIVa1aVe3bt891nblJSUnR2LFjdeutt8rT01NVqlRRp06ddOTIEUefrKwszZgxQ3Xr1pWnp6cCAgL0zDPP5JigpHr16urQoYNiYmLUsGFDeXp6Kjw8XCtXrsx12z169MjXe5C93isNGjQox2ftt99+04ABA1S7dm15eXmpQoUKeuSRR3T06NFrvhZHjx7N8//vKz/vBfm8Xal69er5OpZIBTuOZX8mrvzJPk4kJyfL29s71z9I/fHHH3J1ddWkSZPytQ8Ail4ZqwsAULp9/vnnqlGjhv71r3/lq3+fPn20ePFiPfzwwxo+fLi2b9+uSZMm6eDBg/r0008d/caOHatx48YpMjJS/fv316FDhzRv3jzt3LlTW7ZskZubm15++WX16dNH0qVfkIcOHaq+ffuqRYsWhd4fwzB0//336+uvv1bv3r3VsGFDrV27Vi+88IL+/PNPTZ8+vdDrvtx///tfde/eXdHR0Xr99dd14cIFzZs3T3fddZd++OGHHIGtsF588cVc2ydOnKjRo0fr0UcfVZ8+fXTq1CnNnj1bLVu21A8//CB/f/+rrvPvv//W/Pnz5ePjo8GDB6tSpUr64IMP1KlTJy1ZskSPP/64JOnixYtq3bq1fvnlFw0aNEihoaFavny5evTooaSkpKuOdv73v/91/Hvo0KFOyxITE9WsWTNH0K1UqZK++uor9e7dW3a73XGp3rlz5xQWFqZHH31UZcuWVVxcnKZMmaILFy5o9uzZBXgFC7bd3HzzzTf68ssv87WdzMxMdejQQevXr1eXLl303HPP6dy5c4qNjdW+f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X0096enqOGl1dXTV48OAcNRqGoa+++qpQ275cbGyskpKS9PjjjzvV4urqqqZNm+rrr7/O8Zwr6z537lye2zAMQyNHjlTnzp3VtGlTp2UrV65UVlaWHn30Uad1BgYG6pZbbsl1+1e644471KpVK8djLy8vDRgwQAkJCfr+++8lXXotAwMDHSNdkuTm5qbBgwcrOTlZmzZtclpnWlqaPDw88tynFStWqGPHjjIMw6n26OhonT171rHtbKdPn9aJEye0atUqxcXFqWXLljnWe/bsWad1nT59+rq3m23lypXauXOnJk+efNX9utyKFStUsWJFPfvsszmWZV/Ktnz5cvn5+alNmzZOtTRp0kQ+Pj453r+goCA99NBDjse+vr7q1q2bfvjhByUkJDj1TUlJkaenZ75qza/LZ2FMT0/X33//rVq1asnf3/+qr1thFPTzdj3bka59HMuWlpYmSXl+tiMjIxUUFKQlS5Y42vbt26c9e/boySefLJK6ARQOlxECsIyvr68kXfMX/2y//fabXFxcVKtWLaf2wMBA+fv767fffnP0k6TatWs79XN3d1eNGjUcywvq3Xff1bvvvpujPSQkxKnGoKCgHAEy+/Kfwm77cocPH5Yk3XPPPbkuz35ds50/f16VKlUq0DaWLFmi/fv3a9myZVq6dGmO7RuGoVtuuSXX515+CdrV1KlTJ0db9mt09OhRNW3aVL/99ptuueUWp8B8eb8rX8ukpKRc70/Ldur
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"heart_disease_sex = df.head(15000).groupby(['Sex', 'HeartDisease']).size().unstack()\n",
"\n",
"heart_disease_sex.plot(kind='bar', stacked=True, figsize=(10, 6), color=['lightcoral', 'cornflowerblue'])\n",
"plt.title('Соотношение болезней сердца по полу')\n",
"plt.xlabel('Пол')\n",
"plt.ylabel('Количество')\n",
"plt.legend(title='Heart Disease', labels=['Нет', 'Да'])\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Данная столбчатая диаграмма показывает соотношение людей с сердечными заболеваниями среди мужчин и женщин. Она позволяет сделать вывод о том, что **среди мужчин** более высокая доля тех, кто страдает сердечными заболеваниями."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Влияние физического и психического здоровья на наличие болезней сердца"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0sAAAIjCAYAAADSlID1AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdeVwU9f/A8dcu13LsggqKyqGoCahZHqXmUeZdqVi/vqWlpqmlZqkVeWtlaocpWZaaWtmphZZHqWXempnmAZg3h6agsiC4sMvO7w/ajWUXZRHk6P18PHgoM7Ozb2Y+85l5z+czn1EpiqIghBBCCCGEEMKGurwDEEIIIYQQQoiKSJIlIYQQQgghhHBAkiUhhBBCCCGEcECSJSGEEEIIIYRwQJIlIYQQQgghhHBAkiUhhBBCCCGEcECSJSGEEEIIIYRwQJIlIYQQQgghhHBAkiUhhBBCCCEqILPZTFpaGqdOnSrvUP6zJFkSQgghhBCigvj777954YUXCA0Nxd3dnYCAACIjI8nIyCjv0CqdBQsWkJ6ebv193rx5ZGVlObUOlaIoSinHVaF8+OGHxMbGcvDgQS5fvkyNGjVo3LgxQ4cO5YknnkCtlnyxqvDx8eGRRx5h+fLl5R2KEEIIIYTTTpw4wX333YfRaGTMmDG0aNECV1dXPD09adOmDS4uLuUdYqXSvXt3IiIiGD9+PNu2beOZZ55Br9c7df3vWobxVQiffPIJtWvXZsqUKeh0OtLT09mzZw+DBw9mw4YNfPnll+UdohBCCCGEEIwYMQJ3d3f27NlD3bp1yzucSm/ixIn07t2b+fPno1areeedd5xuKKnyLUtGoxE3Nze76c899xwLFizg9OnT1KtX79YHJkqdtCwJIYQQorLav38/rVq1YuPGjXTt2r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Tu3ZukpCSH332jc7tFTk4O06ZNo2HDhnh4eBAcHMzLL79sU4aK2g+Ft6Vle7/99tt28TRt2tRm/1jWuWrVqiK3X+H1T5s2DbVazc8//2yz3PDhw3F3d+fPP/8scl2XLl2iZ8+eBAUF4eHhQe3atRkwYABnz561We7tt9+mXbt21KhRA09PT1q2bGkX4549e9BoNJw8edJaXwQGBjJixAguX75s993FvW6Dovdb4fPiihUrrOusXr06jz32mF1ZKG5dVdzj1pm6oLjXXQXLlp+fH23btiUoKMjhMX4jVb4bnkV6ejomk4nMzEz279/P22+/zWOPPUZISIh1meXLl+Pj48O4cePw8fHhl19+YerUqWRkZPDWW2/ZrC88PJxJkyahKAonT55k7ty59OrVi8TExOvGMGvWLLvpeXl5PPjgg/z888889thjPP/882RmZrJp0yaOHDlCgwYNHK7vxIkTLF68uMjvc3FxYcWKFYwdO9Y6bdmyZWg0GgwGg82yy5cv56mnnqJ169bMmjWLCxcuMH/+fHbu3MmBAwfw8/MD4NChQ3To0AE3NzeGDx9OvXr1OHnyJD/88AMzZ86kX79+NGzY0LresWPHEhERwfDhw63TIiIiioy5uObMmcPbb7/Nk08+ScuWLRk7diy5ubmsW7eOO+64g5kzZ7JkyRL69etHXFwc9evXL3JdU6dOtdseFsOHDycwMJBz586xYMECunTpwunTp/Hy8nK4fFH7uLiys7Pp1KkTKSkpjBgxgpCQEHbt2sWECRM4f/488+bNsy47dOhQli9fTs+ePXn66acxmUxs376dPXv20KpVK4frf/rpp/n111/ZtGkTkZGRNtM/+eQTHnnkEcaPH8/evXuZNWsW8fHxxMbG2qzjjjvuYPz48TbTLPtcURR69+7Nli1bGDp0KHfccQc//fQTL730EikpKbz77rtOb5Po6Ginlg8KCrLbB+vXr7frcrt8+XKGDBlCkyZNmDBhAn5+fhw4cIAff/yR/v37OxXPU089xXfffce4cePo2rUrwcHBHD58mBkzZjB06FB69epV5PpudBzfyIULF2jTpo31AjogIIANGzYwdOhQMjIyeOGFF4CS1TNGo5GHH36YxMREdu7cSe3atQHn93PXrl0ZOHCgzbQ77rgDgGvXrnHvvfdy4sQJRo8eTf369Vm5ciWDBw8mPT2d559//obbwJnjdMyYMbRu3RqATz/9lE2bNtnMP3r0KB06dECn0/Hyyy/j5ubGRx99xL333svWrVu5++67bZYfPXo0fn5+TJ8+nWPHjrFw4ULOnj1rPVFD/s2SGTNm0KVLF5599lnrcvv27WPnzp02N/VKcm5xJC8vj969e3P27FleeOEFbrvtNlQqFTNnzizW54tTJ8ybN4+rV68CEB8fzxtvvMHEiROtdbyPj49TMV/PwoULadKkCb1798bV1ZUffviBkSNHYjabGTVqlMPPFIxl0aJFN9yG27Zts97YKC1FnV/eeecdpkyZQlRUFNHR0Xh4eLB9+3YWLVp0w3Xe6DwMxa8XLGbOnIlKpSI6OpqLFy8yb948unTpwsGDB/H09LSLoeAxvW/fPmJiYmzmm81mevfuzY4dOxg+fDgREREcPnyYd999l7/++ovVq1cXcwveGpMnT+aHH35g6NChHD58GK1Wy08//cTixYt57bXXaN68eZGfzc3NRavV8vzzz1OjRg1OnjzJe++9x6FDh2xu3MyfP5/evXszYMAAcnNz+eqrr/i///s/1q5dywMPPADkJ14Gg4Fnn32Wzp0788wzz3Dy5Enef/999u7dy969e/Hw8ACKf91WUFRUFP369QNwWN5mzpzJlClTePTRR3n66adJTU3lvffeo2PHjnbrLE5dVZLj1lnOXHeV+BhX/iMaN26sANafgQMHKkaj0WaZ7Oxsu8+NGDFC8fLyUgwGg3Vap06dlE6dOtksN3HiRAVQLl68aJ0GKNOmTbP+/vLLLys1a9ZUWrZsafP5pUuXKoAyd+5cu+83m82KoijK6dOnFUBZtmyZdd6jjz6
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df_slice = df.iloc[0:2000]\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"plt.scatter(df_slice[df_slice['HeartDisease'] == 'Yes']['PhysicalHealth'],\n",
" df_slice[df_slice['HeartDisease'] == 'Yes']['MentalHealth'],\n",
" color='red', label='С заболеваниями', alpha=0.5)\n",
"plt.scatter(df_slice[df_slice['HeartDisease'] == 'No']['PhysicalHealth'],\n",
" df_slice[df_slice['HeartDisease'] == 'No']['MentalHealth'],\n",
" color='green', label='Без заболеваний', alpha=0.5)\n",
"\n",
"plt.title('Зависимость физического и психического здоровья от наличия сердечных заболеваний')\n",
"plt.xlabel('Физическое здоровье (дни с проблемами)')\n",
"plt.ylabel('Психическое здоровье (дни с проблемами)')\n",
"plt.legend()\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Эта диаграмма рассеяния показывает взаимосвязь между физическим и психическим здоровьем людей, страдающих и не страдающих сердечными заболеваниями. Это позволяет сделать вывод о том, что **ухудшение физического и психического здоровья** связано с **повышенным риском** сердечного приступа."
2024-09-20 21:07:57 +04:00
]
}
],
"metadata": {
"kernelspec": {
"display_name": "aimenv",
"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.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}