agabka/projekt (5).ipynb

3670 lines
782 KiB
Plaintext
Raw Normal View History

2024-04-04 22:23:05 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 210,
"id": "7ce53ad1",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import plotly.figure_factory as ff\n",
"import seaborn as sns\n",
"sns.set()\n",
"import plotly.express as px\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b9fd854",
"metadata": {},
"outputs": [],
"source": [
"pip install plotnine"
]
},
{
"cell_type": "code",
"execution_count": 212,
"id": "6d369f6b",
"metadata": {},
"outputs": [],
"source": [
"import plotnine"
]
},
{
"cell_type": "code",
"execution_count": 213,
"id": "73edef6d",
"metadata": {},
"outputs": [
{
"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>Patient Id</th>\n",
" <th>Age</th>\n",
" <th>Gender</th>\n",
" <th>Air Pollution</th>\n",
" <th>Alcohol use</th>\n",
" <th>Dust Allergy</th>\n",
" <th>OccuPational Hazards</th>\n",
" <th>Genetic Risk</th>\n",
" <th>chronic Lung Disease</th>\n",
" <th>Balanced Diet</th>\n",
" <th>...</th>\n",
" <th>Fatigue</th>\n",
" <th>Weight Loss</th>\n",
" <th>Shortness of Breath</th>\n",
" <th>Wheezing</th>\n",
" <th>Swallowing Difficulty</th>\n",
" <th>Clubbing of Finger Nails</th>\n",
" <th>Frequent Cold</th>\n",
" <th>Dry Cough</th>\n",
" <th>Snoring</th>\n",
" <th>Level</th>\n",
" </tr>\n",
" <tr>\n",
" <th>index</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>P1</td>\n",
" <td>33</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>Low</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>P10</td>\n",
" <td>17</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>8</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>Medium</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>P100</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>...</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>9</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>P1000</td>\n",
" <td>37</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>5</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>P101</td>\n",
" <td>46</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>High</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 25 columns</p>\n",
"</div>"
],
"text/plain": [
" Patient Id Age Gender Air Pollution Alcohol use Dust Allergy \\\n",
"index \n",
"0 P1 33 1 2 4 5 \n",
"1 P10 17 1 3 1 5 \n",
"2 P100 35 1 4 5 6 \n",
"3 P1000 37 1 7 7 7 \n",
"4 P101 46 1 6 8 7 \n",
"\n",
" OccuPational Hazards Genetic Risk chronic Lung Disease \\\n",
"index \n",
"0 4 3 2 \n",
"1 3 4 2 \n",
"2 5 5 4 \n",
"3 7 6 7 \n",
"4 7 7 6 \n",
"\n",
" Balanced Diet ... Fatigue Weight Loss Shortness of Breath \\\n",
"index ... \n",
"0 2 ... 3 4 2 \n",
"1 2 ... 1 3 7 \n",
"2 6 ... 8 7 9 \n",
"3 7 ... 4 2 3 \n",
"4 7 ... 3 2 4 \n",
"\n",
" Wheezing Swallowing Difficulty Clubbing of Finger Nails \\\n",
"index \n",
"0 2 3 1 \n",
"1 8 6 2 \n",
"2 2 1 4 \n",
"3 1 4 5 \n",
"4 1 4 2 \n",
"\n",
" Frequent Cold Dry Cough Snoring Level \n",
"index \n",
"0 2 3 4 Low \n",
"1 1 7 2 Medium \n",
"2 6 7 2 High \n",
"3 6 7 5 High \n",
"4 4 2 3 High \n",
"\n",
"[5 rows x 25 columns]"
]
},
"execution_count": 213,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane = pd.read_csv(r'C:\\Users\\HP\\Desktop\\podyplomówka\\cancer_patient_data_sets.csv', index_col = 0)\n",
"dane.head()"
]
},
{
"cell_type": "code",
"execution_count": 214,
"id": "1831fdd7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"Index: 1000 entries, 0 to 999\n",
"Data columns (total 25 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Patient Id 1000 non-null object\n",
" 1 Age 1000 non-null int64 \n",
" 2 Gender 1000 non-null int64 \n",
" 3 Air Pollution 1000 non-null int64 \n",
" 4 Alcohol use 1000 non-null int64 \n",
" 5 Dust Allergy 1000 non-null int64 \n",
" 6 OccuPational Hazards 1000 non-null int64 \n",
" 7 Genetic Risk 1000 non-null int64 \n",
" 8 chronic Lung Disease 1000 non-null int64 \n",
" 9 Balanced Diet 1000 non-null int64 \n",
" 10 Obesity 1000 non-null int64 \n",
" 11 Smoking 1000 non-null int64 \n",
" 12 Passive Smoker 1000 non-null int64 \n",
" 13 Chest Pain 1000 non-null int64 \n",
" 14 Coughing of Blood 1000 non-null int64 \n",
" 15 Fatigue 1000 non-null int64 \n",
" 16 Weight Loss 1000 non-null int64 \n",
" 17 Shortness of Breath 1000 non-null int64 \n",
" 18 Wheezing 1000 non-null int64 \n",
" 19 Swallowing Difficulty 1000 non-null int64 \n",
" 20 Clubbing of Finger Nails 1000 non-null int64 \n",
" 21 Frequent Cold 1000 non-null int64 \n",
" 22 Dry Cough 1000 non-null int64 \n",
" 23 Snoring 1000 non-null int64 \n",
" 24 Level 1000 non-null object\n",
"dtypes: int64(23), object(2)\n",
"memory usage: 203.1+ KB\n"
]
}
],
"source": [
"dane.info()"
]
},
{
"cell_type": "markdown",
"id": "69f1b9c9",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 215,
"id": "af7da17c",
"metadata": {},
"outputs": [
{
"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>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Age</th>\n",
" <td>1000.0</td>\n",
" <td>37.174</td>\n",
" <td>12.005493</td>\n",
" <td>14.0</td>\n",
" <td>27.75</td>\n",
" <td>36.0</td>\n",
" <td>45.0</td>\n",
" <td>73.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Gender</th>\n",
" <td>1000.0</td>\n",
" <td>1.402</td>\n",
" <td>0.490547</td>\n",
" <td>1.0</td>\n",
" <td>1.00</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Air Pollution</th>\n",
" <td>1000.0</td>\n",
" <td>3.840</td>\n",
" <td>2.030400</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>3.0</td>\n",
" <td>6.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Alcohol use</th>\n",
" <td>1000.0</td>\n",
" <td>4.563</td>\n",
" <td>2.620477</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Dust Allergy</th>\n",
" <td>1000.0</td>\n",
" <td>5.165</td>\n",
" <td>1.980833</td>\n",
" <td>1.0</td>\n",
" <td>4.00</td>\n",
" <td>6.0</td>\n",
" <td>7.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Swallowing Difficulty</th>\n",
" <td>1000.0</td>\n",
" <td>3.746</td>\n",
" <td>2.270383</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Clubbing of Finger Nails</th>\n",
" <td>1000.0</td>\n",
" <td>3.923</td>\n",
" <td>2.388048</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>9.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Frequent Cold</th>\n",
" <td>1000.0</td>\n",
" <td>3.536</td>\n",
" <td>1.832502</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>3.0</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Dry Cough</th>\n",
" <td>1000.0</td>\n",
" <td>3.853</td>\n",
" <td>2.039007</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>4.0</td>\n",
" <td>6.0</td>\n",
" <td>7.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Snoring</th>\n",
" <td>1000.0</td>\n",
" <td>2.926</td>\n",
" <td>1.474686</td>\n",
" <td>1.0</td>\n",
" <td>2.00</td>\n",
" <td>3.0</td>\n",
" <td>4.0</td>\n",
" <td>7.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>23 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
" count mean std min 25% 50% 75% \\\n",
"Age 1000.0 37.174 12.005493 14.0 27.75 36.0 45.0 \n",
"Gender 1000.0 1.402 0.490547 1.0 1.00 1.0 2.0 \n",
"Air Pollution 1000.0 3.840 2.030400 1.0 2.00 3.0 6.0 \n",
"Alcohol use 1000.0 4.563 2.620477 1.0 2.00 5.0 7.0 \n",
"Dust Allergy 1000.0 5.165 1.980833 1.0 4.00 6.0 7.0 \n",
"... ... ... ... ... ... ... ... \n",
"Swallowing Difficulty 1000.0 3.746 2.270383 1.0 2.00 4.0 5.0 \n",
"Clubbing of Finger Nails 1000.0 3.923 2.388048 1.0 2.00 4.0 5.0 \n",
"Frequent Cold 1000.0 3.536 1.832502 1.0 2.00 3.0 5.0 \n",
"Dry Cough 1000.0 3.853 2.039007 1.0 2.00 4.0 6.0 \n",
"Snoring 1000.0 2.926 1.474686 1.0 2.00 3.0 4.0 \n",
"\n",
" max \n",
"Age 73.0 \n",
"Gender 2.0 \n",
"Air Pollution 8.0 \n",
"Alcohol use 8.0 \n",
"Dust Allergy 8.0 \n",
"... ... \n",
"Swallowing Difficulty 8.0 \n",
"Clubbing of Finger Nails 9.0 \n",
"Frequent Cold 7.0 \n",
"Dry Cough 7.0 \n",
"Snoring 7.0 \n",
"\n",
"[23 rows x 8 columns]"
]
},
"execution_count": 215,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane.describe().T"
]
},
{
"cell_type": "code",
"execution_count": 216,
"id": "a043ec73",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Patient Id', 'Age', 'Gender', 'Air Pollution', 'Alcohol use',\n",
" 'Dust Allergy', 'OccuPational Hazards', 'Genetic Risk',\n",
" 'chronic Lung Disease', 'Balanced Diet', 'Obesity', 'Smoking',\n",
" 'Passive Smoker', 'Chest Pain', 'Coughing of Blood', 'Fatigue',\n",
" 'Weight Loss', 'Shortness of Breath', 'Wheezing',\n",
" 'Swallowing Difficulty', 'Clubbing of Finger Nails', 'Frequent Cold',\n",
" 'Dry Cough', 'Snoring', 'Level'],\n",
" dtype='object')"
]
},
"execution_count": 216,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane.columns"
]
},
{
"cell_type": "code",
"execution_count": 217,
"id": "9dac40a9",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZoAAAGZCAYAAACwkvfNAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABX5klEQVR4nO3dd3wUdf7H8dfMbnrvlRog9N6lN0UFFevJ6Xl6Vk5P7PoTTz27IiJYTk9Rz96RE7HSEnrvHdJ775udmd8fkWgkoYRsZnfzeT4ePB6wOzvz2QX2ne93vkUxDMNACCGEcBDV7AKEEEK4NwkaIYQQDiVBI4QQwqEkaIQQQjiUBI0QQgiHkqARQgjhUBI0QgghHEqCRgghhENJ0AjhQM42H9rZ6hFtgwSNaFXXXHMNiYmJDX51796dQYMGcfnll/Ptt982OH7ChAk88MADp33+Mz2+KV9++SWJiYmkp6cDsGDBAhITE0/79dnZ2dx8881kZGSc9Lj169eTmJjI+vXrT/s6f3zN6Xrttdd466236v98pu9JiOayml2AaHt69uzJP//5z/o/a5pGdnY277zzDnfddRcBAQGMGTMGgIULF+Lv729WqfUuv/xyRo8efdrHr1mzhhUrVjBnzpyTHterVy8++eQTunTpctrnbs5rAF566SX+/ve/1//5TN+TEM0lQSNanb+/P/379z/h8bFjxzJixAi++OKL+qDp2bNnK1fXuOjoaKKjo1v8vE19Fi39msY46j0J8UfSdSachqenJx4eHg0e+2NX2NKlS5k+fTp9+/Zl+PDh3HPPPeTm5jZ5zs8//5zu3buzYMGCJo/RdZ1XX32VcePG0a9fP2677TZKSkoaHPPHbqa0tDRuvfVWhg0bRr9+/bjyyitZuXIlUNft9uCDDwIwceLE+vonTJjAU089xV/+8hcGDhzII4880mQ32E8//cS5555Lnz59uPzyy1m7dm39c6fb3ZaYmFj/vo8/v3DhwvrfN/a6pUuXMmPGDAYMGMA555zDI4880uCzWLBgAZMnT2bFihVMmzaN3r17c+655/LVV181+fkKIUEjWp1hGNjt9vpfNTU1pKSk8PDDD1NRUcFFF13U6Os2b97MPffcw5QpU3jzzTd58MEHWbduHXfffXejxy9dupQ5c+Zwyy23cPvttzdZz/PPP88rr7zCpZdeysKFCwkJCWHu3LlNHq/rOjfffDOVlZU899xzvPrqqwQHB3PbbbeRkpLCuHHjuPXWW4G6L/bbbrut/rUffPBBfQA09T4BHnroIa699loWLFiAn58fN954I4cOHWry+FP55JNPALjsssvqf/9Hr776KrNnz6Zfv368/PLLzJo1i++//55rrrmG6urq+uPy8vJ4/PHHufbaa3njjTeIj4/ngQce4PDhw82uT7g36ToTrW7jxo306tWrwWOKotCtWzfmz5/PhAkTGn3d5s2b8fLy4sYbb8TLywuA4OBgdu7ciWEYKIpSf+zy5cu57777uOmmm7jzzjubrKW0tJT//ve/XHvttfVhNHr0aHJycli9enWjrykoKODw4cPccsstjB07FoC+ffuycOFCampq6NChA+3btwegR48exMfH1782MjKSBx54AFWt+xmvqRv6//znP7ngggsAGDFiBBMnTuS11147aQCezPGutujo6Ea73UpKSnjttde4/PLLG9w/69atGzNnzuTLL7/k6quvBqCqqoonn3ySESNGANCxY0fGjx/PypUrSUhIaFZ9wr1J0IhW16tXLx577DEAcnJymD9/PrW1tcybN++kX1RDhgxh3rx5TJs2jalTpzJmzBhGjRpV/2V/3O7du1m6dCmRkZH84x//OGkt27Zto7a2lokTJzZ4fOrUqU0GTXh4OF26dGHOnDmsWbOmvo7j3WUnk5CQUB8yTbFYLEyZMqX+z15eXowZM4bly5ef8vzNtW3bNmw2G9OmTWvw+ODBg4mLi2P9+vX1QQM0CKvj93kqKysdVp9wbdJ1Jlqdn58fffr0oU+fPkyaNIl33nmH8vJyrr/+egoLC5t83YABA3jjjTdo164db731FldffTVjx47l3XffbXDcgQMHGDlyJBkZGbz//vsnreX4/YfQ0NAGj0dERDT5GkVRePvtt7nkkktYvXo1s2fPZuTIkdx5550UFxef9Hrh4eEnfR7qWml/vFcVFhZGaWnpKV/bXMc/h8bqCw8Pp6ysrMFjPj4+9b8/HpwyR0c0RYJGmC4sLIxHHnmE7OxsnnzyyZMeO3r0aN566y02btzI66+/TteuXXnqqafYvn17/TGjRo3i9ddf58ILL2TevHlkZmY2eb6QkBCgrjvs904VGFFRUTz66KMkJSXx9ddfc8MNN/DDDz8wb968U7zbUysrKzvhSzs/P/+EMDzueJehpmn1j1VUVJzRNYOCguqv80d5eXn1n5MQzSFBI5zClClTGD16NP/73/+avG/x7LPPctlll2EYBj4+PowfP577778fgKysrPrjjrdGHnzwQaxWK4888kiT1x0wYADe3t4sW7asweMn66baunUrI0eOZMeOHSiKQo8ePZg9ezbdunUjOzsb4JTdYydjs9lYt25d/Z8rKipYsWIFw4YNa/T44/OMfv8ZbNmy5YTjTlZTv3798PT0ZMmSJQ0e37RpE5mZmQwcOPCM3oMQvydBI5zGQw89hIeHB0888QR2u/2E50eMGMGuXbt44IEHSE5OZsWKFTzxxBMEBwczfPjwE44PDw9n9uzZrF69msWLFzd6TT8/P2677TY+/PBDXnjhBZKSknjyySdPGjQ9e/bE29ub++67j2+//Zb169czb9489u7dy7nnngtAYGAgAD/++OMZj8by8PDgoYceYsmSJSxfvpy//e1vVFdXNxi99nvH71Edv2f05Zd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+IUSExBJx+B2BHkHAKAbOoZhSEtIOC0JGuG27JqORVVQFIVqm539KUXsPVbI0cw
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"level_counts = dane['Level'].value_counts()\n",
"ax = level_counts.plot(kind = 'pie', autopct='%1.1f%%', startangle=90)\n",
"ax = plt.title('Risk distribiution')"
]
},
{
"cell_type": "code",
"execution_count": 218,
"id": "b45bd771",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABDYAAAHcCAYAAAAtNCoPAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAACBUUlEQVR4nO3dd3gU5dfG8Xs3IUAgIaGFLghSJYTeRDpKUwNiA6QJSBWQImKhiIDSmyBdQEEEERG7gIKAUtUfTSIgLdRAgNCSnfcP3qwsCSTZbM/3c11cujOzc84zz8zO7MnMsybDMAwBAAAAAAB4IbO7EwAAAAAAALAXhQ0AAAAAAOC1KGwAAAAAAACvRWEDAAAAAAB4LQobAAAAAADAa1HYAAAAAAAAXovCBgAAAAAA8FoUNgAAAAAAgNeisAEAgAczDMPdKXhEDp7ElduDbQ8AQMoobAAAYKf27durVKlS1n+lS5dWxYoV1apVKy1evFgJCQk2yzdo0ECvvfZaqtf/448/asiQISku99prr6lBgwZ2x7mXmzdvasyYMfryyy/vGcsTjB8/XtWrV1dERIRWr17t1Fg7duxQ9+7dra+PHz+uUqVKadWqVQ6Pldr+T7Rq1SqVKlVK27Ztc3guAAB4Mn93JwAAgDcrW7as3n77bUlSQkKCLl26pI0bN+rdd9/Vjh07NGnSJJlMJknS9OnTlT179lSve+HChalarmfPnnrxxRfTnHtKzpw5o4ULF2rMmDFOj2WvgwcPas6cOXrmmWf05JNP6sEHH3RqvBUrVujQoUPW13nz5tXy5ctV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+Pl7x8fEym8169NFHk2z7uwtW+fLlu++jHDVq1NCRI0fUqlUrzZw5U3v37lXLli3VoUOHVOX2yCOPaMmSJcqcObMOHz6s9evXa9asWbpw4YJu3rwpSdq6dasyZcqkRo0aWd9nNpvVtGlT6+t//vlH0dHRatCggbWN8fHxqlq1qrJnz67NmzenKh8AAByFOzYAAHCS06dPK0uWLAoJCUkyr2LFivrwww+1cOFCzZs3T7NmzVKePHnUtWvXFL+o5sqVK8XYd98hYjabFRISotjY2DS14X4SHyNJHLQykb+/v0JDQ3X58mXrtKxZs9osk1i8sVgs91333e1InHbnulMrb968Nq8Tt2PiNlmzZo0mTpyoU6dOKSQkRKVLl1aWLFnSFOPixYs6evSozaNDd7qzkHP3NjGbzfd9jKNZs2ayWCz6+OOPNX36dE2ZMkUFCxbUq6++qubNm6eYm8Vi0cSJE7V06VLFxcUpf/78Cg8Pt94xJEkxMTEKCQmR2Wz7t687+yFxwNYRI0ZoxIgRSeIkjhMDAICrUNgAAMAJEhIS9Ntvv6lSpUry8/NLdpk6deqoTp06unbtmrZu3aqPPvpI7777riIiIlShQoV0xb+7gJGQkKCYmBjrl3mTyaSEhASbZdI68GOOHDkkSWfPnlWhQoWs02/duqWYmBiFhobak7rNus+dO6fixYvbzDt79qwKFy6c5nUmfiFPdP78eUm3Cxzbt2/XkCFD1K5dO3Xp0sV6R8l7772nHTt2pDpGUFCQqlWrpsGDByc7PyAgIM1536lFixZq0aKFLl++rE2bNmnOnDkaNGiQqlSpkuKvoSQW0oYPH67HHntMQUFBkqSnn37aukxYWJhiYmJksVhsihuJ20q6/ZiTJA0ePFjVqlVLEiex7wAAcBUeRQEAwAmWLVumM2fO6Pnnn092/rhx4/T000/LMAxlzZpV9evXt463cOrUKUlK8lfztPj1119tBi399ttvFR8fr+rVq0uSsmXLppiYGJtfL9m5c6fNOu5
"text/plain": [
"<Figure size 1300x500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"age_counts = dane['Age'].value_counts().sort_index(ascending=False)\n",
"\n",
"# histogram\n",
"ax = age_counts.plot(kind='bar', figsize=(13, 5), width=1)\n",
"ax.set_xlabel('Age')\n",
"ax.set_ylabel('Count')\n",
"ax.set_title (\"Distribution of patients' age\")\n",
"for i, value in enumerate(age_counts):\n",
" ax.text(i, value + 0.1, str(value), ha='center', va='bottom')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 244,
"id": "966e57b9",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAioAAAHwCAYAAACIfURnAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABKD0lEQVR4nO3deVxUZf//8TcDIiAiSAouqYgpmYqaKKaEabaIluZdWuLtriXJTyy0cq9MLZJwKxfMrcJS626xus02TXPB7S40l9uoVCQVQZFFZub3h1/mbgJLEJmDvJ6Phw+Zc64553PmzGHeXOc6Z5ysVqtVAAAABmRydAEAAABXQlABAACGRVABAACGRVABAACGRVABAACGRVABAACGRVABAACGRVABAACGRVAByoAR7ptohBqMpDxfD1574PohqOCGN3DgQDVr1sz2LygoSG3atNFDDz2kVatWyWw227Xv2rWrnnnmmate/qZNmzRhwoS/bffMM8+oa9eupV7PleTn52vmzJn66KOPrrguI4iLi1OHDh3UunVrffDBB9d1XcnJyRo1apTt8W+//aZmzZpp/fr1Zb6uq93/hdavX69mzZpp+/btZV5LWWrWrJnmzZvn6DIAuTi6AKA8NG/eXFOnTpUkmc1mZWZm6ptvvtFLL72k5ORkxcfHy8nJSZI0f/58eXp6XvWyly9fflXtRo8erX/+858lrv3vpKena/ny5Zo5c+Z1X1dpHTp0SEuWLNEjjzyiBx98UI0bN76u63vvvfd05MgR2+PatWtrzZo1atCgQZmv62r3f6HC91nh/wD+GkEFlYKnp6dat25tN61r164KCAjQzJkz1bVrVz3wwAOSLoea6+F6fEgaYV1X49y5c5KkiIgItWvXrtzX7+rqWmT/O0qtWrUkSX5+fg6uBKgYOPWDSm3gwIGqXbu2kpKSbNP+fEpmw4YNeuCBB9SqVSuFhobq6aefVnp6uu35O3bs0I4dO2zd+du3b1ezZs2UlJSku+66S3fccYe2bNlS7OmYS5cu6cUXX1RISIhCQkI0YcIEnT171ja/uOf88TTGb7/9pm7dukmSnn32WVvbPz/PbDbrrbfeUq9evdSqVSt16dJFcXFxysvLs1vX4MGDtW7dOt17771q0aKFHnjgAX3zzTd/+zpu2LBBDz30kNq0aaNOnTppypQpyszMlCTNmzdPAwcOlCQNGjToiqekCl+3LVu2aMCAAWrVqpW6d++u1atX27U7e/aspk+frrvuukstWrRQ+/btFRUVpd9++822He+//76OHz9u9zr9+dTPiRMnNG7cOLVv317BwcEaNGiQUlJSirzOn376qaKjo9WmTRuFhIRo4sSJys7OllT8/pekVatW6b777lPLli0VFhamadOm6cKFC5KkW265RR4eHn8ZJo8ePaoRI0aobdu2uuOOOxQfH69nn33W9jpKksVi0eLFi9W9e3e1aNFC9957r1atWmW3nIEDB2rixIlavHixunTpopYtW6p///7at2+fXbsdO3aoX79+Cg4O1r333qutW7cWqSkvL08vv/yywsPD1aJFC/Xq1UsbNmywa9O1a1e99NJLGjRokNq2baspU6ZccRuBq0WPCio1Z2dndezYURs2bFBBQYFcXOwPieTkZD399NMaPXq0QkJClJaWpldeeUVPPfWUVq1apalTpyo2NlaSNHXqVDVp0kQ//vijJCk+Pl7Tp09XXl6eWrdurY8//rjI+j/99FO1atVKs2bN0tmzZxUXF6fU1FS74PRXateurfnz5+vJJ5/UE088oXvuuafYdlOmTNEHH3yg4cOHq3379kpJSdGCBQt04MABLV261HYa4ocfflB6erqio6Pl6emphIQERUdH69tvv1WNGjWKXfbChQuVkJCgxx57TDExMfr111+VkJCgvXv36t1339XDDz+smjVr6vnnn9eUKVPUpk2bv9ymmJgY9e7dW48//rg2bdqkF154QVarVQMHDpTVatWoUaOUmZmpp556SrVq1dKBAweUkJCgKVOmaNmyZRo9erTOnj2rlJQUzZ8/Xw0aNNDFixft1nH27Fn1799f7u7umjx5stzd3bVixQoNGDBAa9euVWBgoK3t1KlT1bdvXy1cuFD79+9XfHy8atasqaeeeqrY/f/JJ59o9uzZmjBhgpo1a6b//ve/mj17tnJzczVr1iz5+flpz549V9z+s2fPKjIyUr6+vpo5c6bMZrMSEhJ04sQJu16hadOmaf369Ro1apTatGmjnTt36qWXXlJWVpaioqJs7T7//HMFBgZq0qRJslqtmj17tqKjo/Xll1/K2dlZP/74o4YOHaoOHTrY1jNu3Di7mqxWq6KiorR7925FR0crMDBQGzduVExMjPLz89W7d29b27feeksDBgzQyJEj5ebm9pf7GrgaBBVUejfddJMuXbqkc+fO6aabbrKbl5ycrKpVq2rEiBGqWrWqJMnb21v/+c9/ZLVa1aRJE9t4lj+fWujfv7/uu+++v1y3l5eXli5daluGj4+PoqKitGXLFnXu3Plva3d1ddWtt94q6fLpnuJOWx05ckRr167V2LFj9cQTT0iSOnXqpNq1a2v8+PH69ttvFR4eLkk6f/681q9fb/tr38PDQ5GRkfr+++917733Fll2ZmamXn/9dT388MO2MUCS1LRpUw0YMEDr16/XY489piZNmkiSmjRp8ren1u6++25NnDhRkhQWFqb09HS9/vrrGjBggH7//Xe5u7trwoQJtlNIHTp00G+//WYLdw0aNFDNmjXtTvf8OaisWLFC586d0zvvvKN69epJku6880716NFDCQkJmjt3rq1teHi4bbBsx44d9d133+nrr7/WU089Vez+3759u+rVq6cBAwbIZDKpffv28vDwUEZGxl9ud6FVq1YpOztbH3zwge30UGFPR6Fjx47p3Xff1bhx4zRy5EhJUufOneXk5KRFixbpsccek4+PjySpoKBAiYmJtjqzs7M1YcIEHThwQC1atNCiRYtUs2ZNvf7663J1dZV0+T0eExNjW9/WrVu1efNmxcfHq0ePHrZ9k5OTo7i4OPXs2dMW8mvXrq1nnnlGJhMd9igbvJOA/1Pc4MaQkBDl5uaqV69eio+PV3Jysjp37qwnn3zybwdDNmvW7G/XGR4ebjdwt2vXrqpSpUqxXe+ltWPHDklSr1697KZHRETI2dnZ7uqTmjVr2p2S8Pf3lyTl5OQUu+y9e/cqPz+/yLLbtWunevXqlerKlgcffNDu8T333KMzZ87o2LFj8vPz08qVK9WuXTudOHFC27Zt0+rVq7V7925dunTpqtexbds23XrrrfLz81NBQYEKCgpkMpl05513Fnnt/xxA/f39iwSfPwoNDdXPP/+shx56SAsXLlRKSop69eqlQYMGXVVt33//vdq0aWM3hqVevXp2PVHff/+9rFarunbtaqu/oKBAXbt2VV5enpKTk21t/ximpP+NjSncp8nJyQoLC7OFFOnya+7s7Gx7vG3bNjk5OSk8PLzI+n7//XcdPnzY1jYwMJCQgjJFjwoqvVOnTsnNzU3e3t5F5rVp00aLFy/W8uXLlZiYqDfeeEO1atXSiBEj/vaDx9fX92/X/eceHJPJJG9vb2VlZZVoG/5K4ViRwkGchVxcXOTj46Pz58/bprm7u9u1KQxjFovlL5f95+0onPbHZV+t2rVr2z0ufB0LX5MPP/xQc+bM0cmTJ+Xt7a2goKASn2I4d+6cUlNTddtttxU7/4/B7M+viclk+sv7pvTo0UMWi0Vvv/225s+fr4SEBNWrV09PPfWUIiIi/ra2s2fPFltXrVq19Pvvv9vql3TF5Z06deov65f+t08zMzNVs2ZNuzaF741C586dk9VqVdu2bYtdX3p6uq1nr7j3AnAtCCqo1Mxms3bs2KG2bdva/QX5R2FhYbZu7u+//14rV67USy+9pNatWys4OPia1v/nQGI2m5WRkWH7cHZycipyn5e/+mu+OIVjS37//XfVr1/fNv3SpUvKyMiw+0AqqcJlnz592m5cR+H6br755hIvs/BDuNCZM2ckXQ4su3bt0oQ
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gender_counts = dane['Gender'].value_counts()\n",
"ax = gender_counts.plot(kind='bar')\n",
"\n",
"# Dodawanie wartości do słupków\n",
"for i, value in enumerate(gender_counts):\n",
" ax.text(i, value + 0.1, str(value), ha='center', va='bottom')\n",
"\n",
"# Zmiana etykiet osi x\n",
"ax.set_xticks([0, 1])\n",
"ax.set_xticklabels(['Man', 'Woman'])\n",
"ax.set_title (\"Distribution of patients' gender\")\n",
"\n",
"# Dodanie legendy\n",
"plt.legend()\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 243,
"id": "98973a0f",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAj8AAAHJCAYAAABqj1iuAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAABfvUlEQVR4nO3deXxMV+PH8c9MdpIQse9KJdQuIUEagmptpbWVUEtR60Nb+74vtW+NfW1LqSqtPoraqmippbYqSmsJRYg1kZn5/eGXeTpNaESSScz3/Xp5yZx777nnTm4m35xz7r0Gi8ViQURERMRBGO3dABEREZG0pPAjIiIiDkXhR0RERByKwo+IiIg4FIUfERERcSgKPyIiIuJQFH5ERETEoSj8iIiIiENR+BFJ59LDfUjTQxtERFKKwo/IM2jdujV+fn7Wf/7+/pQvX5433niD5cuXYzKZbNYPCwujf//+Sa5/69at9OvX71/X69+/P2FhYcnez+PExsYybtw4NmzY8Nh9pQeTJk2icuXKlCtXjnXr1iVYvm/fPvz8/Ni3b1+at+3f3i97ti0ttG7dmtatW9u7GSI2nO3dAJGMrmTJkgwbNgwAk8nErVu32LFjB2PHjuXAgQNMnToVg8EAwKxZs/D09Exy3UuWLEnSel27dqVNmzZP3fZ/c/XqVZYsWcK4ceNSfV/JderUKebPn0+zZs14/fXXeeGFF+zdJBFJ5xR+RJ6Rp6cn5cqVsykLCwujSJEijBs3jrCwMBo2bAg8CkqpoWDBgqlSr733lRQ3b94EoF69egQEBNi3MSKSIWjYSySVtG7dmpw5c7Jy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mljs83TvGfu7u7pbn6ZPD/U8yOSiq5cuYK7uztZs2ZNsKx8+fLMmzePJUuWsHDhQiIiIsiRIwcdO3bk7bfffmK9vr6+/7rvf/Y0GY1GsmbNSnR09FMdw5PED1nlyJHDptzZ2RkfHx9u375tLfPw8LBZJz7g/XMeyz/r/udxxJf9ve6ndfPmTTZu3MjGjRsTLMuWLZu1fQ0aNOCzzz5jyJAh7Ny5k+joaOuQV/xE606dOiW6j/i5W0n1z/cw/nsc/z68+eabRERE8O2331KlShV2795tcxXeP0VFRZE1a1aMRtu/cf/+fsYfw4gRI2zmMT3uGP7+PYyvN35o7NatW9b37p/Hde3aNZv9JeU98/X1/dc/AkSSS+FHJJWYTCZ+/PFHKlSogJOTU6LrhISEEBISwv3799m7dy/Lli1j7NixlCtXjrJlyz7T/v8ZckwmE1FRUdZfqgaDIcF9iP4+yTUpsmTJAjyaD5I/f35r+cOHD4mKisLHxyc5Tbep+9q1axQtWtRm2V9//UWBAgWSXbeXlxdVqlShXbt2CZb9fW7J66+/TkREBPv27eOrr76iQoUK1v16e3sDj+4xVLhw4QT1JBbanuSfc5/iA0P896tAgQJUqlSJb775htu3b+Ph4WEdzkpMrly5iIqKwmw22wSg69evW7+OP4a+fftah/b+Lv57kBQ+Pj6cP38+QXl84Pn7/lLqPRNJLg17iaSSlStXcvXqVd56661El0+YMIEmTZpgsVjw8PCgRo0a1jkfly9fBkjwV/vT+OGHH2wmWm/atIm4uDgqV64MQObMmYmKirK5Kuvnn3+2qeNxoS3e3+fC/N3XX3+NyWSiYsWKyW5/2bJlcXV1TVD3/v37uXTpEhUqVEh23ZUqVeL06dOUKFGC0qVLU7p0aUqVKsWSJUvYvHmzdb0XXniB0qVL8/XXX7N9+3Zrr098+1xcXLhy5Yq1jtKlS+Pi4sLkyZO5cOHCU7Vp165dNq+//vpr8uTJYzPnpUmTJvzwww+
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Grupowanie danych\n",
"grouped_data = dane.groupby(['Gender', 'Level']).size().unstack()\n",
"\n",
"# Ustawienia kategorii i szerokości słupków\n",
"categories = grouped_data.columns\n",
"bar_width = 0.35\n",
"bar_positions_man = np.arange(len(categories))\n",
"bar_positions_woman = [pos + bar_width for pos in bar_positions_man]\n",
"\n",
"# Wygenerowanie wykresu słupkowego\n",
"fig, ax = plt.subplots()\n",
"\n",
"ax.bar(bar_positions_man, grouped_data.loc[1], width=bar_width, label='Man')\n",
"ax.bar(bar_positions_woman, grouped_data.loc[2], width=bar_width, label='Woman')\n",
"\n",
"# Dodanie wartości procentowych do słupków\n",
"for i, column in enumerate(categories):\n",
" for j, value in enumerate(grouped_data.index):\n",
" total = grouped_data[column].sum()\n",
" percent = grouped_data.loc[value, column] / total\n",
" height = grouped_data.loc[value, column]\n",
" ax.text(i + j * bar_width, height + 0.2, f'{percent:.0%}', ha='center', va='bottom') \n",
"\n",
"# Ustawienia etykiet i tytułów\n",
"plt.xlabel('Gender')\n",
"plt.ylabel('Count')\n",
"plt.title('Distribution of level by gender')\n",
"\n",
"# Dodanie legendy\n",
"plt.legend(title='Level')\n",
"\n",
"# Zmiana etykiet osi x\n",
"ax.set_xticks([pos + bar_width / 2 for pos in bar_positions_man])\n",
"ax.set_xticklabels(categories)\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 222,
"id": "8d81604c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Smoking\n",
" 1 181\n",
" 2 222\n",
" 3 172\n",
" 4 59\n",
" 5 10\n",
" 6 60\n",
" 7 207\n",
" 8 89\n",
" dtype: int64]"
]
},
"execution_count": 222,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane3 = [dane.groupby('Smoking').size()]\n",
"dane3 "
]
},
{
"cell_type": "code",
"execution_count": 246,
"id": "d85261ce",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMoAAAImCAYAAACipWb6AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3yN5//H8Ve2IFPtEasEScwgRhGqYrSKqBhVYq+atYrq195q05AaNYrSFh3i26Ko2kKLWi1SozKsSHLO+f2Rn/N1miAhxOH9fDzyaM51X/d1f+47n2p9cl3XbWMymUyIiIiIiIiIiIi85GwzOwAREREREREREZHngQplIiIiIiIiIiIiqFAmIiIiIiIiIiICqFAmIiIiIiIiIiICqFAmIiIiIiIiIiICqFAmIiIiIiIiIiICqFAmIiIiIiIiIiICqFAmIiIiIiIiIiICqFAmIiIiVsJkMmV2CM9FDCIiIiLy9KhQJiIiIk+sXbt2lCxZ0vzl7e1N+fLladasGcuWLcNgMFj0DwwMZMiQIWkePyIigsGDBz+y35AhQwgMDHzs6zxIQkIC48eP5+uvv37gtZ4HU6ZMoUqVKpQrV44NGzZkdjgptGvXjnbt2j3w+Pr16ylZsiQXLlx46rHMmjWLkiVLPvXrZLRffvmFkiVL8ssvvzzV6yxevJiBAweaP69YsYKaNWtSvXp1FixYkKJ/r169mD9/for2NWvW0LVr16caq4iISEayz+wARERE5MVQunRpRo0aBYDBYCA2NpaffvqJcePGsX//fqZPn46NjQ0As2fPJnv27GkeOzw8PE39evTowbvvvpvu2B/lypUrhIeHM378+Kd+rcd18uRJFi1aRMuWLXnrrbcoWrRoZoeUbrVr12b16tXkypUrs0N5qZ0+fZr58+ebC8MnT55kzJgxDBs2DDc3Nz788ENKly5NzZo1ATh48CCHDh1i8uTJKcZq0aIFn3/+OevWraN58+bP9D5EREQehwplIiIikiGyZ89OuXLlLNoCAwMpUqQI48ePJzAwkDfffBNILqo9DYUKFXoq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ly5YF4LXXXqNdu3ZMmTKFdevWmfuWKFHCYt+7I0eO8O233wLJxce5c+fyxhtv8OGHHwJQo0YNbt68aTE787PPPiMmJoaVK1eSP39+8/UaNmzIzJkz+eSTT8x969evT4sWLR76PPbs2YOvr69F4dLPz49u3brRpk0bTCYTrVq1on79+qxatYqsWbPSoEEDFi5cyIYNGyhQoAAjRoygYMGCFuP6+vqyefNmbt68ma79CUVERJ41zSgTERGRZya1WUP+/v7Ex8fTpEkTpk+fzv79+6lRowa9evV64Cyje9Ly1sJatWpZ/MU8MDAQBwcHdu3alf4beIC9e/cCWCxXg+T9wuzs7CzeUOjp6Wmxv1mePHkAuHPnTqpjHzp0iISEhBRjV6pUifz586fr7YdVq1bl3LlzNGvWjLlz53L8+HGaNGlC+/btLfqVL1/e/L29vT0eHh74+PhYzBpyd3fnxo0b5vu3s7OjYcOGFuPcK5rdH+OlS5fo3LkzJpOJUaNGPbRIBo9+Xnv27KFWrVoW+2OVL1/eXDR6GDs7O+rXr2/+7OTkxGuvvWbOjSJFilCxYkU2btwIJL/9dPPmzTRt2vSBubl7925y5sxJmTJlSEpKIikpCYPBQJ06dYiMjLSYOfjvwm+ePHnM93XmzBn++ecf87Lfe4KCglJcr1SpUuTOndt8PVtbW4v7uKdEiRKPfCZ//fUXBQoUSNHes2dPDhw4wIEDB/jwww+5ffs2s2fPZuDAgWzbto2lS5cyefJkihUrRr9+/VKcnz9/fgwGA3///fcjYxAREclMKpSJiIjIU3f
"text/plain": [
"<Figure size 1400x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dane['Gender'] = dane['Gender'].replace({1: 'Man', 2: 'Woman'})\n",
"smoking_counts = dane.groupby(['Smoking', 'Gender']).size()\n",
"\n",
"# Zamiana liczby na procent\n",
"smoking_percentages = smoking_counts / smoking_counts.groupby('Gender').sum() * 100\n",
"\n",
"# Sortowanie danych według stopnia 'Smoking'\n",
"smoking_percentages_sorted = smoking_percentages.sort_index(level='Smoking', sort_remaining=False)\n",
"\n",
"plt.figure(figsize=(14, 6))\n",
"\n",
"# Tworzenie wykresu słupkowego poziomego\n",
"ax = smoking_percentages_sorted.plot(kind='barh')\n",
"\n",
"# Dodawanie wartości procentowych do słupków\n",
"for i, value in enumerate(smoking_percentages_sorted):\n",
" ax.text(value + 0.1, i, f'{value:.2f}%', ha='left', va='center')\n",
"\n",
"# Dodanie legendy\n",
"plt.legend()\n",
"\n",
"# Ustawienia etykiet i tytułów\n",
"plt.xlabel('Percentage')\n",
"plt.ylabel('Smoking, Gender')\n",
"plt.title('Distribution of smoking by ender (%)')\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 224,
"id": "f5daf17c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Passive Smoker\n",
" 1 60\n",
" 2 284\n",
" 3 140\n",
" 4 161\n",
" 5 30\n",
" 6 30\n",
" 7 187\n",
" 8 108\n",
" dtype: int64]"
]
},
"execution_count": 224,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane3 = [dane.groupby('Passive Smoker').size()]\n",
"dane3 "
]
},
{
"cell_type": "code",
"execution_count": 247,
"id": "86122d04",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABRQAAAImCAYAAAAi8wbAAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3yN5//H8Vd2jEwl9q6ZxIwIUSRoKaVGK0ZVUbu1R9Vq7RIrYqZSo2aVquhAW5S2NqFGg7Y2lWUmOef8/sgv5+s0QRJRxPv5eHg057qv+7qv+z6fo/E517AymUwmRERERERERERERNLB+kl3QERERERERERERJ4dSiiKiIiIiIiIiIhIuimhKCIiIiIiIiIiIummhKKIiIiIiIiIiIikmxKKIiIiIiIiIiIikm5KKIqIiIiIiIiIiEi6KaEoIiIiIiIiIiIi6aaEooiIiIiIiIiIiKSbEooiIiLyzDGZTE+6C09FH0REREREngQlFEVERCRLdezYkbJly5r/lCtXjipVqtCyZUuWLl2KwWCwqB8QEMCwYcPS3f7WrVsZOnToQ+sNGzaMgICATF/nfhISEpg4cSIbN26877WeBlOnTsXX15fKlSuzfv36J92dB/r1118pW7Ysv/7665PuymPVsWNHOnbs+KS7YfY0xm1WOXfuHGXLlmXdunWP9TrffvstQUFB5tfff/89gYGB+Pr6MmHChFR/302cOJGRI0emaufnn3+mRYsWJCYmPtb+ioiIZBXbJ90BERERyX4qVKjA6NGjATAYDMTGxvLTTz8xYcIE9u3bx/Tp07GysgIgJCSE3Llzp7vt8PDwdNXr1asXb731Vob7/jBXrlwhPDyciRMnPvZrZdbJkydZuHAhb7zxBs2bN6dkyZJPuksPVLFiRVatWkXp0qWfdFdE0u369euMHTuWBQsWmF8PHjyYTp064eXlxciRIylZsiRt27YFkpOc69at4+uvv07VVu3atVm6dClz587lvffe+0/vQ0REJDOUUBQREZEslzt3bipXrmxRFhAQQIkSJZg4cSIBAQG89tprQHLy8XEoWrToY2n3SV8rPWJiYgB49dVXqV69+pPtTDqkFS8iT7vQ0FAqVqyIp6cnAPv378fGxoZ+/fphZWXFL7/8wq5du8wJxenTp/Pmm2/i4eGRZnu9evWiffv2tG3blnz58v1n9yEiIpIZmvIsIiIi/5mOHTuSL18+Vq5caS7791TkiIgIXnvtNby9valZsyaDBg3iypUr5vN/++03fvvtN/MU2ZTpsitXrqR+/frUqlWLnTt3pjmdMzExkXHjxuHj44OPjw9Dhw7l+vXr5uNpnXPv1Mlz584RGBgIwPDhw811/32ewWBg+fLlNGvWDG9vb+rVq8fUqVO5e/euxbXefvttvvjiC15++WU8PT157bXX+Omnnx76HCMiImjZsiVVqlSh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v79+wHYvn07u3bt4pNPPjFP5a9duzaOjo7MnDmTTp06WawPefjwYbp3706jRo2YOHEi1tbJ3/F/9tlnxMTEsGLFCgoVKgTASy+9RJMmTZg5cyazZs0yt9GoUSNat25tfp3RZ5zCYDAQEhJi/jxVqlSJBg0aEB4ezoABA2jVqhURERH8+uuv1KxZE4Avv/wSX19fChcunGab8+fPJ3fu3CxatMj8/t27liDArl270v0eOjs7Exoaio2NDQB//fUXs2fPJjo6Gjc3N+bMmUPFihWZNm2a+ZkB5tcAGzZs4Pjx46xevZpKlSqZ63Xs2JGpU6fyxRdfmOt6e3s/cCQhwC+//EKpUqXIlSuXuczDw4PRo0czZMgQ7ty5w8svv0z
"text/plain": [
"<Figure size 1500x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"dane['Gender'] = dane['Gender'].replace({1: 'Man', 2: 'Woman'})\n",
"smoking_counts = dane.groupby(['Passive Smoker', 'Gender']).size()\n",
"\n",
"# Zamiana liczby na procent\n",
"smoking_percentages = smoking_counts / smoking_counts.groupby('Gender').sum() * 100\n",
"\n",
"# Sortowanie danych według stopnia 'Passive smoker'\n",
"smoking_percentages_sorted = smoking_percentages.sort_index(level='Passive Smoker', sort_remaining=False)\n",
"\n",
"plt.figure(figsize=(15, 6))\n",
"\n",
"# Tworzenie wykresu słupkowego poziomego\n",
"ax = smoking_percentages_sorted.plot(kind='barh')\n",
"\n",
"# Dodawanie wartości procentowych do słupków\n",
"for i, value in enumerate(smoking_percentages_sorted):\n",
" ax.text(value + 0.1, i, f'{value:.2f}%', ha='left', va='center')\n",
"\n",
"# Dodanie legendy\n",
"plt.legend()\n",
"\n",
"# Ustawienia etykiet i tytułów\n",
"plt.xlabel('Percentage')\n",
"plt.ylabel('Passive Smoker, Gender')\n",
"plt.title('Distribution of passive smokers by gender (%)')\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 248,
"id": "28c8acde",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABRMAAAImCAYAAADALx25AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3zO1///8UcmEZlK7F0JTWJGxChCraK+VsX8WLVVVe1Rbc0SFBE7qKJUVc0WnxZt1R6hRmOrLRGJkeS6rt8f+eX69GqCLKI877dbbpVzzvu8z/udl6ReOcPKZDKZEBEREREREREREXkK66wegIiIiIiIiIiIiPw7KJkoIiIiIiIiIiIiqaJkooiIiIiIiIiIiKSKkokiIiIiIiIiIiKSKkomioiIiIiIiIiISKoomSgiIiIiIiIiIiKpomSiiIiIiIiIiIiIpIqSiSIiIiIiIiIiIpIqSiaKiIjIK89kMmX1EF6IMbys9G5FREREMo+SiSIiIvJC69ChA56enuYPLy8vypcvT/PmzVm2bBkGg8GifWBgIEOHDk11/9u3b2fIkCFPbTd06FACAwPTfZ/HiYuLY8KECXz//fePvdeLYMqUKfj7+1OuXDnWrVuX1cNJlef5bteuXYunpyeXL19+Ju3Te82/SWb9nXqSy5cvU6tWLe7cuQNAREQErVq1okKFCvTs2ZNbt25ZtN++fTsNGzZM9n3mzp071KxZk0uXLj3T8YqIiLyIlEwUERGRF16ZMmVYtWoVq1atYvny5UydOhUfHx/Gjx/Phx9+aDHzbNasWfTu3TvVfYeFhXH16tWntuvduzezZs1K1/if5MaNG4SFhZGQkPDM75Vep0+fZv78+dSrV48FCxbw5ptvZvWQUuV5vttatWqxatUq8uTJk+l9S+YwmUwMHz6cTp064e7uDsDgwYPJlSsXM2fOJDIykvHjx5vbGwwGgoODGThwIDY2NhZ9ubu785///Ifhw4dr5quIiLxybL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vtvo6GgWL15Mhw4dGDx4sPnd3rlzhwMHDqT4nEl8fX0tZsEdP37con7v3r307t2bunXrAuDv74+rq2uyvfcePXpEr169uHbtGl9++SWFChV64n0B+vTpY773m2++yfnz55k1axbVq1encePGTJw4ke+++47+/fsDsH79erJnz069evVS7G/9+vWcPXvWvNwXoEqVKuaxQ2JszZkzh3fffZeRI0cCiV87V1dXRo4cSefOnXn99dfNbZ8Uh0n7WM6fP59cuXIBUKxYMVq3bm2+X1pixdramk8//ZQcOXI89p3t2bMHSPy6/d2ECRMYMGAACxcuxNvbmxkzZnDnzh0WLVrEsmXLOHr0KOPHj+fhw4d06dLFvJ1CEh8fHwB+++03ihUr9tj7i4iIvEw0M1FEREReCklLFv/Oz8+Phw8f0qRJE6ZNm8aBAweoXr06ffv2TbH933l6ej71njVr1jQnsiBxibWdnR2//vpr2h/gMfbu3QtAkyZNLMrffvttbGxsLGa6ubu7W+wJmDdvXiBxyWZKDh8+TFxcXLK+K1WqRIECBVKcRfc4e/bsoXz58uZEIkCBAgUoX768RRuTyURgYCAJCQnmj8DAQB49emSRwPt7ohcw95v0LHv27MHf35/s2bOb+8mZMyeVKlVK9fs/fPgw8fHxyfa7Gzp0aLJZef9UqlSpJ9b7+/szc+ZM3n//fdauXcudO3cYMmRIsj0nBw8ezO+//06/fv1SlUiExNlwf1e3bl0OHz5MbGwsTk5O1KtXz2LZ8Lp162jQoMFjk2179uyhUKFC5kQiJM7aq127tvnzQ4cO8eDBgxS/dgC//PKLue3T4vDAgQOUK1f
"text/plain": [
"<Figure size 1500x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dane['Gender'] = dane['Gender'].replace({1: 'Man', 2: 'Woman'})\n",
"Genetic_risk_counts = dane.groupby(['Genetic Risk', 'Gender']).size()\n",
"Genetic_risk_percentages= Genetic_risk_counts / Genetic_risk_counts.groupby('Gender').sum() * 100\n",
"\n",
"Genetic_risk_percentages_sorted = Genetic_risk_percentages.sort_index(level='Genetic Risk', sort_remaining=False)\n",
"\n",
"plt.figure(figsize=(15, 6))\n",
"\n",
"# Tworzenie wykresu słupkowego poziomego\n",
"ax = Genetic_risk_percentages_sorted.plot(kind='barh')\n",
"\n",
"# Dodawanie wartości procentowych do słupków\n",
"for i, value in enumerate(Genetic_risk_percentages_sorted):\n",
" ax.text(value + 0.1, i, f'{value:.2f}%', ha='left', va='center')\n",
"\n",
"# Dodanie legendy\n",
"plt.legend()\n",
"\n",
"# Ustawienia etykiet i tytułów\n",
"plt.xlabel('Percentage')\n",
"plt.ylabel('Genetic risk, Gender')\n",
"plt.title('Distribution of genetic risk by gender (%)')\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()\n"
]
},
{
"cell_type": "code",
"execution_count": 227,
"id": "818e4ee5",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA44AAAImCAYAAAAcz9SjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAC6GElEQVR4nOzdeVyUVf//8dewC4KCCy7gWmmlhAoqLimjVlia0qJkZi7dmktqt1ullGYuJSqKpimKlRVm5p1py6191VvcbjU10sxbyxTJVEABi2Vmfn/wc2oEERQciPfz8eARc65znetzMcfgM+dc5xgsFosFERERERERketwsHcAIiIiIiIiUrYpcRQREREREZFCKXEUERERERGRQilxFBERERERkUIpcRQREREREZFCKXEUERERERGRQilxFBERERERkUIpcRQREREREZFCKXEUEZHbxmKx2DuEMhGD/H2oP4lIRaHEUUREAOjfvz9NmjSxfjVt2pQWLVoQHh7Oe++9h8lksqlvNBqZNGlSkdvfsmULEydOvGG9SZMmYTQab/o615Odnc3MmTPZsGHDda9VFsyZM4c2bdoQGBjI+vXr8x3fs2cPTZo0Yc+ePbc9thv9vOwZmz18/PHHzJ492/p63bp1NGnShDNnzpTodc6cOUOTJk1Yt25dqdQXESkKJ3sHICIiZcc999zDq6++CoDJZOLSpUts27aNGTNmsH//fubNm4fBYAAgJiaGypUrF7ntuLi4ItUbPnw4zzzzTLFjv5HffvuNuLg4Zs6cWerXulk//vgjy5Yt48knn+TRRx+lUaNG9g5JCvH222/TunVr6+vOnTsTHx9PzZo1S/Q6NWvWJD4+nnr16pVouyIixaHEUURErCpXrkxgYKBNmdFopGHDhsycOROj0UjPnj2BvCSzNNzOP47L2h/iaWlpADz88MMEBQXZNxgpNh8fH3x8fEq8XRcXl3z/LkVEbjdNVRURkRvq378/NWvW5KOPPrKWXTuFdNOmTfTs2ZOAgADatm3LuHHj+O2336zn7927l71791qnMl6d1vjRRx8RGhpKu3bt2LFjR4HTIXNycpg+fTrBwcEEBwczceJEUlJSrMcLOuev0/XOnDlDly5dAHjppZesda89z2QysXr1anr06EFAQACdO3dmzpw5ZGVl2Vzr2Wef5ZNPPuHBBx+kWbNm9OzZk23btt3w57hp0ybCw8Np0aIF7du3JzIykkuXLgGwcOFC+vfvD8CAAQOKNYX2xx9/ZOjQobRs2ZKWLVsyYsQITp8+DUBWVhZBQUHMmDHD5hyz2UyHDh2YOnWqtezjjz/m4YcfplmzZnTu3JmFCxeSm5tb5Diu+t///sdTTz1F8+bN6datG++995712AsvvECnTp0wm80250RGRtKlS5frPjOYkZFBZGQkISEhtGjRgrFjxxIXF0eTJk1s6m3evJnw8HCaN29O+/btmT59OleuXLEeX7hwId26dWPr1q306NGDZs2a8eCDD/Lpp5/atJOWlkZkZCTt2rWjefPmPPnkk+zatct63Gg0kpSUxKeffmqdnlrQVNWEhAT69etHixYt6NChg817XpD+/fszbtw4XnjhBVq2bMk//vGPfFNPzWYz0dHRGI1GmjVrhtFoZO7cueTk5BTYpsViYdKkSTRv3pzt27df99oiIoVR4igiIjfk6OhISEgIhw8fLjCR2L9/P+PGjeOBBx5g2bJlvPTSS+zevZt//vOfALz66qvcc8893HPPPcTHx3Pvvfdaz503bx4TJ05k4sSJ1x1V+eKLL0hMTGTWrFlMmDCBrVu3Mnz48CLHX7NmTWJiYgB4/vnnrd9fKzIykhkzZmA0Gnn77bfp168f77//PsOHD7dJaBITE4mNjeWFF15g0aJFODk58cILLxSaECxevJixY8dy3333sWDBAkaMGMFXX31F//79+eOPP3jiiSeIjIy0xnG9GK/1008/0bdvXy5evMisWbN44403OH36NBEREVy8eBFXV1cefPBBvvjiC5tkbc+ePZw/f55HH30UgKVLlzJlyhRCQkJYsmQJ/fr1Y9myZdaYimPmzJncd999LF68mI4dOzJ9+nTWrFkDwOOPP86vv/5q8xxkdnY2X3zxBb1797ZOhb7WiBEj+OKLLxg1ahTz5s0jMzOTqKgomzobNmxgxIgRNGrUiEWLFjFy5Eg+++yzfO/f+fPnmTZtGs888wzvvPMOfn5+TJo0iRMnTgB5yfaAAQPYsmULY8eOJSYmhlq1ajFkyBBr8hgTE0ONGjXo1KnTdaenbtu2jSFDhlC1alXmzZvH+PHj+eabb3jhhRcK/fl98cUXODs7s2jRogKnUi9btozVq1czYsQIVqxYQUREBMuXL2fJkiUFtjd9+nQ+//xzYmJiuP/++wu9tojI9WiqqoiIFEn16tXJyckhLS2N6tWr2xzbv38/rq6uPPfcc7i6ugJQtWpVvvvuOywWC3fccYf1echrk8O+ffvy0EMPFXptLy8vli9fbm3D29ubESNGsGPHDjp06HDD2F1cXLj77ruBvOmpBU2z/d///sfatWsZM2YMzz//PADt27enZs2aTJgwge3bt9OpUycA0tPTWbdunXWqq7u7O08//TS7d+/mwQcfzNf2pUuXePvtt3niiSesz5AC3HXXXfTr149169bx1FNPcccddwBwxx13FHkqcExMDG5ubsTFxVl/PiEhIXTt2pXly5czceJEHn30UdauXcu+ffusz+Rt2LCB+vXrExgYSHp6Om+//TZ9+vRh8uTJAHTo0IGqVasyefJkBg4cyJ133lmkeADCw8OtCyF17NiRc+fOsWjRIh5//HE6dOhArVq1WL9+PSEhIUDeKGF6ejq9e/cusL1du3axe/duFi5cyAMPPADA/fffT48ePfjf//4H5I2qz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GDMHDw4NPPvmE2bNnM2vWLO666y5efvl
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"Genetic_risk_counts = dane.groupby(['Genetic Risk', 'Level']).size()\n",
"\n",
"# Sortowanie danych według ryzyka genetycznego i liczby w odwrotnej kolejności\n",
"Genetic_risk_counts_sorted = Genetic_risk_counts.sort_index(level=['Genetic Risk', 'Level'], key=lambda x: x.map({'High': 1, 'Medium': 2, 'Low': 3}))\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"\n",
"# Tworzenie wykresu słupkowego horyzontalnego\n",
"ax = Genetic_risk_counts_sorted.plot(kind='barh')\n",
"\n",
"# Dodawanie wartości do słupków\n",
"for i, value in enumerate(Genetic_risk_counts_sorted):\n",
" ax.text(value + 0.1, i, str(value), ha='left', va='center')\n",
"\n",
"# Ustawienia etykiet i tytułów\n",
"plt.xlabel('Count')\n",
"plt.ylabel('Genetic Risk, Level')\n",
"plt.title('Distribution of level by genetic risk')\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 228,
"id": "18002f3f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Smoking 3.0\n",
"dtype: float64"
]
},
"execution_count": 228,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane[['Smoking']].median()"
]
},
{
"cell_type": "code",
"execution_count": 229,
"id": "f21f91ec",
"metadata": {},
"outputs": [
{
"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>Smoking</th>\n",
" <th>Alcohol use</th>\n",
" <th>Level</th>\n",
" </tr>\n",
" <tr>\n",
" <th>index</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>68</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>989</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>992</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>993</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>994</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>256 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Smoking Alcohol use Level\n",
"index \n",
"4 8 8 High\n",
"20 8 8 High\n",
"22 8 8 High\n",
"46 8 8 High\n",
"68 8 8 High\n",
"... ... ... ...\n",
"989 7 7 High\n",
"992 7 7 High\n",
"993 7 7 High\n",
"994 7 7 High\n",
"995 7 7 High\n",
"\n",
"[256 rows x 3 columns]"
]
},
"execution_count": 229,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"\n",
"x = dane[(dane['Level'] == 'High') & (dane['Smoking'] >=7) & (dane['Alcohol use'] >= 7)]\n",
"x_sorted = x[['Smoking', 'Alcohol use', 'Level']].sort_values(by=['Smoking', 'Alcohol use'], ascending=False)\n",
"x_sorted\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 230,
"id": "f10041ca",
"metadata": {},
"outputs": [
{
"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>Smoking</th>\n",
" <th>Alcohol use</th>\n",
" <th>Level</th>\n",
" </tr>\n",
" <tr>\n",
" <th>index</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>68</th>\n",
" <td>8</td>\n",
" <td>8</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>989</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>992</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>993</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>994</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>High</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>256 rows × 3 columns</p>\n",
"</div>"
],
"text/plain": [
" Smoking Alcohol use Level\n",
"index \n",
"4 8 8 High\n",
"20 8 8 High\n",
"22 8 8 High\n",
"46 8 8 High\n",
"68 8 8 High\n",
"... ... ... ...\n",
"989 7 7 High\n",
"992 7 7 High\n",
"993 7 7 High\n",
"994 7 7 High\n",
"995 7 7 High\n",
"\n",
"[256 rows x 3 columns]"
]
},
"execution_count": 230,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = dane[(dane['Smoking'] >= 7) & (dane['Alcohol use'] >= 7)]\n",
"x_sorted = x[['Smoking', 'Alcohol use', 'Level']].sort_values(by=['Smoking', 'Alcohol use'], ascending=False)\n",
"x_sorted"
]
},
{
"cell_type": "code",
"execution_count": 231,
"id": "15eebd5b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Air Pollution\n",
"8 19\n",
"5 20\n",
"7 30\n",
"4 90\n",
"1 141\n",
"3 173\n",
"2 201\n",
"6 326\n",
"Name: count, dtype: int64"
]
},
"execution_count": 231,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dane7 = dane['Air Pollution'].value_counts()\n",
"dane7.sort_values()"
]
},
{
"cell_type": "code",
"execution_count": 232,
"id": "9bd91fc9",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA44AAAImCAYAAAAcz9SjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAADBm0lEQVR4nOzde1xU1fo/8M9wvyt4QQnES4p6cEQFcbykDFJiaUL1VULzgh4VMS+pWCmlqahHULwgKqOoWVKEnkwss46ZKJoYGGlqmHdE5TqgcpmZ3x/8nBoHcAZmYJTP+/XqpbP22ms/M/OcTs+stdcWKBQKBYiIiIiIiIhqYNTYARAREREREZFhY+FIREREREREtWLhSERERERERLVi4UhERERERES1YuFIREREREREtWLhSERERERERLVi4UhERERERES1YuFIREREREREtWLhSEREDUKhUDR2CAYRA9HTME+JyBCxcCQiIowbNw5ubm7Kf7p27YpevXohMDAQu3fvhkwmU+kvFouxcOFCjcf/4YcfEB4e/tR+CxcuhFgsrvN1alJeXo7IyEgcOHCgxmsZgjVr1sDb2xseHh7Yv3+/2vFTp07Bzc0Np06davDYnvZ5NWZsQFUOjxs3rlGuDai//w0bNsDNzU2rMYqLixEeHo4zZ84o2xr7fRERPWbS2AEQEZFh6N69Oz766CMAgEwmQ1FREX766SesWLEC6enpWLt2LQQCAQBg48aNsLGx0XjshIQEjfqFhobinXfe0Tr2p7l79y4SEhIQGRmp92vV1aVLl7Bt2zb83//9H15//XV07NixsUN6pjzO3WfZhQsXsH//fgQGBirbnof3RUTPBxaOREQEALCxsYGHh4dKm1gsRocOHRAZGQmxWIyRI0cCqCoy9aFdu3Z6Gbexr6WJwsJCAMCrr74KT0/Pxg3mGfTiiy82dgh68by+LyJ69nCpKhER1WrcuHFo3bo19u7dq2x7cglpSkoKRo4cCaFQiH79+mHevHm4e/eu8vzTp0/j9OnTyqV8j5f17d27Fz4+Pujfvz+OHz9e7XLIiooKLFu2DF5eXvDy8kJ4eDjy8/OVx6s75+bNm3Bzc0NycjJu3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dsWvXLnh6euL27ds4efIkPv30U5w9exYVFRW1xtKlSxeNYu7Vq5fKd9q9e3e4uLjgzJkzePDgAX777TcMHz5cWTQCVT9o+Pj4NOgusqdPn4axsbHaZ/z4u/xnLP/8wQao+hyBmvOUiOhpOONIRERPlZubCwsLCzRv3lztWK9evbB161YkJCRAIpEgLi4OrVq1wpQpUzB+/Phax23RosVTr/3kDKeRkRGaN2+O4uJird5DbR4vM23VqpVKu4mJCezt7SGVSpVtlpaWKn0eF8dP3rf35NhPvo/Hbf8cW1uFhYVISUlBSkqK2jEHBwdlfCNGjMAXX3yBxYsX49ixYyguLlYuU328KU9NM3OP71XV1JOf4ePv+PHn8MYbbyAuLg6HDx9G//79kZqaqrLbbXW+/vprREdHIycnB82bN0fXrl1hYWHx1Fiq+8yr07p1a7W2Fi1aoLi4GFKpFAqFQi/fn7aKiopgb28PExPV/3x7/JnXlqdGRlVzBTXlKRHR07BwJCKiWslkMpw+fRq9e/dWmXH5p0GDBmHQoEF4+PAh0tLSsGvXLqxYsQIeHh7o2bNnva7/ZIEok8lQUFCgLEgEAoHafVuP703TVLNmzQAA9+7dg7Ozs7K9oqICBQUFsLe3r0voKmPfv38fnTp1Ujl27949uLi41HlsW1tb9O/fHxMnTlQ79s/i4vXXX0dcXBxOnTqFb775Br1791Ze187ODkDVMyTbt2+vNo6mxddjT97ref/+fQB
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"air_pollution = dane.groupby(['Air Pollution', 'Level']).size()\n",
"\n",
"# Sortowanie danych według ryzyka genetycznego i liczby w odwrotnej kolejności\n",
"air_pollution_sorted = air_pollution.sort_index(level=['Air Pollution', 'Level'], key=lambda x: x.map({'High': 1, 'Medium': 2, 'Low': 3}))\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"\n",
"# Tworzenie wykresu słupkowego horyzontalnego\n",
"ax = air_pollution_sorted.plot(kind='barh')\n",
"\n",
"# Dodawanie wartości do słupków\n",
"for i, value in enumerate(air_pollution_sorted):\n",
" ax.text(value + 0.1, i, str(value), ha='left', va='center')\n",
"\n",
"# Ustawienia etykiet i tytułów\n",
"plt.xlabel('Count')\n",
"plt.ylabel('Air Pollution, Level')\n",
"plt.title('Distribution of level by air pollution')\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 242,
"id": "402f9c5a",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA6EAAANBCAYAAAARH7ioAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd1xX5f//8QdTRHERioPEiRtRDPfATMXcZi5McZYjNTXJcs/UnB9XYg7MTW5L0zQtw1GOVLTIhQMHLpQNvz/8+f5GIKK9OZg+77fb+3aDc673eV7n8Ha8uK5zHYukpKQkRERERERERAxgmdkdEBERERERkVeHilARERERERExjIpQERERERERMYyKUBERERERETGMilARERERERExjIpQERERERERMYyKUBERERERETGMilARERERERExjIpQERHJVElJSZndBTGTl/ln+TKfm4iI0VSEioi84oYNG4a3t/cT9/v6+uLr62v23NjYWCZOnMjmzZvNfuzMsG3bNurVq0f58uUZMWJEmm0PHDhA3759qVWrFu7u7jRs2JBJkyZx8+ZNg3r7ZGFhYbi5uREUFPRM75s3bx4BAQGm72fPno2bm5u5u5eqx1nly5cnMjIy1TYrV67Ezc0tzc96aq5du0avXr24fPlymu2Cg4Nxc3MjODj4mY4vIvIqUhEqIiKZ4vr16yxZsoT4+PjM7opZjB49mrx587Jo0SL8/Pye2G7atGl07doVa2trhg8fzoIFC+jYsSNbt26lbdu2Ty12XlQzZswgKirK9P0777zD6tWrDe1DfHw8u3btSnXftm3bnuuYP//8M3v27Hlqu7Jly7J69WrKli37XDkiIq8S68zugIiIyMvgzp071KhRAy8vrye22bZtGwsXLsTf358uXbqYtletWpW6devSokULxo4dy/z58w3occZydnbG2dnZ0MxKlSqxfft2mjdvnmx7eHg4hw8fpnTp0ty7dy9DsrNnz07FihUz5NgiIi8bjYSKiMgz+/7772nVqhXly5enRo0ajBs3jocPH6Zo06FDBzw8PChXrhyNGjUiMDAQeDTls379+gD4+/ubpkgOGzaMbt26sWbNGt58800qVKhAu3btOHfuHD/88ANNmzbF3d2dd955h9OnTyfLW7t2La1ataJixYpUqFCB5s2bJxv9CgoKws3NjWPHjtGyZUsqVKhA06ZN0zVCduLECbp164aXlxeVKlWid+/e/PHHH8D/TcME+N///oebmxthYWGpHmfBggUUL16c9957L8W+119/naFDh1K5cmUSExMBSEhIYMWKFTRt2pQKFSpQt25dpk6dSkxMjOl9w4YN47333mPkyJF4enrSsmVL4uPjcXNzY86cObRu3ZrKlSszd+5cAK5cucKgQYN44403cHd357333uPUqVNpnv+hQ4fo1q0bVapUoVy5cnh7ezN79mxTPx+f/5w5c0xfpzYdd9u2bbRq1QoPDw9q1KjBiBEjuHv3rmn/7NmzadCgAXv27KFp06aUK1eOhg0b8s0336TZv8d8fHz46aefuH//frLt3377LUWKFKFUqVLJtickJLBw4ULefvttKlSoQMWKFWnXrh0HDhwAHn1m/P39Aahfvz7Dhg0DwNvbmwkTJvDee+9RqVIlRowYkWw6bmRkJN7e3jRq1IjY2Fjg0T2lfn5+VKtW7YWYdi0ikplUhIqICPBoKmNqr38uyLJ582b69OlD0aJF+d///kffvn3ZtGkTH3zwgantnj176NOnD2XLlmXu3LnMnj2bggULMnbsWH799Vfy5s3LnDlzAHj//fdNXwMcPXqU5cuXM2zYMCZMmMCff/5Jz549mThxIr169WLixIlcvXqVwYMHm96zYsUKRowYQf369VmwYAFTpkzBxsaGIUOGcOXKlWT979WrF/Xr12fOnDkUKVKEQYMGPXEKJ8Avv/xC+/btSUxMZPz48YwbN46rV6/Srl07QkNDTdMwAdq0acPq1avJmzdviuPcuHGDkJAQ6tati4WFRapZ7dq1o0ePHlhaPvrnecSIEUyYMAFvb2/mzZtHx44dCQwMTHatAQ4fPsyFCxeYPXs2ffr0wdr60USnefPm0bBhQ7744gvq169PREQE7dq14+TJk3z22WdMmzaNxMREOnbsSGhoaKp9CgkJoUuXLuTKlYvp06czb948KlWqxJw5c9i6dStAivNPzdy5cxk4cCDu7u7MmjWLPn368N133+Hr60t0dHSy6zRmzBg6d+7MwoULKVSoEMOGDXti//6uYcOGJCQkpPh5btu2jSZNmqRoP3XqVP73v//x7rvvsmjRIsaMGcPt27f58MMPefjwIXXr1uX9998HHhXYH3zwgem9K1aswM3NjdmzZ6cYec2ePTvjx4/n/PnzplHtr7/+mp9++onx48fz2muvPfVcREReZpqOKyIiXL58Oc172d544w3g0WjO1KlTqVWrFlOnTjXtd3V1pUuXLuzdu5e6devy559/0qJFC4YPH25q4+HhgZeXF4cOHaJSpUqULl0aeDQCWKZMGVO7yMhIZsyYQbFixQA4ePAgq1evZsmSJVSrVg14tFjM5MmTuXfvHjly5ODSpUv4+fnRp08f03EKFSpEq1at+PXXXylQoIBpe6dOnejbty8AtWrVomXLlsydO9c0MvtP06ZNw8XFhUWLFmFlZQVAzZo1adCgAbNnz2bGjBmmaZjOzs5PnJJ57do1U7/S488//2TdunUMGDDAVAjVqFGDvHnzMnToUH788Ufq1KkDPPoFwujRoylcuHCyY1SoUIGePXuavp8+fTp37txh5cqVFCxYEIDatWvj4+PDzJkzmTVrVop+hISEUL16daZMmWIqjmvUqMGePXs4dOgQTZs2fer53717l3nz5vHOO+8wcuRI0/aSJUvSsWNHgoKC6NChAwBRUVGMHz/e9LN2dXWlXr167N271/SZeJLXXnuNKlWq8O2339KiRQvg0Wf72LFjTJ48OcU05+vXrzNw4MBkC2/Z2dnRr18/zpw5g4eHB6+//joApUuXTvazy5s3L8OGDTNdk38uSFStWjU6dOjAwoULqVixIlOnTuXdd9995oWRREReRipCRUQEJycn5s2bl+q+vxcNf/31l2m10L8vKFSlShWyZ8/OTz/9RN26denevTsADx8+5OLFi5w7d44TJ04AEBcXl2ZfcubMmazYcHJyAkhW3OTKlQvAVIQ+niZ5//59zp8/z/nz501TKv+Z9/dRKwsLC1MxGRUVRdasWZO1ffjwISdOnKBPnz6mAhQgR44cpsIovR4XK4+nsD7NwYMHAWjatGmy7U2aNMHf35/g4GBTEWpnZ2cqlv6uZMmSyb4/cOAApUuXJl++fKafn6WlJbVr12bTpk2p9qNFixa0aNGCmJgYLl68yIULFzh58iQJCQlP/Vk+dvToUWJjY1Oci6enJwULFiQ4ONhUhELyn/Xj+0r/Od37SXx8fBg7diz379/HwcGBrVu3UrZsWVxdXVO0nTZtGgARERFcuHCBc+fOsXv3buDpn9NixYqZfqZPMnjwYPbt20evXr14/fXXTVN7RURedSpCRUQEW1tbypcvn+q+bNmymb6+c+cO8Ggl2NGjR6doe/36deDRf+pHjhzJ999/j4WFBYULF6Zy5crA05+3mD179lS3/7NA/LuLFy8yYsQIfvnlF6ytrSlatKjpfsR/5uXLly/Z946OjiQlJXH//v0UGffv3ycpKSnV6ZOvvfZainsP05I/f34sLCzSXP323r17WFlZkS1bNtO9ko+L8Mesra3JnTt3smxHR8dUp/j+s9937tzhwoULTxz1/vvqto9FR0czduxYNm7cSHx8PIUKFcLDwwNra+t0Pzvz8bmk9zr+/efwuNBLb9Zbb73FmDFj+P7772nZsiXbt29PUfw+duLECUaPHs2JEyews7OjePHiphHip+WlZ0qtvb09DRs25Msvv6Rq1appfoZFRF4lKkJFRCTdcuTIAcDQoUNNU3T/LmfOnMCjEaDQ0FC++uorKlWqhK2tLVFRUaxdu9bsfUpMTKRnz57Y2NiwZs0aypQ
"text/plain": [
"<Figure size 1000x800 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data = dane.drop(['Patient Id', 'Level'], axis=1)\n",
"\n",
"# Stworzenie macierzy korelacji\n",
"corr_matrix = data.corr()\n",
"\n",
"# Stworzenie wykresu heatmapy\n",
"plt.figure(figsize=(10, 8))\n",
"sns.heatmap(corr_matrix, annot=False, cmap='coolwarm', fmt='.2f')\n",
"\n",
"# Dodanie tytułu\n",
"plt.title('Heatmap of Correlation Matrix')\n",
"\n",
"# Wyświetlenie wykresu\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00915ec0",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import sklearn "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8388706b",
"metadata": {},
"outputs": [
{
"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>Patient Id</th>\n",
" <th>Age</th>\n",
" <th>Gender</th>\n",
" <th>Air Pollution</th>\n",
" <th>Alcohol use</th>\n",
" <th>Dust Allergy</th>\n",
" <th>OccuPational Hazards</th>\n",
" <th>Genetic Risk</th>\n",
" <th>chronic Lung Disease</th>\n",
" <th>Balanced Diet</th>\n",
" <th>...</th>\n",
" <th>Fatigue</th>\n",
" <th>Weight Loss</th>\n",
" <th>Shortness of Breath</th>\n",
" <th>Wheezing</th>\n",
" <th>Swallowing Difficulty</th>\n",
" <th>Clubbing of Finger Nails</th>\n",
" <th>Frequent Cold</th>\n",
" <th>Dry Cough</th>\n",
" <th>Snoring</th>\n",
" <th>Level</th>\n",
" </tr>\n",
" <tr>\n",
" <th>index</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>P1</td>\n",
" <td>33</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>Low</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>P10</td>\n",
" <td>17</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>8</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>Medium</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>P100</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>...</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>9</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>P1000</td>\n",
" <td>37</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>5</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>P101</td>\n",
" <td>46</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>995</th>\n",
" <td>P995</td>\n",
" <td>44</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>8</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>996</th>\n",
" <td>P996</td>\n",
" <td>37</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>9</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>997</th>\n",
" <td>P997</td>\n",
" <td>25</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>...</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>9</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>998</th>\n",
" <td>P998</td>\n",
" <td>18</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>High</td>\n",
" </tr>\n",
" <tr>\n",
" <th>999</th>\n",
" <td>P999</td>\n",
" <td>47</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>...</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>9</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>High</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1000 rows × 25 columns</p>\n",
"</div>"
],
"text/plain": [
" Patient Id Age Gender Air Pollution Alcohol use Dust Allergy \\\n",
"index \n",
"0 P1 33 1 2 4 5 \n",
"1 P10 17 1 3 1 5 \n",
"2 P100 35 1 4 5 6 \n",
"3 P1000 37 1 7 7 7 \n",
"4 P101 46 1 6 8 7 \n",
"... ... ... ... ... ... ... \n",
"995 P995 44 1 6 7 7 \n",
"996 P996 37 2 6 8 7 \n",
"997 P997 25 2 4 5 6 \n",
"998 P998 18 2 6 8 7 \n",
"999 P999 47 1 6 5 6 \n",
"\n",
" OccuPational Hazards Genetic Risk chronic Lung Disease \\\n",
"index \n",
"0 4 3 2 \n",
"1 3 4 2 \n",
"2 5 5 4 \n",
"3 7 6 7 \n",
"4 7 7 6 \n",
"... ... ... ... \n",
"995 7 7 6 \n",
"996 7 7 6 \n",
"997 5 5 4 \n",
"998 7 7 6 \n",
"999 5 5 4 \n",
"\n",
" Balanced Diet ... Fatigue Weight Loss Shortness of Breath \\\n",
"index ... \n",
"0 2 ... 3 4 2 \n",
"1 2 ... 1 3 7 \n",
"2 6 ... 8 7 9 \n",
"3 7 ... 4 2 3 \n",
"4 7 ... 3 2 4 \n",
"... ... ... ... ... ... \n",
"995 7 ... 5 3 2 \n",
"996 7 ... 9 6 5 \n",
"997 6 ... 8 7 9 \n",
"998 7 ... 3 2 4 \n",
"999 6 ... 8 7 9 \n",
"\n",
" Wheezing Swallowing Difficulty Clubbing of Finger Nails \\\n",
"index \n",
"0 2 3 1 \n",
"1 8 6 2 \n",
"2 2 1 4 \n",
"3 1 4 5 \n",
"4 1 4 2 \n",
"... ... ... ... \n",
"995 7 8 2 \n",
"996 7 2 4 \n",
"997 2 1 4 \n",
"998 1 4 2 \n",
"999 2 1 4 \n",
"\n",
" Frequent Cold Dry Cough Snoring Level \n",
"index \n",
"0 2 3 4 Low \n",
"1 1 7 2 Medium \n",
"2 6 7 2 High \n",
"3 6 7 5 High \n",
"4 4 2 3 High \n",
"... ... ... ... ... \n",
"995 4 5 3 High \n",
"996 3 1 4 High \n",
"997 6 7 2 High \n",
"998 4 2 3 High \n",
"999 6 7 2 High \n",
"\n",
"[1000 rows x 25 columns]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f02e1f34",
"metadata": {},
"outputs": [
{
"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>Patient Id</th>\n",
" <th>Age</th>\n",
" <th>Gender</th>\n",
" <th>Air Pollution</th>\n",
" <th>Alcohol use</th>\n",
" <th>Dust Allergy</th>\n",
" <th>OccuPational Hazards</th>\n",
" <th>Genetic Risk</th>\n",
" <th>chronic Lung Disease</th>\n",
" <th>Balanced Diet</th>\n",
" <th>...</th>\n",
" <th>Fatigue</th>\n",
" <th>Weight Loss</th>\n",
" <th>Shortness of Breath</th>\n",
" <th>Wheezing</th>\n",
" <th>Swallowing Difficulty</th>\n",
" <th>Clubbing of Finger Nails</th>\n",
" <th>Frequent Cold</th>\n",
" <th>Dry Cough</th>\n",
" <th>Snoring</th>\n",
" <th>Level</th>\n",
" </tr>\n",
" <tr>\n",
" <th>index</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>P1</td>\n",
" <td>33</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>P10</td>\n",
" <td>17</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>7</td>\n",
" <td>8</td>\n",
" <td>6</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>P100</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>...</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>9</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>P1000</td>\n",
" <td>37</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>5</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>P101</td>\n",
" <td>46</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>7</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>...</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>4</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 25 columns</p>\n",
"</div>"
],
"text/plain": [
" Patient Id Age Gender Air Pollution Alcohol use Dust Allergy \\\n",
"index \n",
"0 P1 33 1 2 4 5 \n",
"1 P10 17 1 3 1 5 \n",
"2 P100 35 1 4 5 6 \n",
"3 P1000 37 1 7 7 7 \n",
"4 P101 46 1 6 8 7 \n",
"\n",
" OccuPational Hazards Genetic Risk chronic Lung Disease \\\n",
"index \n",
"0 4 3 2 \n",
"1 3 4 2 \n",
"2 5 5 4 \n",
"3 7 6 7 \n",
"4 7 7 6 \n",
"\n",
" Balanced Diet ... Fatigue Weight Loss Shortness of Breath \\\n",
"index ... \n",
"0 2 ... 3 4 2 \n",
"1 2 ... 1 3 7 \n",
"2 6 ... 8 7 9 \n",
"3 7 ... 4 2 3 \n",
"4 7 ... 3 2 4 \n",
"\n",
" Wheezing Swallowing Difficulty Clubbing of Finger Nails \\\n",
"index \n",
"0 2 3 1 \n",
"1 8 6 2 \n",
"2 2 1 4 \n",
"3 1 4 5 \n",
"4 1 4 2 \n",
"\n",
" Frequent Cold Dry Cough Snoring Level \n",
"index \n",
"0 2 3 4 1 \n",
"1 1 7 2 2 \n",
"2 6 7 2 3 \n",
"3 6 7 5 3 \n",
"4 4 2 3 3 \n",
"\n",
"[5 rows x 25 columns]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = dane.replace({'Level':{'High' : 3, 'Medium' : 2, 'Low' : 1}})\n",
"data.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52632684",
"metadata": {},
"outputs": [],
"source": [
"import sklearn"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a47f580a",
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(10)\n",
"np.set_printoptions(precision=6, suppress=True)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7caae544",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Y shape: (1000,)\n",
"X shape: (1000, 23)\n"
]
}
],
"source": [
"X = data.drop(['Level', 'Patient Id'], axis=1)\n",
"y = data['Level']\n",
"\n",
"\n",
"print(\"Y shape:\", y.shape)\n",
"print(\"X shape:\", X.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9139408a",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"X_train, X_test, y_train, y_test = train_test_split (X, y)\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f45152a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X_train shape: (750, 23)\n",
"y_train shape: (750,)\n",
"X_test shape: (250, 23)\n",
"y_test shape: (250,)\n"
]
}
],
"source": [
"print(\"X_train shape:\", X_train.shape)\n",
"print(\"y_train shape:\", y_train.shape)\n",
"print(\"X_test shape:\", X_test.shape)\n",
"print(\"y_test shape:\", y_test.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ba2674d",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\HP\\anaconda3\\lib\\site-packages\\sklearn\\linear_model\\_logistic.py:460: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
"STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
"\n",
"Increase the number of iterations (max_iter) or scale the data as shown in:\n",
" https://scikit-learn.org/stable/modules/preprocessing.html\n",
"Please also refer to the documentation for alternative solver options:\n",
" https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n"
]
},
{
"data": {
"text/html": [
"<style>#sk-container-id-1 {color: black;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-r
],
"text/plain": [
"LogisticRegression()"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.linear_model import LogisticRegression\n",
"classifier = LogisticRegression()\n",
"classifier.fit(X_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba0a5bda",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.019763, 0.980237, 0. ],\n",
" [0. , 0. , 1. ],\n",
" [0. , 0.000002, 0.999998],\n",
" [0.999979, 0.000021, 0. ],\n",
" [0. , 0.000038, 0.999962],\n",
" [0.000022, 0.983401, 0.016577],\n",
" [0. , 0.023981, 0.976019],\n",
" [0.025065, 0.943631, 0.031305],\n",
" [0. , 0.011278, 0.988722],\n",
" [0.077079, 0.922921, 0. ],\n",
" [0.000003, 0.000326, 0.999672],\n",
" [0.000473, 0.999527, 0. ],\n",
" [0.16753 , 0.83247 , 0. ],\n",
" [0.995731, 0.004269, 0. ],\n",
" [0.949387, 0.050613, 0. ],\n",
" [0.21037 , 0.78963 , 0. ],\n",
" [0. , 0. , 1. ],\n",
" [0.91181 , 0.045917, 0.042272],\n",
" [0. , 0.002178, 0.997822],\n",
" [0.984437, 0.015558, 0.000005],\n",
" [0. , 0.002066, 0.997934],\n",
" [0.99922 , 0.00078 , 0. ],\n",
" [0. , 0.000298, 0.999702],\n",
" [0. , 0.004236, 0.995764],\n",
" [0. , 0.000004, 0.999996],\n",
" [0.238042, 0.760375, 0.001583],\n",
" [0.025065, 0.943631, 0.031305],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0.997777, 0.002223, 0. ],\n",
" [0.238042, 0.760375, 0.001583],\n",
" [0.913746, 0.086254, 0. ],\n",
" [0.002141, 0.997859, 0. ],\n",
" [0. , 0.004236, 0.995764],\n",
" [0.99922 , 0.00078 , 0. ],\n",
" [0.00192 , 0.99808 , 0. ],\n",
" [0. , 0.012453, 0.987547],\n",
" [0.00145 , 0.99855 , 0. ],\n",
" [0. , 0. , 1. ],\n",
" [0.00248 , 0.99752 , 0. ],\n",
" [0.998712, 0.000937, 0.000351],\n",
" [0.238042, 0.760375, 0.001583],\n",
" [0.001213, 0.97811 , 0.020677],\n",
" [0. , 0. , 1. ],\n",
" [0.015839, 0.984161, 0. ],\n",
" [0. , 0.023981, 0.976019],\n",
" [0.000003, 0.000326, 0.999672],\n",
" [0.930462, 0.069418, 0.000121],\n",
" [0. , 0.002178, 0.997822],\n",
" [0. , 0.000003, 0.999997],\n",
" [0.001321, 0.998655, 0.000024],\n",
" [0.001178, 0.998807, 0.000014],\n",
" [0.00035 , 0.99965 , 0. ],\n",
" [0.05124 , 0.948155, 0.000606],\n",
" [0. , 0. , 1. ],\n",
" [0.001321, 0.998655, 0.000024],\n",
" [0. , 0. , 1. ],\n",
" [0. , 0.004285, 0.995715],\n",
" [0.000004, 0.02071 , 0.979285],\n",
" [0.969283, 0.030717, 0. ],\n",
" [0.000063, 0.040843, 0.959093],\n",
" [0. , 0.002066, 0.997934],\n",
" [0.942577, 0.018654, 0.038768],\n",
" [0. , 0.000002, 0.999998],\n",
" [0.870813, 0.129142, 0.000044],\n",
" [0. , 0. , 1. ],\n",
" [0.913746, 0.086254, 0. ],\n",
" [0.000637, 0.999363, 0. ],\n",
" [0. , 0.000003, 0.999997],\n",
" [0. , 0.000298, 0.999702],\n",
" [0.029989, 0.970011, 0. ],\n",
" [0.994782, 0.000846, 0.004371],\n",
" [0.999889, 0.000075, 0.000035],\n",
" [0.947557, 0.052443, 0. ],\n",
" [0.029989, 0.970011, 0. ],\n",
" [0.129826, 0.870174, 0. ],\n",
" [0.055579, 0.94417 , 0.000251],\n",
" [0.002141, 0.997859, 0. ],\n",
" [0.001398, 0.9986 , 0.000002],\n",
" [0. , 0.000062, 0.999938],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0. , 0.000004, 0.999996],\n",
" [0.969283, 0.030717, 0. ],\n",
" [0. , 0.004236, 0.995764],\n",
" [0.001178, 0.998807, 0.000014],\n",
" [0. , 0. , 1. ],\n",
" [0. , 0.014023, 0.985977],\n",
" [0. , 0. , 1. ],\n",
" [0.033577, 0.966423, 0. ],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0. , 0.000062, 0.999938],\n",
" [0.099592, 0.900408, 0. ],\n",
" [0.000177, 0.999787, 0.000036],\n",
" [0.997699, 0.002301, 0. ],\n",
" [0.930462, 0.069418, 0.000121],\n",
" [0.00248 , 0.99752 , 0. ],\n",
" [0.00248 , 0.99752 , 0. ],\n",
" [0.238042, 0.760375, 0.001583],\n",
" [0.101768, 0.898232, 0. ],\n",
" [0.029989, 0.970011, 0. ],\n",
" [0.98255 , 0.01745 , 0. ],\n",
" [0. , 0.004285, 0.995715],\n",
" [0.000332, 0.999668, 0. ],\n",
" [0.999328, 0.000672, 0. ],\n",
" [0. , 0.023981, 0.976019],\n",
" [0.997777, 0.002223, 0. ],\n",
" [0.949387, 0.050613, 0. ],\n",
" [0.930462, 0.069418, 0.000121],\n",
" [0.00028 , 0.99972 , 0. ],\n",
" [0. , 0.004236, 0.995764],\n",
" [0. , 0. , 1. ],\n",
" [0.998712, 0.000937, 0.000351],\n",
" [0. , 0.000038, 0.999962],\n",
" [0.000898, 0.99788 , 0.001222],\n",
" [0.91181 , 0.045917, 0.042272],\n",
" [0.984437, 0.015558, 0.000005],\n",
" [0.000003, 0.000326, 0.999672],\n",
" [0.099592, 0.900408, 0. ],\n",
" [0.033577, 0.966423, 0. ],\n",
" [0.969283, 0.030717, 0. ],\n",
" [0.999328, 0.000672, 0. ],\n",
" [0. , 0. , 1. ],\n",
" [0. , 0.008068, 0.991932],\n",
" [0. , 0.000298, 0.999702],\n",
" [0.003572, 0.996428, 0. ],\n",
" [0.997777, 0.002223, 0. ],\n",
" [0. , 0.000002, 0.999998],\n",
" [0.000063, 0.040843, 0.959093],\n",
" [0.947557, 0.052443, 0. ],\n",
" [0.907855, 0.092061, 0.000084],\n",
" [0.00145 , 0.99855 , 0. ],\n",
" [0.101768, 0.898232, 0. ],\n",
" [0. , 0.009143, 0.990857],\n",
" [0.861344, 0.134685, 0.00397 ],\n",
" [0. , 0.004236, 0.995764],\n",
" [0.990975, 0.009025, 0. ],\n",
" [0.870813, 0.129142, 0.000044],\n",
" [0.995587, 0.000049, 0.004364],\n",
" [0. , 0.000298, 0.999702],\n",
" [0.942577, 0.018654, 0.038768],\n",
" [0. , 0.000005, 0.999995],\n",
" [0.000898, 0.99788 , 0.001222],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0.099592, 0.900408, 0. ],\n",
" [0.099592, 0.900408, 0. ],\n",
" [0.999979, 0.000021, 0. ],\n",
" [0.995587, 0.000049, 0.004364],\n",
" [0.001398, 0.9986 , 0.000002],\n",
" [0.000003, 0.000326, 0.999672],\n",
" [0.999889, 0.000075, 0.000035],\n",
" [0.861344, 0.134685, 0.00397 ],\n",
" [0.000003, 0.000326, 0.999672],\n",
" [0.969283, 0.030717, 0. ],\n",
" [0.238042, 0.760375, 0.001583],\n",
" [0.000977, 0.999023, 0. ],\n",
" [0.002141, 0.997859, 0. ],\n",
" [0.000005, 0.000077, 0.999918],\n",
" [0.997699, 0.002301, 0. ],\n",
" [0. , 0.004236, 0.995764],\n",
" [0. , 0. , 1. ],\n",
" [0.999425, 0.000575, 0. ],\n",
" [0.974593, 0.025407, 0. ],\n",
" [0.002453, 0.997528, 0.000019],\n",
" [0.84426 , 0.15574 , 0. ],\n",
" [0.000898, 0.99788 , 0.001222],\n",
" [0.949387, 0.050613, 0. ],\n",
" [0. , 0.000032, 0.999968],\n",
" [0.000332, 0.999668, 0. ],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0.05124 , 0.948155, 0.000606],\n",
" [0.999889, 0.000075, 0.000035],\n",
" [0. , 0. , 1. ],\n",
" [0.099592, 0.900408, 0. ],\n",
" [0. , 0.000298, 0.999702],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0. , 0.000298, 0.999702],\n",
" [0.598003, 0.391491, 0.010506],\n",
" [0.002141, 0.997859, 0. ],\n",
" [0.001321, 0.998655, 0.000024],\n",
" [0.129826, 0.870174, 0. ],\n",
" [0.033577, 0.966423, 0. ],\n",
" [0.101768, 0.898232, 0. ],\n",
" [0.999979, 0.000021, 0. ],\n",
" [0.870813, 0.129142, 0.000044],\n",
" [0.002453, 0.997528, 0.000019],\n",
" [0.129826, 0.870174, 0. ],\n",
" [0. , 0.000032, 0.999968],\n",
" [0. , 0.004285, 0.995715],\n",
" [0. , 0.000004, 0.999996],\n",
" [0. , 0.000345, 0.999655],\n",
" [0.033577, 0.966423, 0. ],\n",
" [0.055579, 0.94417 , 0.000251],\n",
" [0.99922 , 0.00078 , 0. ],\n",
" [0.997699, 0.002301, 0. ],\n",
" [0. , 0.014023, 0.985977],\n",
" [0. , 0.008068, 0.991932],\n",
" [0.998712, 0.000937, 0.000351],\n",
" [0.000637, 0.999363, 0. ],\n",
" [0.001321, 0.998655, 0.000024],\n",
" [0.930462, 0.069418, 0.000121],\n",
" [0.001398, 0.9986 , 0.000002],\n",
" [0.002453, 0.997528, 0.000019],\n",
" [0.05124 , 0.948155, 0.000606],\n",
" [0. , 0. , 1. ],\n",
" [0.001111, 0.998889, 0. ],\n",
" [0. , 0.000203, 0.999797],\n",
" [0.000063, 0.040843, 0.959093],\n",
" [0.930462, 0.069418, 0.000121],\n",
" [0.019763, 0.980237, 0. ],\n",
" [0.033577, 0.966423, 0. ],\n",
" [0.659404, 0.319765, 0.020831],\n",
" [0. , 0. , 1. ],\n",
" [0.999979, 0.000021, 0. ],\n",
" [0. , 0.002178, 0.997822],\n",
" [0. , 0.000085, 0.999915],\n",
" [0.974593, 0.025407, 0. ],\n",
" [0.98255 , 0.01745 , 0. ],\n",
" [0.000308, 0.999692, 0. ],\n",
" [0. , 0. , 1. ],\n",
" [0.974593, 0.025407, 0. ],\n",
" [0.947557, 0.052443, 0. ],\n",
" [0.913746, 0.086254, 0. ],\n",
" [0.015839, 0.984161, 0. ],\n",
" [0.974593, 0.025407, 0. ],\n",
" [0. , 0. , 1. ],\n",
" [0.129826, 0.870174, 0. ],\n",
" [0.000177, 0.999787, 0.000036],\n",
" [0.238042, 0.760375, 0.001583],\n",
" [0.99808 , 0.001917, 0.000003],\n",
" [0. , 0. , 1. ],\n",
" [0.001213, 0.97811 , 0.020677],\n",
" [0. , 0.008068, 0.991932],\n",
" [0.999979, 0.000021, 0. ],\n",
" [0.001398, 0.9986 , 0.000002],\n",
" [0.015839, 0.984161, 0. ],\n",
" [0. , 0.021595, 0.978405],\n",
" [0.002453, 0.997528, 0.000019],\n",
" [0. , 0.000005, 0.999995],\n",
" [0.907855, 0.092061, 0.000084],\n",
" [0.974593, 0.025407, 0. ],\n",
" [0. , 0.000032, 0.999968],\n",
" [0.91181 , 0.045917, 0.042272],\n",
" [0.000898, 0.99788 , 0.001222],\n",
" [0. , 0.002066, 0.997934],\n",
" [0.055579, 0.94417 , 0.000251],\n",
" [0. , 0.014023, 0.985977],\n",
" [0.000029, 0.006112, 0.993859],\n",
" [0. , 0.002178, 0.997822],\n",
" [0. , 0.023981, 0.976019],\n",
" [0.999889, 0.000075, 0.000035],\n",
" [0.000308, 0.999692, 0. ]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_prob = classifier.predict_proba(X_test)\n",
"y_prob"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08f121e4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2, 3, 3, 1, 3, 2, 3, 2, 3, 2, 3, 2, 2, 1, 1, 2, 3, 1, 3, 1, 3, 1,\n",
" 3, 3, 3, 2, 2, 1, 1, 2, 1, 2, 3, 1, 2, 3, 2, 3, 2, 1, 2, 2, 3, 2,\n",
" 3, 3, 1, 3, 3, 2, 2, 2, 2, 3, 2, 3, 3, 3, 1, 3, 3, 1, 3, 1, 3, 1,\n",
" 2, 3, 3, 2, 1, 1, 1, 2, 2, 2, 2, 2, 3, 1, 3, 1, 3, 2, 3, 3, 3, 2,\n",
" 1, 3, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 3, 2, 1, 3, 1, 1, 1, 2, 3, 3,\n",
" 1, 3, 2, 1, 1, 3, 2, 2, 1, 1, 3, 3, 3, 2, 1, 3, 3, 1, 1, 2, 2, 3,\n",
" 1, 3, 1, 1, 1, 3, 1, 3, 2, 1, 2, 2, 1, 1, 2, 3, 1, 1, 3, 1, 2, 2,\n",
" 2, 3, 1, 3, 3, 1, 1, 2, 1, 2, 1, 3, 2, 1, 2, 1, 3, 2, 3, 1, 3, 1,\n",
" 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 3, 3, 3, 2, 2, 1, 1, 3, 3, 1, 2, 2,\n",
" 1, 2, 2, 2, 3, 2, 3, 3, 1, 2, 2, 1, 3, 1, 3, 3, 1, 1, 2, 3, 1, 1,\n",
" 1, 2, 1, 3, 2, 2, 2, 1, 3, 2, 3, 1, 2, 2, 3, 2, 3, 1, 1, 3, 1, 2,\n",
" 3, 2, 3, 3, 3, 3, 1, 2], dtype=int64)"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_pred = classifier.predict(X_test)\n",
"y_pred"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c876fff8",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import confusion_matrix\n",
"from sklearn.metrics import accuracy_score\n",
"from mlxtend.plotting import plot_confusion_matrix\n",
"import seaborn as sns\n",
"sns.set()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cbb6c719",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy : 0.992\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAa8AAAG1CAYAAABOJnv8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAqHElEQVR4nO3deVhV5cL+8XuDIioiSppKxwlFw7HCKWdMLctKyobjUMchG17LMRUTM83sKFBa/MwsO2nmlEPZUVNP5oRmWh5zaACHUtE0EDQFda/fH77utx2obN2weOD7uS6uy/2stRc3rOLea+1nre2wLMsSAAAG8bE7AAAAnqK8AADGobwAAMahvAAAxqG8AADGobwAAMahvAAAxqG8AADGobwAAMYpZncAbzt/walfT5y2OwbyQbWbA+2OAMDLHJIcjmuvV+jK69cTpxX+7EK7YyAfpC7oa3cEAF7m53upwK6F04YAAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgAA41BeAADjUF4AAONQXgZoXa+Szi7ue8Wv6EdukyRVKV9Kswa11a//6qFjc3rp87F3q1GNYJvTw1u+WLVSLZtFqHxgKYWFVtPk11+TZVl2x0IeYF9fWzG7A+Davks+qbYjP802PvbxO3RHrQpasCFJAf7FtXrCvcq64NTA6Zt0LuuiRnVvrOVj71aTwYuVknrWhuTwlsTNm/Vwt/v1cPdHNfaVCdq8aaPGjhktp9OpEaNG2x0PXsS+zh2HZXOdO51OvfXWW1q4cKHS09N1xx13aOzYsapWrdp1bW9/SrrCn13o5ZQFz31NqmrhqI76++S1WpJ4QKO6N9YL9zdQ4+cXu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s4JAICLx0de//73vzVixAg1b95c8fHxsixLktSpUyetX79eCQkJXg8JAMCfeXzkNX36dD322GN6+eWXdfHiRdd4VFSUTp48qQULFmjQoEHezAgAgBuPj7z279+vjh075risUaNGOnbs2A2HAgDgajwur+DgYCUlJeW4LCkpScHBwTccCgCAq/G4vLp06aKpU6dq5cqVysrKknTp2q7vv/9eCQkJuvvuu70eEgCAP3NYl2dc5FJWVpaeffZZbdy4UT4+PnI6nSpdurT++OMPRURE6N1335W/v39e5b0mp2XpjyyPfiQYqkLz5+2OgHyUuu0tuyMgH/j5Sj65uNeFxxM2/Pz8NHPmTG3atEmJiYk6deqUypQpo6ZNm6pt27bcYQMAkOeu6zovSWrZsqVuv/12ZWRkKCgoiGu7AAD55rrKa/PmzZo2bZp27twpy7Lk6+urxo0ba9CgQYqIiPB2RgAA3FzXRcp9+vRRZmam/ud//kcvv/yynn76aaWlpenJJ5/Uli1b8iInAAAuHk/Y6Nq1q8LCwhQbG+s2blmWnn32WR0/flyffPKJV0N6ggkbRQcTNooWJmwUDbmdsOHxkdfBgwfVrVu3bOMOh0N///vf9dNPP3m6SQAAPOJxeYWGhmrPnj05Ljt69KiqVq16w6EAALiaXE3YOHLkiOvfffr0UUxMjHx8fHTPPfeoQoUKOnXqlDZs2KBp06bp1VdfzbOwAABIuXzPq27dum7Xb11
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cm = confusion_matrix(y_test, y_pred)\n",
"plot_confusion_matrix(cm)\n",
"\n",
"acc = accuracy_score(y_test, y_pred)\n",
"print('Accuracy',':', acc)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e3c2afe8",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"colorscale": [
[
0,
"rgb(3, 5, 18)"
],
[
0.09090909090909091,
"rgb(25, 25, 51)"
],
[
0.18181818181818182,
"rgb(44, 42, 87)"
],
[
0.2727272727272727,
"rgb(58, 60, 125)"
],
[
0.36363636363636365,
"rgb(62, 83, 160)"
],
[
0.45454545454545453,
"rgb(62, 109, 178)"
],
[
0.5454545454545454,
"rgb(72, 134, 187)"
],
[
0.6363636363636364,
"rgb(89, 159, 196)"
],
[
0.7272727272727273,
"rgb(114, 184, 205)"
],
[
0.8181818181818182,
"rgb(149, 207, 216)"
],
[
0.9090909090909091,
"rgb(192, 229, 232)"
],
[
1,
"rgb(234, 252, 253)"
]
],
"reversescale": true,
"showscale": true,
"type": "heatmap",
"x": [
"pred_1",
"pred_2",
"pred_3"
],
"y": [
"true_1",
"true_2",
"true_3"
],
"z": [
[
0,
0,
85
],
[
2,
87,
0
],
[
76,
0,
0
]
]
}
],
"layout": {
"annotations": [
{
"font": {
"color": "#000000"
},
"showarrow": false,
"text": "0",
"x": "pred_1",
"xref": "x",
"y": "true_1",
"yref": "y"
},
{
"font": {
"color": "#000000"
},
"showarrow": false,
"text": "0",
"x": "pred_2",
"xref": "x",
"y": "true_1",
"yref": "y"
},
{
"font": {
"color": "#FFFFFF"
},
"showarrow": false,
"text": "85",
"x": "pred_3",
"xref": "x",
"y": "true_1",
"yref": "y"
},
{
"font": {
"color": "#000000"
},
"showarrow": false,
"text": "2",
"x": "pred_1",
"xref": "x",
"y": "true_2",
"yref": "y"
},
{
"font": {
"color": "#FFFFFF"
},
"showarrow": false,
"text": "87",
"x": "pred_2",
"xref": "x",
"y": "true_2",
"yref": "y"
},
{
"font": {
"color": "#000000"
},
"showarrow": false,
"text": "0",
"x": "pred_3",
"xref": "x",
"y": "true_2",
"yref": "y"
},
{
"font": {
"color": "#FFFFFF"
},
"showarrow": false,
"text": "76",
"x": "pred_1",
"xref": "x",
"y": "true_3",
"yref": "y"
},
{
"font": {
"color": "#000000"
},
"showarrow": false,
"text": "0",
"x": "pred_2",
"xref": "x",
"y": "true_3",
"yref": "y"
},
{
"font": {
"color": "#000000"
},
"showarrow": false,
"text": "0",
"x": "pred_3",
"xref": "x",
"y": "true_3",
"yref": "y"
}
],
"font": {
"size": 14
},
"height": 400,
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"fillpattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"title": {
"text": "Confusion Matrix - Accuracy: 0.9920"
},
"width": 400,
"xaxis": {
"dtick": 1,
"gridcolor": "rgb(0, 0, 0)",
"side": "top",
"ticks": ""
},
"yaxis": {
"dtick": 1,
"ticks": "",
"ticksuffix": " "
}
}
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def plot_confusion_matrix(cm):\n",
" cm = cm[::-1]\n",
" cm = pd.DataFrame(cm, columns=['pred_1', 'pred_2', 'pred_3'], index=['true_1', 'true_2', 'true_3'])\n",
" fig = ff.create_annotated_heatmap(z = cm.values, x = list(cm.columns), y = list(cm.index), colorscale = 'ice', showscale = True, reversescale = True)\n",
" fig.update_layout(width=400, height=400, title='Confusion Matrix - Accuracy: {:.4f}'.format(acc), font_size=14)\n",
" fig.show()\n",
"plot_confusion_matrix(cm)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a1ffeb65",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" pred_1 0.97 1.00 0.99 76\n",
" pred_2 1.00 0.98 0.99 89\n",
" pred_3 1.00 1.00 1.00 85\n",
"\n",
" accuracy 0.99 250\n",
" macro avg 0.99 0.99 0.99 250\n",
"weighted avg 0.99 0.99 0.99 250\n",
"\n"
]
}
],
"source": [
"from sklearn.metrics import classification_report\n",
"print(classification_report(y_test, y_pred, target_names=['pred_1', 'pred_2', 'pred_3']))"
]
}
],
"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.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}