diff --git a/your-code/main.ipynb b/your-code/main.ipynb
index cdc1acb..d27ef65 100644
--- a/your-code/main.ipynb
+++ b/your-code/main.ipynb
@@ -14,12 +14,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'C:\\\\Data_Science\\\\IH_Notebooks\\\\lab-two-sample-hyp-test\\\\your-code'"
+ ]
+ },
+ "execution_count": 1,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# import numpy and pandas\n",
- "\n"
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import os\n",
+ "os.getcwd()\n"
]
},
{
@@ -35,13 +49,267 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " # | \n",
+ " Name | \n",
+ " Type 1 | \n",
+ " Type 2 | \n",
+ " Total | \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",
+ " 1 | \n",
+ " Bulbasaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 318 | \n",
+ " 45 | \n",
+ " 49 | \n",
+ " 49 | \n",
+ " 65 | \n",
+ " 65 | \n",
+ " 45 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Ivysaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 405 | \n",
+ " 60 | \n",
+ " 62 | \n",
+ " 63 | \n",
+ " 80 | \n",
+ " 80 | \n",
+ " 60 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 525 | \n",
+ " 80 | \n",
+ " 82 | \n",
+ " 83 | \n",
+ " 100 | \n",
+ " 100 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 3 | \n",
+ " VenusaurMega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 625 | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 309 | \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",
+ "
\n",
+ " \n",
+ " | 795 | \n",
+ " 719 | \n",
+ " Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 600 | \n",
+ " 50 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 50 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 796 | \n",
+ " 719 | \n",
+ " DiancieMega Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 700 | \n",
+ " 50 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 110 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 797 | \n",
+ " 720 | \n",
+ " HoopaHoopa Confined | \n",
+ " Psychic | \n",
+ " Ghost | \n",
+ " 600 | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 60 | \n",
+ " 150 | \n",
+ " 130 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 798 | \n",
+ " 720 | \n",
+ " HoopaHoopa Unbound | \n",
+ " Psychic | \n",
+ " Dark | \n",
+ " 680 | \n",
+ " 80 | \n",
+ " 160 | \n",
+ " 60 | \n",
+ " 170 | \n",
+ " 130 | \n",
+ " 80 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 799 | \n",
+ " 721 | \n",
+ " Volcanion | \n",
+ " Fire | \n",
+ " Water | \n",
+ " 600 | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 120 | \n",
+ " 130 | \n",
+ " 90 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
800 rows × 13 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " # Name Type 1 Type 2 Total HP Attack Defense \\\n",
+ "0 1 Bulbasaur Grass Poison 318 45 49 49 \n",
+ "1 2 Ivysaur Grass Poison 405 60 62 63 \n",
+ "2 3 Venusaur Grass Poison 525 80 82 83 \n",
+ "3 3 VenusaurMega Venusaur Grass Poison 625 80 100 123 \n",
+ "4 4 Charmander Fire NaN 309 39 52 43 \n",
+ ".. ... ... ... ... ... .. ... ... \n",
+ "795 719 Diancie Rock Fairy 600 50 100 150 \n",
+ "796 719 DiancieMega Diancie Rock Fairy 700 50 160 110 \n",
+ "797 720 HoopaHoopa Confined Psychic Ghost 600 80 110 60 \n",
+ "798 720 HoopaHoopa Unbound Psychic Dark 680 80 160 60 \n",
+ "799 721 Volcanion Fire Water 600 80 110 120 \n",
+ "\n",
+ " Sp. Atk Sp. Def Speed Generation Legendary \n",
+ "0 65 65 45 1 False \n",
+ "1 80 80 60 1 False \n",
+ "2 100 100 80 1 False \n",
+ "3 122 120 80 1 False \n",
+ "4 60 50 65 1 False \n",
+ ".. ... ... ... ... ... \n",
+ "795 100 150 50 6 True \n",
+ "796 160 110 110 6 True \n",
+ "797 150 130 70 6 True \n",
+ "798 170 130 80 6 True \n",
+ "799 130 90 70 6 True \n",
+ "\n",
+ "[800 rows x 13 columns]"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Run this code:\n",
"\n",
- "pokemon = pd.read_csv('../pokemon.csv')"
+ "pokemon = pd.read_csv('../pokemon.csv')\n",
+ "pokemon"
]
},
{
@@ -53,12 +321,155 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " # | \n",
+ " Name | \n",
+ " Type 1 | \n",
+ " Type 2 | \n",
+ " Total | \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",
+ " 1 | \n",
+ " Bulbasaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 318 | \n",
+ " 45 | \n",
+ " 49 | \n",
+ " 49 | \n",
+ " 65 | \n",
+ " 65 | \n",
+ " 45 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Ivysaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 405 | \n",
+ " 60 | \n",
+ " 62 | \n",
+ " 63 | \n",
+ " 80 | \n",
+ " 80 | \n",
+ " 60 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 525 | \n",
+ " 80 | \n",
+ " 82 | \n",
+ " 83 | \n",
+ " 100 | \n",
+ " 100 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 3 | \n",
+ " VenusaurMega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 625 | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 309 | \n",
+ " 39 | \n",
+ " 52 | \n",
+ " 43 | \n",
+ " 60 | \n",
+ " 50 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " # Name Type 1 Type 2 Total HP Attack Defense \\\n",
+ "0 1 Bulbasaur Grass Poison 318 45 49 49 \n",
+ "1 2 Ivysaur Grass Poison 405 60 62 63 \n",
+ "2 3 Venusaur Grass Poison 525 80 82 83 \n",
+ "3 3 VenusaurMega Venusaur Grass Poison 625 80 100 123 \n",
+ "4 4 Charmander Fire NaN 309 39 52 43 \n",
+ "\n",
+ " Sp. Atk Sp. Def Speed Generation Legendary \n",
+ "0 65 65 45 1 False \n",
+ "1 80 80 60 1 False \n",
+ "2 100 100 80 1 False \n",
+ "3 122 120 80 1 False \n",
+ "4 60 50 65 1 False "
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "pokemon.head()"
]
},
{
@@ -70,11 +481,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Legendary\n",
+ "False 735\n",
+ "True 65\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
+ "\n",
+ "pokemon.value_counts(pokemon.Legendary)\n",
"\n"
]
},
@@ -87,12 +514,33 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 17,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Mean non-legendary: 417.21360544217686\n",
+ "Std non-legendary: 106.76041745713005\n",
+ "Mean legendary: 637.3846153846154\n",
+ "Std non-legendary: 60.93738905315344\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "non_legendary = pokemon.copy()\n",
+ "legendary = pokemon.copy()\n",
+ "\n",
+ "non_legendary = non_legendary.loc[(non_legendary['Legendary'] == False)]\n",
+ "legendary = legendary.loc[(legendary['Legendary'] == True)]\n",
+ "\n",
+ "print(\"Mean non-legendary: \", non_legendary['Total'].mean())\n",
+ "print(\"Std non-legendary: \", non_legendary['Total'].std())\n",
+ "print(\"Mean legendary: \", legendary['Total'].mean())\n",
+ "print(\"Std non-legendary: \", legendary['Total'].std())"
]
},
{
@@ -106,11 +554,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 20,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Test statistics (t): 25.8335743895517\n",
+ "P_value: 9.357954335957444e-47\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
+ "import scipy.stats as st\n",
+ "\n",
+ "alpha = 0.05\n",
+ "\n",
+ "non_legendary = non_legendary['Total'].dropna()\n",
+ "legendary = legendary['Total'].dropna()\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(legendary, non_legendary, equal_var=False)\n",
+ "\n",
+ "print(f\"Test statistics (t): {t_stat}\")\n",
+ "print(f\"P_value: {p_value}\")\n",
"\n"
]
},
@@ -123,12 +591,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 21,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There's enough evidence to reject the H0 hypothesis.\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
- "\n"
+ "\n",
+ "null_hypothesis = \"There is no difference in mean Total points between legendary and non-legendary Pokemon.\"\n",
+ "alt_hypothesis = \"There is difference in mean Total points between legendary and non-legendary Pokemon.\"\n",
+ "\n",
+ "if p_value > alpha:\n",
+ " print(\"There's not enough evidence to reject the H0 hypothesis.\")\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"There's enough evidence to reject the H0 hypothesis.\")"
]
},
{
@@ -140,11 +624,42 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 23,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Type 1\n",
+ "Water 112\n",
+ "Normal 98\n",
+ "Grass 70\n",
+ "Bug 69\n",
+ "Psychic 57\n",
+ "Fire 52\n",
+ "Rock 44\n",
+ "Electric 44\n",
+ "Ground 32\n",
+ "Ghost 32\n",
+ "Dragon 32\n",
+ "Dark 31\n",
+ "Poison 28\n",
+ "Fighting 27\n",
+ "Steel 27\n",
+ "Ice 24\n",
+ "Fairy 17\n",
+ "Flying 4\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 23,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
+ "pokemon['Type 1'].value_counts()\n",
"\n"
]
},
@@ -157,12 +672,34 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 33,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Mean Total Water pokemon: 430.45535714285717\n",
+ "Std Total Water pokemon: 113.1882660643146\n",
+ "Mean Total Non-Water pokemon: 430.45535714285717\n",
+ "Std Total Non-Water pokemon: 113.1882660643146\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "water_pokemon = pokemon.copy()\n",
+ "non_water_pokemon = pokemon.copy()\n",
+ "\n",
+ "water_pokemon = water_pokemon.loc[(water_pokemon['Type 1'] == 'Water')]\n",
+ "non_water_pokemon = non_water_pokemon.loc[(non_water_pokemon['Type 1'] != 'Water')]\n",
+ "\n",
+ "\n",
+ "print(\"Mean Total Water pokemon: \", water_pokemon['Total'].mean())\n",
+ "print(\"Std Total Water pokemon: \", water_pokemon['Total'].std())\n",
+ "print(\"Mean Total Non-Water pokemon: \", water_pokemon['Total'].mean())\n",
+ "print(\"Std Total Non-Water pokemon: \", water_pokemon['Total'].std())"
]
},
{
@@ -174,12 +711,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 35,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Test statistics (t): -0.4418547448849676\n",
+ "P_value: 0.6587140317488793\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "water_pokemon = water_pokemon['Total'].dropna()\n",
+ "non_water_pokemon = non_water_pokemon['Total'].dropna()\n",
+ "\n",
+ "t_stat, p_value = st.ttest_ind(water_pokemon, non_water_pokemon, equal_var=True)\n",
+ "\n",
+ "print(f\"Test statistics (t): {t_stat}\")\n",
+ "print(f\"P_value: {p_value}\")"
]
},
{
@@ -191,12 +744,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 36,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There's not enough evidence to reject the H0 hypothesis.\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
- "\n"
+ "\n",
+ "null_hypothesis = \"There is no difference in Mean Total points between Water and non Water pokemon.\"\n",
+ "alt_hypothesis = \"There is difference in Mean Total points between Water and non Water pokemon.\"\n",
+ "\n",
+ "if p_value > alpha:\n",
+ " print(\"There's not enough evidence to reject the H0 hypothesis.\")\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"There's enough evidence to reject the H0 hypothesis.\")"
]
},
{
@@ -210,12 +779,29 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 37,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Test Statistic (t): 4.325566393330478\n",
+ "P-Value: 1.7140303479358558e-05\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "null_hypothesis = \"Defense and Attack scores are equal.\"\n",
+ "alt_hypothesis = \"Defense and Attack scores aren't equal.\"\n",
+ "\n",
+ "\n",
+ "t_stat, p_value = st.ttest_rel(pokemon['Attack'], pokemon['Defense'])\n",
+ "\n",
+ "print(f\"Test Statistic (t): {t_stat}\")\n",
+ "print(f\"P-Value: {p_value:}\")"
]
},
{
@@ -227,12 +813,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 38,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There's enough evidence to reject the H0 hypothesis.\n",
+ "Defense and Attack scores aren't equal.\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
- "\n"
+ "\n",
+ "if p_value > alpha:\n",
+ " print(\"There's not enough evidence to reject the H0 hypothesis.\")\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"There's enough evidence to reject the H0 hypothesis.\")\n",
+ "\n",
+ "print(alt_hypothesis)"
]
},
{
@@ -244,12 +846,29 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 39,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Test Statistic (t): 0.853986188453353\n",
+ "P-Value: 0.3933685997548122\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "null_hypothesis = \"There's no difference between mean Special Defense and Mean Special Attack\"\n",
+ "alt_hypothesis = \"There difference between mean Special Defense and Mean Special Attack\"\n",
+ "\n",
+ "\n",
+ "t_stat, p_value = st.ttest_rel(pokemon['Sp. Atk'], pokemon['Sp. Def'])\n",
+ "\n",
+ "print(f\"Test Statistic (t): {t_stat}\")\n",
+ "print(f\"P-Value: {p_value:}\")"
]
},
{
@@ -261,12 +880,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 40,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There's not enough evidence to reject the H0 hypothesis.\n",
+ "There's no difference between mean Special Defense and Mean Special Attack\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
- "\n"
+ "\n",
+ "if p_value > alpha:\n",
+ " print(\"There's not enough evidence to reject the H0 hypothesis.\")\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"There's enough evidence to reject the H0 hypothesis.\")\n",
+ "\n",
+ "print(null_hypothesis)\n"
]
},
{
@@ -280,13 +915,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 44,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Test Statistic (t): 4.325566393330478\n",
+ "P-Value: 8.570151739679279e-06\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- " \n",
- " "
+ "\n",
+ "pokemon['Difference_Att_Def'] = (pokemon['Attack'] - pokemon['Defense'])\n",
+ "\n",
+ "t_stat, p_value = st.ttest_1samp(pokemon['Difference_Att_Def'], 0, alternative='greater')\n",
+ "\n",
+ "print(f\"Test Statistic (t): {t_stat}\")\n",
+ "print(f\"P-Value: {p_value:}\")"
]
},
{
@@ -302,12 +951,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 50,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Is_water_type False True \n",
+ "Legendary \n",
+ "False 627 108\n",
+ "True 61 4\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "pokemon['Is_water_type'] = pokemon['Type 1'] == 'Water'\n",
+ "\n",
+ "cross_tab = pd.crosstab(pokemon['Legendary'],pokemon['Is_water_type'])\n",
+ "print(cross_tab)\n"
]
},
{
@@ -319,12 +983,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 54,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Chi2ContingencyResult(statistic=np.float64(2.9429200762850503), pvalue=np.float64(0.0862546724955095), dof=1, expected_freq=array([[632.1, 102.9],\n",
+ " [ 55.9, 9.1]]))"
+ ]
+ },
+ "execution_count": 54,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "\n",
+ "from scipy.stats import chi2_contingency\n",
+ "\n",
+ "chi2_stat, p_value, _, _ = chi2_contingency(cross_tab)\n",
+ "chi2_pvalue"
]
},
{
@@ -336,12 +1016,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 55,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "There's not enough evidence to reject the H0.\n",
+ "There is no correlation between Legendary Pokemon and Water Type.\n"
+ ]
+ }
+ ],
"source": [
"# Your answer here:\n",
- "\n"
+ "\n",
+ "null_hypothesis = \"There is no correlation between Legendary Pokemon and Water Type.\"\n",
+ "alt_hypothesis = \"There is cocorrelation between Legendary Pokemon and Water Type.\"\n",
+ "\n",
+ "if p_value > alpha:\n",
+ " print(\"There's not enough evidence to reject the H0.\")\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"There enough evidence to reject the H0.\")\n",
+ "\n",
+ "print(null_hypothesis)\n"
]
},
{
@@ -354,7 +1053,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -368,9 +1067,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.13.2"
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}