pst/ukol.ipynb

805 lines
472 KiB
Plaintext
Raw Normal View History

2024-10-18 18:42:33 +02:00
{
"cells": [
2024-10-19 13:46:09 +02:00
{
"cell_type": "markdown",
"id": "c88902ee",
"metadata": {},
"source": [
"# Úkol: BI-PST\n"
]
},
{
"cell_type": "markdown",
"id": "91241ee8",
"metadata": {},
"source": [
"Spolupracovali:\n",
" * Ondřej Hladůvka (reprezentant)\n",
" * Tomáš Kaňka"
]
},
2024-10-18 18:42:33 +02:00
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 31,
2024-10-19 13:46:09 +02:00
"id": "334be38a",
2024-10-18 18:42:33 +02:00
"metadata": {},
"outputs": [],
2024-10-18 21:02:29 +02:00
"source": [
"#import csv\n",
"#import math\n",
2024-10-19 20:36:56 +02:00
"import numpy as np\n",
2024-10-19 13:46:09 +02:00
"import matplotlib.pyplot as plt\n",
2024-10-18 21:02:29 +02:00
"import pandas as pd\n",
"#np.set_printoptions(precision=3)\n",
"#from sympy import *\n",
2024-10-20 14:10:02 +02:00
"from scipy import stats \n",
2024-10-19 20:36:56 +02:00
"from scipy.stats import norm, uniform, expon\n",
2024-10-18 21:02:29 +02:00
"#from scipy.optimize import minimize"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 2,
2024-10-18 21:02:29 +02:00
"id": "7c90184c-5f76-4277-b0ad-aeec2ac37d30",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"M = 10\n",
"dataset ex0221\n"
]
}
],
2024-10-18 21:02:29 +02:00
"source": [
"K = 28\n",
"L = 8\n",
"M = (((K + L) * 47) % 11) + 1\n",
2024-10-20 14:10:02 +02:00
"print(\"M =\",M)\n",
"print(\"dataset ex0221\")"
2024-10-18 21:02:29 +02:00
]
},
2024-10-19 13:46:09 +02:00
{
"cell_type": "markdown",
"id": "129f8693",
"metadata": {},
"source": [
"## Úloha č. 1"
]
},
2024-10-18 21:02:29 +02:00
{
"cell_type": "markdown",
"id": "503f77b6-1c9d-4406-8b30-ec3b792267e7",
"metadata": {},
"source": [
"(1b) Načtěte datový soubor a rozdělte sledovanou proměnnou na příslušné dvě pozorované skupiny.\n",
"Stručně popište data a zkoumaný problém. Pro každou skupinu zvlášť odhadněte střední hodnotu, rozptyl a medián příslušného rozdělení."
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 4,
2024-10-18 21:02:29 +02:00
"id": "b80d5cec-db0c-42e7-a3b9-296803242269",
2024-10-19 20:36:56 +02:00
"metadata": {
"scrolled": true
},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prvních 5 řádků:\n",
" Weight Status\n",
"0 24.500000 survived\n",
"1 26.900000 survived\n",
"2 26.900000 survived\n",
"3 24.299999 survived\n",
"4 24.100000 survived\n",
"Info\n",
"Počet řádků: 59\n",
"Datové typy:\n",
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 59 entries, 0 to 58\n",
"Data columns (total 2 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Weight 59 non-null float64\n",
" 1 Status 59 non-null object \n",
"dtypes: float64(1), object(1)\n",
"memory usage: 1.0+ KB\n"
]
},
{
"data": {
"text/plain": [
"None"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2024-10-18 21:02:29 +02:00
"source": [
2024-10-19 13:46:09 +02:00
"# načtení dat\n",
"df = pd.read_csv(\"/data.csv\")\n",
"df = df.drop(df.columns[0], axis=1)\n",
2024-10-19 20:36:56 +02:00
"survived = df[df['Status'] == 'survived']['Weight'].values\n",
"perished = df[df['Status'] == 'perished']['Weight'].values\n",
2024-10-19 13:46:09 +02:00
"# informace\n",
"print(\"Prvních 5 řádků:\")\n",
"print(df.head())\n",
"print(\"Info\")\n",
"print(\"Počet řádků:\", df.shape[0])\n",
2024-10-19 20:36:56 +02:00
"print(\"Datové typy:\")\n",
"display(df.info())\n"
2024-10-19 13:46:09 +02:00
]
},
{
"cell_type": "markdown",
"id": "41e43831",
"metadata": {},
"source": [
"Tento datový soubor zkoumá, zda hmotnost dospělých samců vrabců hraje roli v jejich přežití během extrémních klimatických podmínek. Cílem je zjistit, zda vrabci, kteří přežili, měli významně jinou průměrnou hmotnost ve srovnání se vrabci, kteří zahynuli. \n",
"\n",
"Tabulak má dva sloupce weight a status, kde\n",
"**weight** udává hmotnost dospělých samců vrabců v gramech a\n",
"**status** udává, zda vrabec přežil nebo zahynul během zimní bouře. Může mít hodnoty \"survived\" (přežil) nebo \"perished\" (zahynul).\n"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 5,
2024-10-19 13:46:09 +02:00
"id": "717d3775",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['Weight', 'Status'], dtype='object')\n",
" Status mean var median\n",
"0 perished 26.275000 2.168043 26.000000\n",
"1 survived 25.462857 1.584756 25.700001\n"
]
}
],
2024-10-19 13:46:09 +02:00
"source": [
"# Zobrazení názvů sloupců\n",
"print(df.columns)\n",
"\n",
"groups = df.groupby('Status')\n",
"summary_stats = groups['Weight'].agg(['mean', 'var', 'median']).reset_index()\n",
"\n",
"# Zobrazení výsledků\n",
"print(summary_stats)"
]
},
{
"cell_type": "markdown",
"id": "b370bf22",
"metadata": {},
"source": [
"## Úloha č. 2"
2024-10-18 21:02:29 +02:00
]
},
{
"cell_type": "markdown",
"id": "29eef015-c103-4e7f-89e8-2b59526f4b1e",
"metadata": {},
"source": [
"(1b) Pro každou skupinu zvlášť odhadněte hustotu a distribuční funkci pomocí histogramu a empirické distribuční funkce."
]
},
2024-10-19 13:46:09 +02:00
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 6,
2024-10-19 13:46:09 +02:00
"id": "9c8f12d3",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"data": {
"image/png": "iVB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PT5UqVdLXX3+dKEvevHklSaNGjbLvIyHD/v371bVrVxUrVkx+fn4KCQlR9+7ddeXKlVSfZ2xsrIYPH65q1aopR44cCggIUL169bRu3bpUt71165bGjh2r0qVL6+OPP05UNCV48cUXVaNGjVT3ValSJU2aNEnXrl3TlClTUl3fEQmHX+7atUt16tRRtmzZVLRoUc2YMSPRegmHEM6fP1/vvPOOChUqJH9/f0VEREiSFi1apGrVqilbtmzKkyePXnjhBZ05cybVx4+Li9OoUaNUokQJ+fn5KXfu3Hr88ccVHh5+3+327t2rvHnzqmHDhrp586ZGjhyZ7GubcBjjiRMn7G1hYWF66qmntGrVKlWuXFl+fn4qW7aslixZkuxzvvvQz4TX648//tATTzwhf39/FSpUSOPGjUv1cVPaZ1RUlA4dOqTLly/f/8WS4/0lSTExMRoxYoSKFy8uX19fhYaG6o033lBMTEyi9SwWi/r27au5c+eqXLly8vX11cqVK+3L0vI5vltqr1FaMsbExGjgwIHKmzevsmfPrjZt2ujvv/9O9fUC4J4YcQLgNq5fv57sl7i4uDin99mrVy8tXrxYffv2VdmyZXXlyhVt3rxZBw8eVNWqVfX222/r+vXr+vvvvzVx4kRJsk8IcOvWLTVs2FBHjx5V3759VbRoUS1atEhdu3bVtWvX1L9/f+XNm1fTp0/Xq6++qnbt2umZZ56RJFWsWFGSFB4err/++kvdunVTSEiIfv/9d33++ef6/ffftW3btmS/dCeIiIjQzJkz1alTJ7388su6ceOGvvzySzVr1kw7duxQ5cqVU9x28+bNunr1qgYMGCBPT0+nX78E//rXv/TSSy9p1apVGjNmTKJlyfVbnjx5Ut3nP//8o5YtW6pDhw7q1KmTFi5cqFdffVU+Pj7q3r17onVHjx4tHx8fvf7664qJiZGPj49mz56tbt266bHHHtPYsWN14cIFffLJJ9qyZYv27Nmj4ODgFB975MiRGjt2rHr06KEaNWooIiJCO3fu1O7du9WkSZNkt/n111/VrFkzVa9eXd99952yZcuW6nO8159//qmOHTuqV69e6tKli7766is9++yzWrlyZYqPe/fr1bx5cz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X05ladiwoQzDcHhabUf6a9GiRSpTpoxKly6ty5cv238SJhW59zDTBg0aqGzZsqk+tqOfY0deI0czrlixQpJtwpS7OTuJDICMj0P1ALiNGjVqJDvJQM6cOR06DyM548aNU5cuXRQaGqpq1aqpZcuW6ty5s4oVK5bqtidPnlSJEiWSTEJQpkwZ+/LUXL16VaNGjdL8+fN18eLFRMuuX7+e6vZff/21xo8fr0OHDiU6ZPHeWezuFRQUJEnJFjrOunnzZrKFWEr9lpqCBQsqICAgUVvJkiUl2c4dSygwpaTPN+G1L1WqVJL9li5dWps3b77vY7/77rt6+umnVbJkSZUvX17NmzfXiy++mKRIj46OVqtWrVStWjUtXLjwgWd6K168eJLDM+9+ziEhISluW7hw4STb5syZU/v373+gTI5ypL/+/PNPHTx40H7e373u/Qyk9j5O4Ojn2JHXyNGMJ0+elIeHhx599NFEy5N7zwHIHCicAGQ6KZ0XFB8fn6StQ4cOqlevnpYuXapVq1bpo48+0ocffqglS5Y4dV5IWnXo0EG//PKLBg8erMqVKyswMFBWq1XNmzeX1Wq977bffPONunbtqrZt22rw4MHKly+fPD09NXbsWB07duy+25YuXVqS9Ntvv6lt27YP/Dzi4uJ05MgR06YZd+Z8ovupX7++jh07pu+++06rVq3SzJkzNXHiRM2YMUM9evSwr+fr66uWLVvqu+++08qVK/X
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- Výsledky pro skupinu: perished ---\n",
" Weight CDF\n",
"0 24.600000 0.041667\n",
"1 24.600000 0.083333\n",
"2 24.900000 0.125000\n",
"3 25.000000 0.166667\n",
"4 25.000000 0.208333\n",
"5 25.100000 0.250000\n",
"6 25.500000 0.291667\n",
"7 25.600000 0.333333\n",
"8 25.600000 0.375000\n",
"9 25.799999 0.416667\n",
"10 25.900000 0.458333\n",
"11 26.000000 0.500000\n",
"12 26.000000 0.541667\n",
"13 26.000000 0.583333\n",
"14 26.000000 0.625000\n",
"15 26.100000 0.666667\n",
"16 26.500000 0.708333\n",
"17 26.500000 0.750000\n",
"18 27.100000 0.791667\n",
"19 27.500000 0.833333\n",
"20 27.600000 0.875000\n",
"21 28.299999 0.916667\n",
"22 28.299999 0.958333\n",
"23 31.100000 1.000000\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA04AAAIjCAYAAAA0vUuxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACLE0lEQVR4nOzdeZxN9R/H8fed3TbGPkZjkDXMEBGyZd+JCFlLKbtfKmWXaCE7RUjITsq+RhElS7JnbBl7DMbs5/fHbS7XzJiZ6457Z7yej8c83PM92+fe+53rfub7PZ9jMgzDEAAAAAAgUS6ODgAAAAAAnB2JEwAAAAAkgcQJAAAAAJJA4gQAAAAASSBxAgAAAIAkkDgBAAAAQBJInAAAAAAgCSROAAAAAJAEEicAAAAASAKJEwAANujcubMyZ8782M+7bds2mUwmbdu27bGfO63o3LmzChQo4JBzm0wmDRs2zCHnBpC6SJwAOL05c+bIZDLp999/T3B9jRo1VKpUqVQ7/4IFCzR+/Hib9w8LC9OwYcOc9ovuihUr1KBBA+XMmVMeHh7y8/NT69attWXLFss2cV/W4348PT2VJ08e1ahRQx9//LGuXLkS77hx71tCP++///7jfIoAADwyN0cHAADObsGCBTp06JD69u1r0/5hYWEaPny4JHOS5ywMw1DXrl01Z84clS1bVv3795evr69CQkK0YsUK1apVS7/88osqV65s2ad379567rnnFBMToytXrmjnzp0aOnSoxo0bp8WLF+vFF1+Md54RI0aoYMGCVm2pmeimd9WqVdPdu3fl4eHh6FCc1owZMxQbG+voMACkMyROAPCEGjt2rObMmaO+fftq3LhxMplMlnUffvihvv32W7m5Wf83UbVqVbVq1cqq7cCBA6pbt65atmypw4cPK2/evFbrGzRooPLly6fe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9aska+vr9q2bWtpc3d3V+/evXX79m399NNPSR4jQ4YMlsfh4eG6evWqnn/+eUl66OiGJLm6uloKBMTGxur69euKjo5W+fLlk9w3bipblixZkowxuTJnzqxbt27Fa0/ofUsONzc3vfnmm5ZlDw8Pvfnmm7p8+bL27t1rtW2nTp2sXsvff/9dly9f1ttvv211PVCjRo1UvHhxrV69+qHn9vHx0V9//aUTJ04kGefWrVtVr1491apVS8uXL5enp2eynl9C/Pz81KJFC8uyt7e3OnbsqH379unixYsP3Tdz5sx69dVXLcseHh6qUKGCTp06ZVMsNWrUkGEYSZbWzpo1qyRp/fr1CgsLs+lcCenevXu8tjZt2mjv3r36+++/LW2LFi2Sp6enmjVrluixXnzxReXMmVOLFi2ytP3777/auHGj1UjSkiVLVKJECRUvXtxqhDSu6EncNNg1a9ZIMhdLuZ+tBWQApA0kTgDSjAoVKqh27drxfhKanpNcn376qQ4dOiR/f39VqFBBw4YNS/YXzTNnzqhIkSLxihCUKFHCsj4p169fV58+fZQnTx5lyJBBuXLlslSgi7s+5GG++eYbBQYGWq7DyZUrl1avXp3kvt7e3pKUYKJjq9u3byeYiCX0viWHn59fvIIARYsWlaR41+g8WLUv7rUvVqxYvOMWL148yfdmxIgRunHjhooWLarSpUtrwIABOnjwYLztwsPD1ahRI5UtW1aLFy9+5Ep3hQsXjndNVGLP+UFPPfVUvH2zZctmue4ntRQsWFD9+/fXzJkzlTNnTtWrV09TpkxJVv9N6rgPevnll+Xi4mJJgAzD0JIlS9SgQQNLn06Im5ubWrZsqe+//95yrdLy5csVFRVllTidOHFCf/31l3LlymX1E/ceXL58WZK
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- Výsledky pro skupinu: survived ---\n",
" Weight CDF\n",
"0 23.200001 0.028571\n",
"1 23.600000 0.057143\n",
"2 23.700001 0.085714\n",
"3 23.799999 0.114286\n",
"4 23.900000 0.142857\n",
"5 24.100000 0.171429\n",
"6 24.200001 0.200000\n",
"7 24.299999 0.228571\n",
"8 24.299999 0.257143\n",
"9 24.500000 0.285714\n",
"10 24.600000 0.314286\n",
"11 24.700001 0.342857\n",
"12 24.700001 0.371429\n",
"13 24.799999 0.400000\n",
"14 24.900000 0.428571\n",
"15 25.400000 0.457143\n",
"16 25.600000 0.485714\n",
"17 25.700001 0.514286\n",
"18 25.700001 0.542857\n",
"19 25.700001 0.571429\n",
"20 25.700001 0.600000\n",
"21 25.900000 0.628571\n",
"22 26.200001 0.657143\n",
"23 26.200001 0.685714\n",
"24 26.299999 0.714286\n",
"25 26.299999 0.742857\n",
"26 26.500000 0.771429\n",
"27 26.600000 0.800000\n",
"28 26.700001 0.828571\n",
"29 26.700001 0.857143\n",
"30 26.900000 0.885714\n",
"31 26.900000 0.914286\n",
"32 27.000000 0.942857\n",
"33 27.900000 0.971429\n",
"34 28.000000 1.000000\n"
]
}
],
2024-10-19 13:46:09 +02:00
"source": [
"def calculate_density_cdf(group):\n",
" sorted_weights = group.sort_values('Weight')\n",
" cdf = pd.Series(range(1, len(sorted_weights) + 1)) / len(sorted_weights)\n",
" results = pd.DataFrame({'Weight': sorted_weights['Weight'].values, 'CDF': cdf.values})\n",
" \n",
" return results\n",
"\n",
"groups = df.groupby('Status')\n",
"density_cdf_results = {}\n",
"\n",
"for name, group in groups:\n",
" density_cdf_results[name] = calculate_density_cdf(group)\n",
"\n",
"for name, results in density_cdf_results.items():\n",
" plt.figure(figsize=(10, 6))\n",
" plt.hist(df[df['Status'] == name]['Weight'], bins=20, density=True, alpha=0.5, label=f'Hustota {name}')\n",
" \n",
" # CDF\n",
" plt.plot(results['Weight'], results['CDF'], label=f'CDF {name}', color='red')\n",
" \n",
" # Nastavení g\n",
" plt.title(f'Hustota a CDF pro skupinu: {name}')\n",
" plt.xlabel('Hmotnost')\n",
" plt.ylabel('Hustota / Kumulativní pravděpodobnost (CDF)')\n",
" plt.legend()\n",
" plt.grid()\n",
" plt.show()\n",
" print(f\"\\n--- Výsledky pro skupinu: {name} ---\")\n",
" print(results)\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "f98f6ad6",
"metadata": {},
"source": [
"Vytvořili jsme funkci calculate_density_cdf, která seřadila data podle hmotnosti a spočítala kumulativní distribuční funkci. Tato funkce vrátila DataFrame se seřazenými hmotnostmi a odpovídajícími hodnotami CDF."
]
},
{
"cell_type": "markdown",
"id": "9f9b7946",
"metadata": {},
"source": [
"## Úloha č. 3"
]
},
2024-10-18 21:02:29 +02:00
{
"cell_type": "markdown",
"id": "626d8bce-65af-4659-96e9-c1fbe4ccb3cc",
"metadata": {},
"source": [
"(3b) Pro každou skupinu zvlášť najděte nejbližší rozdělení: \n",
"Odhadněte parametry normálního, exponenciálního a rovnoměrného rozdělení.\n",
"Zaneste příslušné hustoty s odhadnutými parametry do grafů histogramu. Diskutujte, které z rozdělení odpovídá pozorovaným datům nejlépe."
]
},
2024-10-20 14:10:02 +02:00
{
"cell_type": "markdown",
"id": "542a742d-2c96-4d06-bf05-49823752ed6d",
"metadata": {},
"source": [
"Odhady získáme pomocí momentové metody"
]
},
2024-10-19 20:36:56 +02:00
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 7,
2024-10-20 14:10:02 +02:00
"id": "b1995dc6-a79c-4859-a720-5dca78d63e44",
2024-10-19 20:36:56 +02:00
"metadata": {},
"outputs": [],
"source": [
"def show_distribution(data):\n",
" fig = plt.figure(figsize = (10, 14))\n",
" gs = fig.add_gridspec(4,2, figure = fig)\n",
" sp1 = fig.add_subplot(gs[0, 0])\n",
" sp2 = fig.add_subplot(gs[0, 1])\n",
" sp3 = fig.add_subplot(gs[1, 0])\n",
" sp4 = fig.add_subplot(gs[1, 1])\n",
" sp5 = fig.add_subplot(gs[ 2:, 0:])\n",
" \n",
" sp1.set_title('Data Histogram')\n",
" sp1.hist(data, bins=10, density=True, alpha=0.5)\n",
" sp2.hist(data, bins=10, density=True, alpha=0.5)\n",
" sp3.hist(data, bins=10, density=True, alpha=0.5)\n",
" sp4.hist(data, bins=10, density=True, alpha=0.5)\n",
" sp5.hist(data, bins=10, density=True, alpha=0.5)\n",
" \n",
2024-10-20 14:10:02 +02:00
" mu, std = norm.fit(data)\n",
" xmin, xmax = sp1.get_xlim()\n",
2024-10-19 20:36:56 +02:00
" x = np.linspace(xmin, xmax, 100)\n",
2024-10-20 14:10:02 +02:00
" p_norm = norm.pdf(x, mu, std)\n",
2024-10-19 20:36:56 +02:00
" sp2.plot(x, p_norm, 'red')\n",
" sp2.fill_between(x, p_norm, alpha=0.2, color='red')\n",
" sp2.set_title(f'Normal fit ($\\mu={mu:.2f}, \\sigma={std:.2f}$)')\n",
"\n",
" loc, scale = expon.fit(data)\n",
" p_exp = expon.pdf(x, loc, scale)\n",
" split0 = next((i for i, x in enumerate(p_exp) if x != 0), len(p_exp))\n",
" sp3.plot(x[split0:], p_exp[split0:], 'green')\n",
" sp3.fill_between(x[split0:], p_exp[split0:], alpha=0.2, color='green')\n",
" sp3.set_title(f'Exponential Distribution Fit (scale={scale:.2f})')\n",
"\n",
" loc_uni, scale_uni = uniform.fit(data)\n",
" p_uni = uniform.pdf(x, loc_uni, scale_uni)\n",
" split1 = next((i for i, x in enumerate(p_uni) if x != 0), len(p_uni))\n",
" split2 = -next((i for i, x in enumerate(reversed(p_uni)) if x != 0), len(p_uni))\n",
" sp4.plot(x[split1:split2], p_uni[split1:split2], 'purple')\n",
" sp4.plot(x[:split1], p_uni[:split1], 'purple')\n",
" sp4.plot(x[split2:], p_uni[split2:], 'purple')\n",
" sp4.fill_between(x[split1:split2], p_uni[split1:split2], alpha=0.1, color='purple')\n",
" sp4.set_title(f'Uniform Distribution Fit (range=({loc_uni:.2f}, {loc_uni+scale_uni:.2f}))')\n",
" \n",
" sp5.plot(x, p_norm, 'red', label=f'Normal fit: $\\mu={mu:.2f}, \\sigma={std:.2f}$')\n",
" sp5.plot(x[split0:], p_exp[split0:], 'green', label=f'Exponential fit: scale={scale:.2f}')\n",
" sp5.plot(x[split1:split2], p_uni[split1:split2], 'purple')\n",
" sp5.plot(x[:split1], p_uni[:split1], 'purple')\n",
" sp5.plot(x[split2:], p_uni[split2:], 'purple', label=f'Uniform fit: range=({loc_uni:.2f}, {loc_uni+scale_uni:.2f})')\n",
" #sp5.plot(x, p_uni, 'blue', label=f'Uniform fit: range=({loc_uni:.2f}, {loc_uni+scale_uni:.2f})')\n",
" sp5.set_title('Combined Distributions')\n",
" sp5.legend()"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 8,
2024-10-19 20:36:56 +02:00
"id": "2121c37e-edac-446d-8ed5-1f1fab942637",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAR6CAYAAACnV42WAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd1hUR9sG8HvpTUBEmiAgFqwQsWHDgqDBHnuF1xaNLRg1do3GXoi9RWNNjMaWxGDBlij2HnuvYKdLne+P/diw7IIsAgfY+3ddeylnT3nO7DLDc87MHJkQQoCIiIiIiIg+iY7UARARERERERUHTK6IiIiIiIjyAJMrIiIiIiKiPMDkioiIiIiIKA8wuSIiIiIiIsoDTK6IiIiIiIjyAJMrIiIiIiKiPMDkioiIiIiIKA8wuSIiIiIiIsoDTK6IiIiIiIjyAJMrIiIiIiKiPMDkiqgAyWQyTJ06VeowiIjo//3000+QyWR4+PDhR9c9e/Ys6tevD1NTU8hkMly6dEmj7T9m7ty5cHd3R1pa2ifviyinVq5cibJlyyIxMVHqUIoFJldUKKQ3TukvIyMjODg4wN/fH4sXL0ZMTEyu933y5ElMnToV79+/z7uAAUydOhUymQyvX79W+76Liwtat279ycfZunUrQkJCPnk/RES5lV5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gghBg4cKIyNjXMdB8nxzhUVGWZmZkqzBmYce/XhwwfExsaiXr16AOQzCTVq1Oij+8y4j6ioKCQnJ8PHxwf79+9HVFQULCwsPrqP3377Debm5irL1XXjyMz
"text/plain": [
"<Figure size 1000x1400 with 5 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA04AAAR6CAYAAAB87Ce0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd1hT1/8H8HeYYcgSAREEcSsqiqNY9957b+qqow6qVdS62rqrWK0Lq7Zqq19XtbV1a62Ke0/cG3CyZeX8/sgvqSEBEgQukffrefIoJ3d87g3ck889554jE0IIEBERERERUYZMpA6AiIiIiIgov2PiRERERERElAUmTkRERERERFlg4kRERERERJQFJk5ERERERERZYOJERERERESUBSZOREREREREWWDiRERERERElAUmTkRERERERFlg4kRERERERJQFJk5ERERERERZYOJElENkMhmmT58udRhERPSedevWQSaT4cGDB1kue+bMGdSuXRs2NjaQyWS4ePGiQetnZd68eShXrhwUCsUHb4tIXytWrEDx4sWRlJQkdShGj4kT5TpVpaN6yeVyuLu7o3nz5vjhhx8QGxub7W2fOHEC06dPx9u3b3MuYADTp0+HTCbDy5cvdb7v7e2NNm3afPB+fv31V4SEhHzwdoiIPoTqOi2Xy/H06VOt9xs0aABfX18JIss7KSkp6Nq1K16/fo1FixZh/fr18PLy0rlsduqemJgYzJ07FxMmTICJifRfv86cOYORI0eiYsWKsLGxQfHixdGtWzeEh4dnuM758+fRrl07ODk5wdraGr6+vvjhhx9ybD+3b99Gjx494OHhAWtra5QrVw4zZ85EQkLCBx9vXomLi8O0adPQokULODk5QSaTYd26ddne3nfffQeZTKbX319Gyw4YMADJyclYuXJltuMgJen/cqnAmDlzJtavX4/ly5fji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eHg4bGxv07dsXixYtMrgVTdd+GjRogLlz52LgwIGYMWMGChcujBMnTmD58uUYNWqUwa2UY8eORUhICJo1a4bAwEB1XZuSkoI2bdrA399fa53cOq+GSktLwxdffIFBgwahUqVKObZstWrVcPz48ZwMteARRLls7dq1AoA4c+ZMhsvY29uLqlWrqn9OSEjQWua3334TAMTRo0fVZfPnzxcAxP3797WW17WN5s2bCx8fnyxjnjZtmgCQ6at169Ya6wAQ06ZN0zimESNGZLqf1q1bCy8vL63ykJAQAUBs2LBBXZacnCwCAgKEra2tiImJEUIIsW3bNgFAhISEqJdLS0sTjRo1EgDE2rVr1eX9+/cXAMTEiRO19qfrXM2ePVvIZDLx8OFDrW3MmjVLXfbmzRthZWUlZDKZ2LRpk7r85s2bWueEiPKn96/Td+/eFWZmZmLUqFHq9+vXry8qVqyo/rlDhw7CwsJC3L17V1327NkzUahQIVGvXj11mepa2rNnT619qt4bMmSIuiw1NVV4eHgImUwm5syZoy5XXWf69++vLtN13QoLCxMAxC+//KJ1bLrqifcdPnxYABBbtmzReW7eXz+zukeXKVOmCAAiNjZWZ7x79+7VKH/8+LEAIFatWpVprPq89I1RCCHWr18vAIiffvpJo7xy5crC2tpaWFtbiy+++EJs27ZNfPHFFwKA6NGjh97bz2o/33zzjbCystKIf/LkyQZv/+jRowKAGDZsmEb5jBkzBABx+vRpnevl9Hk9c+aMVl2sj6VLlwp7e3sRFRUlhND++8vuskOGDBFWVlYGxUKa2OJE+YKtra3G6HrvP+v07t07xMXF4ZNPPgGgHNWnbt26WW7z/W1ER0cjJSUF9evXx969exEdHQ17e/sst7Ft2zbY2dlplevqVpG
"text/plain": [
"<Figure size 1000x1400 with 5 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2024-10-19 20:36:56 +02:00
"source": [
2024-10-19 21:05:37 +02:00
"show_distribution(survived)\n",
2024-10-19 20:36:56 +02:00
"show_distribution(perished)"
]
},
2024-10-19 13:46:09 +02:00
{
"cell_type": "markdown",
"id": "424b6dc3",
"metadata": {},
"source": [
"## Úloha č. 4"
]
},
2024-10-18 21:02:29 +02:00
{
"cell_type": "markdown",
"id": "6226456c-fdf3-4537-830c-05f8ee7022c5",
"metadata": {},
"source": [
"(1b) Pro každou skupinu zvlášť vygenerujte náhodný výběr o 100 hodnotách z rozdělení, \n",
"které jste zvolili jako nejbližší, s parametry odhadnutými v předchozím bodě.\n",
"Porovnejte histogram simulovaných hodnot s pozorovanými daty."
]
},
2024-10-19 21:05:37 +02:00
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 9,
2024-10-19 21:05:37 +02:00
"id": "85df4788-b10c-48cd-aa08-10398d9c124a",
"metadata": {},
"outputs": [],
"source": [
"def showRandomData(mean, std, dataset, title):\n",
" data = np.random.normal(mean, std, 100)\n",
" plt.figure(figsize=(10, 6))\n",
" x = np.linspace(data.min() - 5, data.max() + 5, 100)\n",
" p_norm = norm.pdf(x, mean, std)\n",
" plt.plot(x, p_norm, 'black', linewidth = 2)\n",
" plt.hist(data, bins = 10, color = \"blue\", alpha=0.5 , density = True)\n",
" #plt.set_title(\"Náhodné hodnoty z normálního rozdělení\")\n",
" plt.hist(dataset, bins = 10, color = \"green\", alpha=0.5, density = True)\n",
" plt.show()"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 10,
2024-10-19 21:05:37 +02:00
"id": "c4466cb2-863a-4c61-8338-0f6a25014c6c",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0MAAAH5CAYAAABDDuXVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABe60lEQVR4nO3deXhU9cH+/3sme8hCQiAbCUkIJIQtQCAiKlRSQG0Ft6Jtf1hq8aktrX5Tq9JHAbV9cCulthRal6ptVaS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sb16pUmSDh1apcOH/9tl3wsA4LooQwAA03344QOqqiqRJKWmXqehQ7/Tpd/PavXRVVedn7r7s88WdOn3AwC4JsoQAMBUZWXbtHnznyRJ/v4h+sY3lspisXT59x069DsKD0+UJO3d+2+VlhZ0+fcEALgWyhAAwFTr1//evj5+/Hx7QelqPj5+uvLKB+y3OToEAN6HMgQAMM3Zs6e0bdtfJUn+/qEaNerubv3+I0Z83z42aceO5Tp5ck+3fn8AgLkoQwAA0xQUvKSGhjOSpOHD71RAQGi3fn8/vyBdcUXul7cMffZZ51zgFQDgHihDAABTGIZNGzYstt8eM+bHpuQYPfoeBQQ0X9h169ZXVFFx2JQcAIDuRxkCAJhi//4PdOrUfklSSkqOoqLSTckREBCmMWN+Ikmy2Rq1evWvTckBAOh+lCEAgClaTpwwevRsE5NIV1xxr/z8giVJmzc/p5qaY6bmAQB0jw6VocWLFyspKUmBgYHKzs7W+vX
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA0MAAAH5CAYAAABDDuXVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABe/ElEQVR4nO3deVxU96H+8WfYQQEXlE2URRE3wLigcW1CRE2rxiyatDExaXprapteu8XeRm3TXrPY3DStib+mMTG7SZrVGGNKxGjEXdyiCCriBioqCMg65/cHcYQIyiBwhpnP+/U6L2eGM2ee8WQyPpzv+R6LYRiGAAAAAMDFuJkdAAAAAADMQBkCAAAA4JIoQwAAAABcEmUIAAAAgEuiDAEAAABwSZQhAAAAAC6JMgQAAADAJXmYHaA5WK1WnThxQv7+/rJYLGbHAQAAAGASwzB04cIFhYWFyc3t6sd+nKIMnThxQhEREWbHAAAAAOAgjh49qm7dul11HacoQ/7+/pJq3nBAQID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ADgkihDAAAAAFwSZQgAAACAS6IMAQAAAHBJlCEAAAAALokyBAAAAMAlUYYAAAAAuCTKEAAAAACXRBkCAAAA4JIoQwAAAABckofZAQAAaKzqykoV5+Wp+MQJXTh5UhdOnFBlaak69+qliJEj5de5s9kRAQBtCGUIAODQzh85ovyMDF04eVIlp05JhnHFOnkZGcrbuVNd+/dXv8hR6hLZxYSkAIC2hjIEAHBYxzdvVvZnnzX4c4ubmyzu7rJWVkqGoVO7d+v5B3arz6g+Gn3vaIX
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2024-10-19 21:05:37 +02:00
"source": [
"mean_survived, std_survived = norm.fit(survived)\n",
"showRandomData(mean_survived, std_survived, survived, \"survived\")\n",
"mean_perished, std_perished = norm.fit(perished)\n",
"showRandomData(mean_perished, std_perished, survived, \"perished\")"
]
},
2024-10-20 22:34:55 +02:00
{
"cell_type": "markdown",
"id": "1e1d73c6",
"metadata": {},
"source": []
},
2024-10-19 13:46:09 +02:00
{
"cell_type": "markdown",
"id": "d43bff73",
"metadata": {},
"source": [
"## Úloha č. 5"
]
},
2024-10-18 21:02:29 +02:00
{
"cell_type": "markdown",
"id": "1c5f7d31-ca21-42b4-9a23-1111bbf599b9",
"metadata": {},
"source": [
"(1b) Pro každou skupinu zvlášť spočítejte oboustranný 95% konfidenční interval pro střední hodnotu."
]
},
2024-10-20 14:10:02 +02:00
{
"cell_type": "markdown",
"id": "dec7a5cc-4c6b-4213-b3b8-8b58813f73cb",
"metadata": {},
"source": [
"Dle Studentova rozdělení:\n",
"$$\n",
"\\begin{align}\n",
"\\left( \\overset{\\_}{X_{n}} - t_{\\frac{\\alpha}{2},n-1}\\frac{s}{\\sqrt{n}}, \\overset{\\_}{X_{n}} + t_{\\frac{\\alpha}{2},n-1}\\frac{s}{\\sqrt{n}} \\right)\n",
"\\end{align}\n",
"$$"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 11,
2024-10-20 14:10:02 +02:00
"id": "69ad2d59-bdc0-4cc7-b51c-7453f2126157",
"metadata": {},
"outputs": [],
"source": [
"def conf_interval(data, name):\n",
" conf = stats.t.interval(confidence = 0.95, df = len(data) - 1, loc = np.mean(data), scale = stats.sem(data))\n",
" print(f\"Oboustranný konfidenční interval 95% střední hodnoty skupiny \\\"{name}\\\":\", conf)\n",
" return conf"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 12,
2024-10-20 14:10:02 +02:00
"id": "16ee6a87-8b6a-472c-9689-9d3877d31084",
"metadata": {},
"outputs": [],
"source": [
"def plot_conf_interval(title, list, interval):\n",
" fig, ax = plt.subplots(figsize = (6, 4))\n",
" ax.hist(list, bins = 10, color = \"blue\", alpha=0.5)\n",
" ax.set_title(f\"Oboustranný 95% interval skupiny \\\"{title}\\\"\")\n",
" ax.axvline(x = interval[0], color = \"red\")\n",
" ax.axvline(x = interval[1], color = \"red\")\n",
" plt.show()"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 13,
2024-10-20 14:10:02 +02:00
"id": "b5fd12a4-8517-4c5e-9f18-eaf627c56afa",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Oboustranný konfidenční interval 95% střední hodnoty skupiny \"survived\": (np.float64(25.030419953409798), np.float64(25.895294593883747))\n",
"Oboustranný konfidenční interval 95% střední hodnoty skupiny \"perished\": (np.float64(25.653248327602988), np.float64(26.89675170418613))\n"
]
}
],
2024-10-20 14:10:02 +02:00
"source": [
"conf_survived = conf_interval(survived, \"survived\")\n",
"conf_perished = conf_interval(perished, \"perished\")"
]
},
{
"cell_type": "code",
2024-10-20 22:34:55 +02:00
"execution_count": 14,
2024-10-20 14:10:02 +02:00
"id": "f17915e9-aef8-430d-8096-c13f078e25eb",
"metadata": {},
2024-10-20 22:34:55 +02:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUh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6Vpylf//+mj59urp06aInn3xS33//vZKSkrRt2zYtWLDA63pHjhyppKQk9e/fX/Xq1VN6erqSk5O1ceNG3XvvvRo4cKD279+vZcuW6YMPPsjxMaZOnaqzZ8/q4YcfltPpVGhoqNLT0zVp0iR1795dAwYM0IkTJzR58mS1atVK69at06233ur2GLNmzdKJEyc0cOBAORwOjR07Vvfff7927dqlokWLutpdvHhRrVq1Uv369fXqq69q+fLlGjdunCpXrqzBgwfL4XCoZ8+eGjt2rI4eParQ0FDXsp9++qnS09PVs2fPXPsj60NS8eLF3eaXKFFCkrRhw4Zsy/Tt21cnT56Un5+fmjRpoldeecXtTeeOO+7QpEmT9OWXXyomJkbjxo1TvXr1JElbt27Vu+++q3Xr1uVak7e6du2qmJgYJSUlaePGjZo0aZIiIiL08ssvS5I++OAD1+v98MMPS5IqV64sSTp48KDuvPNOV2iFh4dryZIl6tevn9LT0/XYY4+5reuFF15QsWLFNHz4cGVkZKh69eqqVKmS5syZo/j4eLe2s2fPVunSpdWqVStJf+0l+e6779StWzdVqFBBe/bs0fjx49W8eXNt3brV1eeeGjRokObNm6chQ4aoevXqOnLkiFavXq1t27bp9ttvz3GZxYsXq0uXLoqLi9OUKVPytdW4atUqzZ49W0OHDpXT6dQ777yj1q1ba926dXmevJeSkqIuXbqoX79+io+P15QpU9SnTx/FxsaqRo0aqlSpkho1aqSZM2fq8ccfd1t25syZCgoKcn2QzY/89FlermZMXC4uLk69e/fW+vXr3Q597d27V2vXrtUrr7zimjd69Gg988wz6tq1q/r3768///xTb731lpo2baoffvhBpUqVkiRNnjxZAwcOVMOGDfXYY49p165d6tChg0JDQxUVFZWv51zoGVzR8ePHjSTTsWPHK7br0KGDkWTS09ONMcY899xzRpLp0KGDW7tHHnnESDI//vijMcaYTZs2GUmmf//+bu2GDx9uJJn/+7//c82TZJ577rls665YsaKJj4933a5Tp45p27btFetNSEgwOb38u3fvNpJMcHCwOXTokNt9Fy5cMBkZGW7zjh07Zm644Qbz0EMPZXuMsLAwc/ToUdf8hQsXGknm008/dc2Lj483kszzzz/v9ri33XabiY2Ndd3+9ddfjSQzfvx4t3YdOnQw0dHRJjMzM9fnOn/+fCPJfPDBB27z3333XSPJ1KxZ0zXv22+/NZ07dzaTJ082CxcuNElJSSYsLMwEBASYjRs3uvXF/fffbyQZSSYqKsps3rzZGGNMy5YtzaBBg3Kt50ouf42zxtGl/WuMMZ06dTJhYWFu8wIDA93GQZZ+/fqZyMhIc/jwYbf53bp1MyEhIeb06dPGGGNWrFhhJJlKlSq55mVJTEw0RYsWdXs9MzIyTKlSpdxqu3w5Y4xZs2aNkWTef/9917ysda1YsSLnjviPkJAQk5CQcMU2zZo1MzVq1DDG/PVaFy1a1AwYMMBcvHjR1SY+Pt5UrFgx27JZ/XuprNc0OTnZNW/v3r0mICDAdOrUyTVv6tSpRpLZvXu3a17FihWNJPP111+75h06dMg4nU7z5JNPuuZNmDDBSDLbtm1zzTt37pwpU6ZMjq+hNzzps8vfM7I0a9bMNGvWzHX7WoyJy/spLS0tW38YY8zYsWONw+Ewe/fuNcYYs2fPHuPn52dGjx7t1u6nn34y/v7+rvnnzp0zERER5tZbb3V7f5o4caKR5PZ8/k7YLZ+HEydOSJKCgoKu2C7r/svPmE5ISHC7/eijj0r664S2S/9
"text/plain": [
"<Figure size 600x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAfcAAAF2CAYAAABzmdFaAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAzAUlEQVR4nO3dd3gU5d7/8c+SwIaEFNIgQCAEEAxNpT2oBI6FcpDOoUgJTUGDiCiPxkclUTGI9ehRmjQFBWkWFEEU4aC0gBxEEBIBjYqGloSahOT+/eHJ/tgUkg0pML5f1zUXzOw9O9+9dzKfnbZrM8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CLpRo0by8PBQQECAbr31Vn3++eeSpBEjRuiNN95wPGfuIP3/Q1YvvviiXn31VUdN+/btU2Zmpp566im1atVKvr6+8vLyUocOHbRhwwanei59jtmzZzueo02bNtqxY4dT2xEjRqhatWr69ddf1bt3b1WrVk1BQUF65JFHlJ2dLUkyxigsLEy9evWSJPXq1Ut9+/aV9Gf4+Pr6auzYsfnfuP/697//LUkaNGiQ0/RBgwbJGKOlS5cWON/p06fzHbbPdf78eVWvXt0x7u/vr3PnzjnGY2Nj1bx5c0edxZX3Pc49N5mUlKQRI0bIz89Pvr6+GjlypNPybDabzp49q4ULFzrez0vXiV9//VWjRo1SjRo1ZLfb1bRpU82bN89p2bmnJJYsWaInnnhCtWvXlqenp3bt2iWbzaaFCxfmq3ft2rWy2WxavXq1JOmnn37S/fffr8aNG6tq1aoKCAjQP/7xjxKflz59+rQmTpyosLAw2e12BQcH684779SuXbsuO9+6devk6empwYMH6+LFixoxYoTCwsLytcvt30vZbDaNHz9eixcvVuPGjeXh4aFWrVpp06ZNTu0KOuceFhamu+66S5s3b1bbtm3l4eGh8PBwvf322442hw4dks1m0yuvvJKvnm+++UY2m03vvfdeMXqnYLmv6Ycffihy2yNJixYtUqtWrVS1alX5+/tr0KBBSk5OdmqTe13Dzp07FRkZKU9PTz3++OOOx/Ke03799dfVtGlTeXp6qnr16mrdurXefffdfMtOTU297HrtSo2SHNubqlWrqm3bto6//b8q9tyL8PHHHyssLEwdOnQo8PHIyEiFhYXpk08+yffYgAEDFBYWpvj4eG3dulWvvfaa41xxrjFjxmjhwoXq37+/Hn74YW3btk3x8fHav3+/Vq1a5XK9sbGxio+P15gxY9S2bVulp6crISFBu3bt0p133qmxY8fqt99+0+eff6533nmnwOeYP3++Lly4oHvvvVd2u13+/v5KT0/XW2+9pcGDB+uee+7R6dOnNXfuXHXp0kXbt2/XDTfc4PQc7777rk6fPq2xY8fKZrNp+vTp6tu3rw4dOqTKlSs72mVnZ6tLly5q166dXnzxRa1fv14vvfSSGjR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avMcb06dPHBAQEOE3z8vJyWg9yjR492oSEhJjjx487TR80aJDx9fU1586dM8YYs2HDBiPJhIeHO6bliomJMZUrV3Z6PzMyMoyfn59TbXnnM8aYLVu2GEnm7bffdkzLXdaGDRsK7oj/8vX1NdHR0Zdt07FjR9O0aVNjzJ/vdeXKlc0999xjsrOzHW2ioqJMvXr18s2b27+Xyn1PExISHNN++ukn4+HhYfr06eOYNn/+fCPJHD582DGtXr16RpLZtGmTY1pKSoqx2+3m4YcfdkybNWuWkWT279/vmJaZmWkCAwMLfA9dUdxtz5EjR4ybm5uZOnWqU7vvvvvOuLu7O03v2LGjkWRmzpyZb3kdO3Y0HTt2dIz36tXL8X4UVWNR63Vxa8zMzDTBwcH
"text/plain": [
"<Figure size 600x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2024-10-20 14:10:02 +02:00
"source": [
"plot_conf_interval(\"survived\", survived, conf_survived)\n",
"plot_conf_interval(\"perished\", perished, conf_perished)"
]
},
2024-10-20 22:34:55 +02:00
{
"cell_type": "markdown",
"id": "743db93d",
"metadata": {},
"source": []
},
2024-10-19 13:46:09 +02:00
{
"cell_type": "markdown",
"id": "1c7cf77b",
"metadata": {},
"source": [
"## Úloha č. 6"
]
},
2024-10-18 21:02:29 +02:00
{
"cell_type": "markdown",
"id": "53a61e4f-fc67-4237-ab38-f5f9fb7767c5",
"metadata": {},
"source": [
"(1b) Pro každou skupinu zvlášť otestujte na hladině významnosti 5 % hypotézu,\n",
"zda je střední hodnota rovná hodnotě K (parametr úlohy), proti oboustranné alternativě.\n",
"Můžete použít buď výsledek z předešlého bodu, nebo výstup z příslušné vestavěné funkce vašeho softwaru."
]
},
2024-10-20 22:34:55 +02:00
{
"cell_type": "code",
"execution_count": 33,
"id": "379f961c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- Výsledky t-testu pro skupinu: perished ---\n",
"T-statistika: 4.2421\n",
"P-hodnota: 0.0003\n",
"Zamítáme nulovou hypotézu (střední hodnota se statisticky významně liší od K).\n",
"\n",
"--- Výsledky t-testu pro skupinu: survived ---\n",
"T-statistika: 2.1752\n",
"P-hodnota: 0.0367\n",
"Zamítáme nulovou hypotézu (střední hodnota se statisticky významně liší od K).\n"
]
}
],
"source": [
"for name, group in groups:\n",
" t_stat, p_value = stats.ttest_1samp(group['Weight'], 25)\n",
" print(f\"\\n--- Výsledky t-testu pro skupinu: {name} ---\")\n",
" print(f\"T-statistika: {t_stat:.4f}\")\n",
" print(f\"P-hodnota: {p_value:.4f}\")\n",
" \n",
" # Vyhodnocení na hladině významnosti 5 %\n",
" if p_value < 0.05:\n",
" print(\"Zamítáme nulovou hypotézu (střední hodnota se statisticky významně liší od K).\")\n",
" else:\n",
" print(\"Nezamítáme nulovou hypotézu (střední hodnota se statisticky významně neliší od K).\")\n"
]
},
{
"cell_type": "markdown",
"id": "ccd22286",
"metadata": {},
"source": [
"Postupovalo se tak, že se pro každou skupinu provedl t-test k ověření, zda se střední hmotnost vrabců významně liší od hodnoty 25, přičemž se hodnotily p-hodnoty a rozhodovalo se o zamítnutí nulové hypotézy na základě hladiny významnosti 0,05."
]
},
{
"cell_type": "markdown",
"id": "7f993c66",
"metadata": {},
"source": [
"Můžeme tedy říci, zda střední váha vrabců v každé skupině odpovídá hodnotě KK, nebo zda se významně liší."
]
},
2024-10-19 13:46:09 +02:00
{
"cell_type": "markdown",
"id": "617cf82f",
"metadata": {},
"source": [
"## Úloha č. 7"
]
},
2024-10-18 21:02:29 +02:00
{
"cell_type": "markdown",
"id": "7007c195-97a3-4cd4-8427-dcc8417eedf8",
"metadata": {},
"source": [
"(2b) Na hladině významnosti 5 % otestujte, jestli mají pozorované skupiny stejnou střední hodnotu.\n",
"Typ testu a alternativy stanovte tak, aby vaše volba nejlépe korespondovala s povahou zkoumaného problému."
]
2024-10-20 22:34:55 +02:00
},
{
"cell_type": "markdown",
"id": "0736883a",
"metadata": {},
"source": [
"Byl proveden t-test pro nezávislé vzorky, aby se zjistilo, zda existuje rozdíl ve středních hodnotách mezi skupinami přežití a úmrtí, přičemž byla vyhodnocena p-hodnota a porovnána s hladinou významnosti 0.05."
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "557d6c95",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"T-test: T-statistika = -2.27141, p-hodnota = 0.02692\n",
"Zamítáme nulovou hypotézu. Skupiny mají různé střední hodnoty.\n"
]
}
],
"source": [
"t_test = stats.ttest_ind(survived, perished, equal_var=True) \n",
"print(f\"T-test: T-statistika = {t_test.statistic:.5f}, p-hodnota = {t_test.pvalue:.5f}\")\n",
"\n",
"alpha = 0.05\n",
"if t_test.pvalue < alpha:\n",
" print(\"Zamítáme nulovou hypotézu. Skupiny mají různé střední hodnoty.\")\n",
"else:\n",
" print(\"Nepodařilo se zamítnout nulovou hypotézu. Skupiny mají stejné střední hodnoty.\")\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "984140bc",
"metadata": {},
"source": [
"Pokud byla p-hodnota t-testu menší než 0.05, zamítli jsme nulovou hypotézu, což znamená, že střední váha vrabců se mezi skupinami liší. To naznačuje, že faktory ovlivňující přežití mohou souviset s hmotností vrabců, což by mohlo mít vliv na jejich schopnost se přizpůsobit obtížným podmínkám.\n",
"\n",
"Z analýzy tedy vyplývá, že mezi skupinami existuje významný rozdíl ve středních hodnotách."
]
2024-10-18 18:42:33 +02:00
}
],
"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.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}