diff --git a/.ipynb_checkpoints/lab-hypothesis-testing-checkpoint.ipynb b/.ipynb_checkpoints/lab-hypothesis-testing-checkpoint.ipynb
new file mode 100644
index 0000000..c8d2adb
--- /dev/null
+++ b/.ipynb_checkpoints/lab-hypothesis-testing-checkpoint.ipynb
@@ -0,0 +1,785 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Lab | Hypothesis Testing"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Objective**\n",
+ "\n",
+ "Welcome to the Hypothesis Testing Lab, where we embark on an enlightening journey through the realm of statistical decision-making! In this laboratory, we delve into various scenarios, applying the powerful tools of hypothesis testing to scrutinize and interpret data.\n",
+ "\n",
+ "From testing the mean of a single sample (One Sample T-Test), to investigating differences between independent groups (Two Sample T-Test), and exploring relationships within dependent samples (Paired Sample T-Test), our exploration knows no bounds. Furthermore, we'll venture into the realm of Analysis of Variance (ANOVA), unraveling the complexities of comparing means across multiple groups.\n",
+ "\n",
+ "So, grab your statistical tools, prepare your hypotheses, and let's embark on this fascinating journey of exploration and discovery in the world of hypothesis testing!"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Challenge 1**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In this challenge, we will be working with pokemon data. The data can be found here:\n",
+ "\n",
+ "- https://raw.githubusercontent.com/data-bootcamp-v4/data/main/pokemon.csv"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#libraries\n",
+ "import pandas as pd\n",
+ "import scipy.stats as st\n",
+ "import numpy as np\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Name | \n",
+ " Type 1 | \n",
+ " Type 2 | \n",
+ " HP | \n",
+ " Attack | \n",
+ " Defense | \n",
+ " Sp. Atk | \n",
+ " Sp. Def | \n",
+ " Speed | \n",
+ " Generation | \n",
+ " Legendary | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " Bulbasaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 45 | \n",
+ " 49 | \n",
+ " 49 | \n",
+ " 65 | \n",
+ " 65 | \n",
+ " 45 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " Ivysaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 60 | \n",
+ " 62 | \n",
+ " 63 | \n",
+ " 80 | \n",
+ " 80 | \n",
+ " 60 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 80 | \n",
+ " 82 | \n",
+ " 83 | \n",
+ " 100 | \n",
+ " 100 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " Mega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 39 | \n",
+ " 52 | \n",
+ " 43 | \n",
+ " 60 | \n",
+ " 50 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 795 | \n",
+ " Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 50 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 50 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 796 | \n",
+ " Mega Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 50 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 110 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 797 | \n",
+ " Hoopa Confined | \n",
+ " Psychic | \n",
+ " Ghost | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 60 | \n",
+ " 150 | \n",
+ " 130 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 798 | \n",
+ " Hoopa Unbound | \n",
+ " Psychic | \n",
+ " Dark | \n",
+ " 80 | \n",
+ " 160 | \n",
+ " 60 | \n",
+ " 170 | \n",
+ " 130 | \n",
+ " 80 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 799 | \n",
+ " Volcanion | \n",
+ " Fire | \n",
+ " Water | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 120 | \n",
+ " 130 | \n",
+ " 90 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
800 rows × 11 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Name Type 1 Type 2 HP Attack Defense Sp. Atk Sp. Def \\\n",
+ "0 Bulbasaur Grass Poison 45 49 49 65 65 \n",
+ "1 Ivysaur Grass Poison 60 62 63 80 80 \n",
+ "2 Venusaur Grass Poison 80 82 83 100 100 \n",
+ "3 Mega Venusaur Grass Poison 80 100 123 122 120 \n",
+ "4 Charmander Fire NaN 39 52 43 60 50 \n",
+ ".. ... ... ... .. ... ... ... ... \n",
+ "795 Diancie Rock Fairy 50 100 150 100 150 \n",
+ "796 Mega Diancie Rock Fairy 50 160 110 160 110 \n",
+ "797 Hoopa Confined Psychic Ghost 80 110 60 150 130 \n",
+ "798 Hoopa Unbound Psychic Dark 80 160 60 170 130 \n",
+ "799 Volcanion Fire Water 80 110 120 130 90 \n",
+ "\n",
+ " Speed Generation Legendary \n",
+ "0 45 1 False \n",
+ "1 60 1 False \n",
+ "2 80 1 False \n",
+ "3 80 1 False \n",
+ "4 65 1 False \n",
+ ".. ... ... ... \n",
+ "795 50 6 True \n",
+ "796 110 6 True \n",
+ "797 70 6 True \n",
+ "798 80 6 True \n",
+ "799 70 6 True \n",
+ "\n",
+ "[800 rows x 11 columns]"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df = pd.read_csv(\"https://raw.githubusercontent.com/data-bootcamp-v4/data/main/pokemon.csv\")\n",
+ "df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- We posit that Pokemons of type Dragon have, on average, more HP stats than Grass. Choose the propper test and, with 5% significance, comment your findings."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# H0 = Average HP of Dragon type pokemons > Average HP of Grass type pokemons\n",
+ "# H1 = Average HP of Dragon type pokemons !> Average HP of Grass type pokemons\n",
+ "\n",
+ "\n",
+ "\n",
+ "df_dragon = df[df[\"Type 1\"]==\"Dragon\"][\"HP\"]\n",
+ "df_grass = df[df[\"Type 1\"]==\"Grass\"][\"HP\"]\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\n",
+ "[ 'Poison', nan, 'Flying', 'Dragon', 'Ground', 'Fairy',\n",
+ " 'Grass', 'Fighting', 'Psychic', 'Steel', 'Ice', 'Rock',\n",
+ " 'Dark', 'Water', 'Electric', 'Fire', 'Ghost', 'Bug',\n",
+ " 'Normal']\n",
+ "Length: 19, dtype: str"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df[\"Type 2\"].unique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "3.3349632905124063 0.0007993609745420602\n"
+ ]
+ }
+ ],
+ "source": [
+ "#1 tailed 2-sample test\n",
+ "\n",
+ "df_dragon = df[df[\"Type 1\"] == \"Dragon\"][\"HP\"]\n",
+ "df_grass = df[df[\"Type 1\"] == \"Grass\"][\"HP\"]\n",
+ "t_stat, p_value=st.ttest_ind(df_dragon,df_grass, equal_var=False,alternative=\"greater\")\n",
+ "\n",
+ "\n",
+ "print(t_stat, p_value)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "alpha = 0.05\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "- We posit that Legendary Pokemons have different stats (HP, Attack, Defense, Sp.Atk, Sp.Def, Speed) when comparing with Non-Legendary. Choose the propper test and, with 5% significance, comment your findings.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df_legendary = df[df[\"Legendary\"] == True]\n",
+ "df_non_legendary = df[df[\"Legendary\"] == False]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "8.981370483625046 1.0026911708035289e-13\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#HP\n",
+ "\n",
+ "#H0: Legendary pokemons HP = Non-Legendary pokemons HP\n",
+ "#H1: Legendary pokemons HP != Non-Legendary pokemons HP\n",
+ "\n",
+ "df_legendary_HP = df_legendary[\"HP\"]\n",
+ "df_non_legendary_HP = df_non_legendary[\"HP\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_HP,df_non_legendary_HP, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "10.438133539322203 2.520372449236657e-16\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Attack\n",
+ "\n",
+ "#H0: Legendary pokemons Attack = Non-Legendary pokemons Attack\n",
+ "#H1: Legendary pokemons Attack != Non-Legendary pokemons Attack\n",
+ "\n",
+ "df_legendary_Attack = df_legendary[\"Attack\"]\n",
+ "df_non_legendary_Attack = df_non_legendary[\"Attack\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Attack,df_non_legendary_Attack, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "7.637078164784618 4.8269984949193406e-11\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Defense\n",
+ "\n",
+ "#H0: Legendary pokemons Defense = Non-Legendary pokemons Defense\n",
+ "#H1: Legendary pokemons Defense != Non-Legendary pokemons Defense\n",
+ "\n",
+ "df_legendary_Defense = df_legendary[\"Defense\"]\n",
+ "df_non_legendary_Defense = df_non_legendary[\"Defense\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Defense,df_non_legendary_Defense, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "13.417449984138461 1.5514614112239793e-21\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Sp. Atk\n",
+ "\n",
+ "#H0: Legendary pokemons Sp. Atk = Non-Legendary pokemons Sp. Atk\n",
+ "#H1: Legendary pokemons Sp. Atk != Non-Legendary pokemons Sp. Atk\n",
+ "\n",
+ "df_legendary_Sp_Atk = df_legendary[\"Sp. Atk\"]\n",
+ "df_non_legendary_Sp_Atk = df_non_legendary[\"Sp. Atk\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Sp_Atk,df_non_legendary_Sp_Atk, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "10.015696613114878 2.2949327864052933e-15\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Sp. Def\n",
+ "\n",
+ "\n",
+ "#H0: Legendary pokemons Sp. Def = Non-Legendary pokemons Sp. Def\n",
+ "#H1: Legendary pokemons Sp. Def != Non-Legendary pokemons Sp. Def\n",
+ "\n",
+ "df_legendary_Sp_Def = df_legendary[\"Sp. Def\"]\n",
+ "df_non_legendary_Sp_Def = df_non_legendary[\"Sp. Def\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Sp_Def,df_non_legendary_Sp_Def, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "11.47504444631443 1.049016311882455e-18\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Speed\n",
+ "\n",
+ "\n",
+ "#H0: Legendary pokemons Speed = Non-Legendary pokemons Speed\n",
+ "#H1: Legendary pokemons Speed != Non-Legendary pokemons Speed\n",
+ "\n",
+ "df_legendary_speed = df_legendary[\"Speed\"]\n",
+ "df_non_legendary_speed = df_non_legendary[\"Speed\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_speed,df_non_legendary_speed, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**Challenge 2**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In this challenge, we will be working with california-housing data. The data can be found here:\n",
+ "- https://raw.githubusercontent.com/data-bootcamp-v4/data/main/california_housing.csv"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " longitude | \n",
+ " latitude | \n",
+ " housing_median_age | \n",
+ " total_rooms | \n",
+ " total_bedrooms | \n",
+ " population | \n",
+ " households | \n",
+ " median_income | \n",
+ " median_house_value | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " -114.31 | \n",
+ " 34.19 | \n",
+ " 15.0 | \n",
+ " 5612.0 | \n",
+ " 1283.0 | \n",
+ " 1015.0 | \n",
+ " 472.0 | \n",
+ " 1.4936 | \n",
+ " 66900.0 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " -114.47 | \n",
+ " 34.40 | \n",
+ " 19.0 | \n",
+ " 7650.0 | \n",
+ " 1901.0 | \n",
+ " 1129.0 | \n",
+ " 463.0 | \n",
+ " 1.8200 | \n",
+ " 80100.0 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " -114.56 | \n",
+ " 33.69 | \n",
+ " 17.0 | \n",
+ " 720.0 | \n",
+ " 174.0 | \n",
+ " 333.0 | \n",
+ " 117.0 | \n",
+ " 1.6509 | \n",
+ " 85700.0 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " -114.57 | \n",
+ " 33.64 | \n",
+ " 14.0 | \n",
+ " 1501.0 | \n",
+ " 337.0 | \n",
+ " 515.0 | \n",
+ " 226.0 | \n",
+ " 3.1917 | \n",
+ " 73400.0 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " -114.57 | \n",
+ " 33.57 | \n",
+ " 20.0 | \n",
+ " 1454.0 | \n",
+ " 326.0 | \n",
+ " 624.0 | \n",
+ " 262.0 | \n",
+ " 1.9250 | \n",
+ " 65500.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " longitude latitude housing_median_age total_rooms total_bedrooms \\\n",
+ "0 -114.31 34.19 15.0 5612.0 1283.0 \n",
+ "1 -114.47 34.40 19.0 7650.0 1901.0 \n",
+ "2 -114.56 33.69 17.0 720.0 174.0 \n",
+ "3 -114.57 33.64 14.0 1501.0 337.0 \n",
+ "4 -114.57 33.57 20.0 1454.0 326.0 \n",
+ "\n",
+ " population households median_income median_house_value \n",
+ "0 1015.0 472.0 1.4936 66900.0 \n",
+ "1 1129.0 463.0 1.8200 80100.0 \n",
+ "2 333.0 117.0 1.6509 85700.0 \n",
+ "3 515.0 226.0 3.1917 73400.0 \n",
+ "4 624.0 262.0 1.9250 65500.0 "
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df = pd.read_csv(\"https://raw.githubusercontent.com/data-bootcamp-v4/data/main/california_housing.csv\")\n",
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**We posit that houses close to either a school or a hospital are more expensive.**\n",
+ "\n",
+ "- School coordinates (-118, 34)\n",
+ "- Hospital coordinates (-122, 37)\n",
+ "\n",
+ "We consider a house (neighborhood) to be close to a school or hospital if the distance is lower than 0.50.\n",
+ "\n",
+ "Hint:\n",
+ "- Write a function to calculate euclidean distance from each house (neighborhood) to the school and to the hospital.\n",
+ "- Divide your dataset into houses close and far from either a hospital or school.\n",
+ "- Choose the propper test and, with 5% significance, comment your findings.\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.14.6"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}
diff --git a/lab-hypothesis-testing.ipynb b/lab-hypothesis-testing.ipynb
index 0cc26d5..c8d2adb 100644
--- a/lab-hypothesis-testing.ipynb
+++ b/lab-hypothesis-testing.ipynb
@@ -38,7 +38,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -51,7 +51,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 13,
"metadata": {},
"outputs": [
{
@@ -278,7 +278,7 @@
"[800 rows x 11 columns]"
]
},
- "execution_count": 3,
+ "execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
@@ -297,11 +297,88 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
- "#code here"
+ "# H0 = Average HP of Dragon type pokemons > Average HP of Grass type pokemons\n",
+ "# H1 = Average HP of Dragon type pokemons !> Average HP of Grass type pokemons\n",
+ "\n",
+ "\n",
+ "\n",
+ "df_dragon = df[df[\"Type 1\"]==\"Dragon\"][\"HP\"]\n",
+ "df_grass = df[df[\"Type 1\"]==\"Grass\"][\"HP\"]\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\n",
+ "[ 'Poison', nan, 'Flying', 'Dragon', 'Ground', 'Fairy',\n",
+ " 'Grass', 'Fighting', 'Psychic', 'Steel', 'Ice', 'Rock',\n",
+ " 'Dark', 'Water', 'Electric', 'Fire', 'Ghost', 'Bug',\n",
+ " 'Normal']\n",
+ "Length: 19, dtype: str"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df[\"Type 2\"].unique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "3.3349632905124063 0.0007993609745420602\n"
+ ]
+ }
+ ],
+ "source": [
+ "#1 tailed 2-sample test\n",
+ "\n",
+ "df_dragon = df[df[\"Type 1\"] == \"Dragon\"][\"HP\"]\n",
+ "df_grass = df[df[\"Type 1\"] == \"Grass\"][\"HP\"]\n",
+ "t_stat, p_value=st.ttest_ind(df_dragon,df_grass, equal_var=False,alternative=\"greater\")\n",
+ "\n",
+ "\n",
+ "print(t_stat, p_value)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "alpha = 0.05\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
]
},
{
@@ -313,11 +390,206 @@
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
- "#code here"
+ "df_legendary = df[df[\"Legendary\"] == True]\n",
+ "df_non_legendary = df[df[\"Legendary\"] == False]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 45,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "8.981370483625046 1.0026911708035289e-13\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#HP\n",
+ "\n",
+ "#H0: Legendary pokemons HP = Non-Legendary pokemons HP\n",
+ "#H1: Legendary pokemons HP != Non-Legendary pokemons HP\n",
+ "\n",
+ "df_legendary_HP = df_legendary[\"HP\"]\n",
+ "df_non_legendary_HP = df_non_legendary[\"HP\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_HP,df_non_legendary_HP, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 46,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "10.438133539322203 2.520372449236657e-16\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Attack\n",
+ "\n",
+ "#H0: Legendary pokemons Attack = Non-Legendary pokemons Attack\n",
+ "#H1: Legendary pokemons Attack != Non-Legendary pokemons Attack\n",
+ "\n",
+ "df_legendary_Attack = df_legendary[\"Attack\"]\n",
+ "df_non_legendary_Attack = df_non_legendary[\"Attack\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Attack,df_non_legendary_Attack, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 47,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "7.637078164784618 4.8269984949193406e-11\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Defense\n",
+ "\n",
+ "#H0: Legendary pokemons Defense = Non-Legendary pokemons Defense\n",
+ "#H1: Legendary pokemons Defense != Non-Legendary pokemons Defense\n",
+ "\n",
+ "df_legendary_Defense = df_legendary[\"Defense\"]\n",
+ "df_non_legendary_Defense = df_non_legendary[\"Defense\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Defense,df_non_legendary_Defense, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "13.417449984138461 1.5514614112239793e-21\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Sp. Atk\n",
+ "\n",
+ "#H0: Legendary pokemons Sp. Atk = Non-Legendary pokemons Sp. Atk\n",
+ "#H1: Legendary pokemons Sp. Atk != Non-Legendary pokemons Sp. Atk\n",
+ "\n",
+ "df_legendary_Sp_Atk = df_legendary[\"Sp. Atk\"]\n",
+ "df_non_legendary_Sp_Atk = df_non_legendary[\"Sp. Atk\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Sp_Atk,df_non_legendary_Sp_Atk, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "10.015696613114878 2.2949327864052933e-15\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Sp. Def\n",
+ "\n",
+ "\n",
+ "#H0: Legendary pokemons Sp. Def = Non-Legendary pokemons Sp. Def\n",
+ "#H1: Legendary pokemons Sp. Def != Non-Legendary pokemons Sp. Def\n",
+ "\n",
+ "df_legendary_Sp_Def = df_legendary[\"Sp. Def\"]\n",
+ "df_non_legendary_Sp_Def = df_non_legendary[\"Sp. Def\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_Sp_Def,df_non_legendary_Sp_Def, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "11.47504444631443 1.049016311882455e-18\n",
+ "H0 rejected\n"
+ ]
+ }
+ ],
+ "source": [
+ "#Speed\n",
+ "\n",
+ "\n",
+ "#H0: Legendary pokemons Speed = Non-Legendary pokemons Speed\n",
+ "#H1: Legendary pokemons Speed != Non-Legendary pokemons Speed\n",
+ "\n",
+ "df_legendary_speed = df_legendary[\"Speed\"]\n",
+ "df_non_legendary_speed = df_non_legendary[\"Speed\"]\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(df_legendary_speed,df_non_legendary_speed, equal_var=False)\n",
+ "print(t_stat, p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"H0 rejected\")\n",
+ "else:\n",
+ " print(\"H0 cannot be rejected.\")"
]
},
{
@@ -481,13 +753,6 @@
" "
]
},
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
{
"cell_type": "code",
"execution_count": null,
@@ -498,7 +763,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -512,9 +777,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.9"
+ "version": "3.14.6"
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}