diff --git a/your-code/main.ipynb b/your-code/main.ipynb
index cdc1acb..61ec6f8 100644
--- a/your-code/main.ipynb
+++ b/your-code/main.ipynb
@@ -14,12 +14,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import numpy and pandas\n",
- "\n"
+ "\n",
+ "import pandas as pd # manipulate dataframes\n",
+ "import numpy as np # numerical python"
]
},
{
@@ -35,13 +37,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Run this code:\n",
"\n",
- "pokemon = pd.read_csv('../pokemon.csv')"
+ "pokemon_df = pd.read_csv('../pokemon.csv')\n",
+ "pokemon = pokemon_df.copy()"
]
},
{
@@ -53,11 +56,155 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 5,
+ "metadata": {},
+ "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": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
+ "pokemon.head(5)\n",
+ "\n",
"\n"
]
},
@@ -70,11 +217,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Legendary\n",
+ "False 735\n",
+ "True 65\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
+ "legendary_pokemon_counts = pokemon[\"Legendary\"].value_counts()\n",
+ "legendary_pokemon_counts\n",
"\n"
]
},
@@ -87,12 +250,70 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " mean | \n",
+ " std | \n",
+ "
\n",
+ " \n",
+ " | Legendary | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | False | \n",
+ " 417.213605 | \n",
+ " 106.760417 | \n",
+ "
\n",
+ " \n",
+ " | True | \n",
+ " 637.384615 | \n",
+ " 60.937389 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " mean std\n",
+ "Legendary \n",
+ "False 417.213605 106.760417\n",
+ "True 637.384615 60.937389"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "grouped_stats = pokemon.groupby('Legendary')['Total'].agg(['mean', 'std'])\n",
+ "grouped_stats\n"
]
},
{
@@ -106,12 +327,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "T-statistic: 25.8335743895517\n",
+ "P-value: 9.357954335957446e-47\n"
+ ]
+ }
+ ],
+ "source": [
+ "from scipy.stats import ttest_ind\n",
+ "\n",
+ "legendary_points = pokemon[pokemon['Legendary'] == True]['Total'].dropna()\n",
+ "non_legendary_points = pokemon[pokemon['Legendary'] == False]['Total'].dropna()\n",
+ "\n",
+ "t_stat, p_value = ttest_ind(legendary_points, non_legendary_points, equal_var=False)\n",
+ "\n",
+ "print(\"T-statistic:\", t_stat)\n",
+ "print(\"P-value:\", p_value)"
]
},
{
@@ -128,7 +365,7 @@
"outputs": [],
"source": [
"# Your conclusions here:\n",
- "\n"
+ "# As the p value is way smaller that the aplha of 0.05 and the t is very high, we have enough evidence to say that there is a significant difference between these two groups.\n"
]
},
{
@@ -140,12 +377,43 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 24,
+ "metadata": {},
+ "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",
+ "Electric 44\n",
+ "Rock 44\n",
+ "Dragon 32\n",
+ "Ground 32\n",
+ "Ghost 32\n",
+ "Dark 31\n",
+ "Poison 28\n",
+ "Steel 27\n",
+ "Fighting 27\n",
+ "Ice 24\n",
+ "Fairy 17\n",
+ "Flying 4\n",
+ "Name: count, dtype: int64"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "pokemon_type1_counts = pokemon[\"Type 1\"].value_counts()\n",
+ "pokemon_type1_counts\n"
]
},
{
@@ -157,12 +425,32 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 27,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mean 430.455357\n",
+ "std 113.188266\n",
+ "Name: Total, dtype: float64\n",
+ "mean 435.859012\n",
+ "std 121.091682\n",
+ "Name: Total, dtype: float64\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "water_pokemon = pokemon[pokemon['Type 1'] == 'Water']['Total']\n",
+ "non_water_pokemon = pokemon[pokemon['Type 1'] != 'Water']['Total']\n",
+ "\n",
+ "water_pokemon_stats = water_pokemon.agg(['mean', 'std'])\n",
+ "print(water_pokemon_stats)\n",
+ "\n",
+ "non_water_pokemon_stats = non_water_pokemon.agg(['mean', 'std'])\n",
+ "print(non_water_pokemon_stats)\n"
]
},
{
@@ -174,11 +462,27 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 33,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "T-statistic: -0.4638681676327303\n",
+ "P-value: 0.6433915385821449\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
+ "# H0 = No significant difference between water and non-water pokemon.\n",
+ "# H1 = Significant difference between water and non-water pokemon.\n",
+ "\n",
+ "t_stat, p_value = ttest_ind(water_pokemon, non_water_pokemon, equal_var=False)\n",
+ "print(\"T-statistic:\", t_stat)\n",
+ "print(\"P-value:\", p_value)\n",
+ "\n",
"\n"
]
},
@@ -191,11 +495,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 34,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Fail to Reject the Null Hypothesis: No significant difference between water and non-water pokemon.\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
+ "alpha = 0.05\n",
+ "\n",
+ "# decision making\n",
+ "if p_value > alpha:\n",
+ " print(\"Fail to Reject the Null Hypothesis: No significant difference between water and non-water pokemon.\")\n",
+ "else:\n",
+ " print(\"Reject the Null Hypothesis: There is a significant difference between water and non-water pokemon.\")\n",
"\n"
]
},
@@ -212,9 +531,26 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Paired T-statistic: 4.325566393330478\n",
+ "P-value: 1.7140303479358558e-05\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
+ "from scipy.stats import ttest_rel\n",
+ "\n",
+ "t_stat, p_value = ttest_rel(pokemon['Attack'], pokemon['Defense'])\n",
+ "\n",
+ "print(\"Paired T-statistic:\", t_stat)\n",
+ "print(\"P-value:\", p_value)\n",
+ "\n",
+ "\n",
"\n"
]
},
@@ -227,12 +563,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 39,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Reject the Null Hypothesis: There is a significant difference between each pokemons defense and attack score..\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
- "\n"
+ "alpha = 0.05\n",
+ "\n",
+ "# decision making\n",
+ "if p_value > alpha:\n",
+ " print(\"Fail to Reject the Null Hypothesis: No significant difference between each pokemons defense and attack score.\")\n",
+ "else:\n",
+ " print(\"Reject the Null Hypothesis: There is a significant difference between each pokemons defense and attack score..\")\n"
]
},
{
@@ -244,12 +594,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 40,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Paired T-statistic: 0.853986188453353\n",
+ "P-value: 0.3933685997548122\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- "\n"
+ "t_stat, p_value = ttest_rel(pokemon['Sp. Atk'], pokemon['Sp. Def'])\n",
+ "\n",
+ "print(\"Paired T-statistic:\", t_stat)\n",
+ "print(\"P-value:\", p_value)\n"
]
},
{
@@ -261,11 +623,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 41,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Fail to Reject the Null Hypothesis: No significant difference between each pokemons special defense and special attack score.\n"
+ ]
+ }
+ ],
"source": [
"# Your conclusions here:\n",
+ "alpha = 0.05\n",
+ "\n",
+ "# decision making\n",
+ "if p_value > alpha:\n",
+ " print(\"Fail to Reject the Null Hypothesis: No significant difference between each pokemons special defense and special attack score.\")\n",
+ "else:\n",
+ " print(\"Reject the Null Hypothesis: There is a significant difference between each pokemons special defense and special attack score..\")\n",
"\n"
]
},
@@ -280,13 +657,37 @@
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 45,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "One-sample T-statistic: -4.325566393330478\n",
+ "P-value: 1.7140303479358558e-05\n",
+ "Reject the Null Hypothesis: There is a significant difference between each pokemons defense and attack score..\n"
+ ]
+ }
+ ],
"source": [
"# Your code here:\n",
- " \n",
- " "
+ "from scipy.stats import ttest_1samp\n",
+ "\n",
+ "differences = pokemon['Defense'] - pokemon['Attack']\n",
+ "\n",
+ "t_stat, p_value = ttest_1samp(differences, 0)\n",
+ "\n",
+ "print(\"One-sample T-statistic:\", t_stat)\n",
+ "print(\"P-value:\", p_value)\n",
+ "\n",
+ "alpha = 0.05\n",
+ "\n",
+ "# decision making\n",
+ "if p_value > alpha:\n",
+ " print(\"Fail to Reject the Null Hypothesis: No significant difference between each pokemons defense and attack score.\")\n",
+ "else:\n",
+ " print(\"Reject the Null Hypothesis: There is a significant difference between each pokemons defense and attack score..\")"
]
},
{
@@ -354,7 +755,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "base",
"language": "python",
"name": "python3"
},
@@ -368,7 +769,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.12.7"
}
},
"nbformat": 4,