diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb
index c1bb43d..f92f7b7 100755
--- a/your-code/challenge-1.ipynb
+++ b/your-code/challenge-1.ipynb
@@ -19,7 +19,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -38,11 +38,265 @@
},
{
"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",
+ " ... | \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": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here:\n"
+ "pokemon_df = pd.read_csv(\"Pokemon.csv\")\n",
+ "pokemon_df"
]
},
{
@@ -58,7 +312,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
@@ -75,7 +329,10 @@
" \"\"\"\n",
" results = {}\n",
"\n",
- " # Your code here\n",
+ " for feature in features:\n",
+ " t_stat, p_value = ttest_ind(s1[feature], s2[feature], equal_var=False)\n",
+ " \n",
+ " results[feature] = p_value\n",
" \n",
" return results"
]
@@ -101,11 +358,36 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 20,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 1.0026911708035284e-13,\n",
+ " 'Attack': 2.520372449236646e-16,\n",
+ " 'Defense': 4.8269984949193316e-11,\n",
+ " 'Sp. Atk': 1.5514614112239812e-21,\n",
+ " 'Sp. Def': 2.2949327864052826e-15,\n",
+ " 'Speed': 1.049016311882451e-18,\n",
+ " 'Total': 9.357954335957446e-47}"
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "from scipy.stats import ttest_ind\n",
+ "\n",
+ "legendary = pokemon_df[pokemon_df['Legendary'] == True]\n",
+ "non_legendary = pokemon_df[pokemon_df['Legendary'] == False]\n",
+ "\n",
+ "\n",
+ "legendary_vs_non = t_test_features(legendary, non_legendary, features=['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total'])\n",
+ "\n",
+ "legendary_vs_non\n"
]
},
{
@@ -117,11 +399,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "#They should be very different as the p-value is very small"
]
},
{
@@ -133,11 +415,34 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 0.14551697834219623,\n",
+ " 'Attack': 0.24721958967217725,\n",
+ " 'Defense': 0.5677711011725426,\n",
+ " 'Sp. Atk': 0.12332165977104388,\n",
+ " 'Sp. Def': 0.18829872292645752,\n",
+ " 'Speed': 0.00239265937312135,\n",
+ " 'Total': 0.5631377907941676}"
+ ]
+ },
+ "execution_count": 22,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "g1 = pokemon_df[pokemon_df['Generation'] == 1]\n",
+ "g2 = pokemon_df[pokemon_df['Generation'] == 2]\n",
+ "\n",
+ "\n",
+ "g1_vs_g2 = t_test_features(g1, g2, features=['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total'])\n",
+ "\n",
+ "g1_vs_g2\n"
]
},
{
@@ -153,7 +458,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "#Not taking \"speed\" in consideration, we cannot reject that they are similar"
]
},
{
@@ -165,11 +470,33 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 25,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 0.11314389855379414,\n",
+ " 'Attack': 0.00014932578145948305,\n",
+ " 'Defense': 2.7978540411514693e-08,\n",
+ " 'Sp. Atk': 0.00013876216585667907,\n",
+ " 'Sp. Def': 0.00010730610934512779,\n",
+ " 'Speed': 0.02421703281819093,\n",
+ " 'Total': 1.1157056505229961e-07}"
+ ]
+ },
+ "execution_count": 25,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "type1 = pokemon_df[pokemon_df['Type 2'].isnull()]\n",
+ "type2 = pokemon_df[~pokemon_df['Type 2'].isnull()]\n",
+ "\n",
+ "t1_vs_t2 = t_test_features(type1, type2, features=['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total'])\n",
+ "\n",
+ "t1_vs_t2"
]
},
{
@@ -185,7 +512,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "#They are not very similar"
]
},
{
@@ -199,11 +526,32 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 27,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "T-test results for Attack vs Defense:\n",
+ "T-statistic: 4.325566393330478, p-value: 1.7140303479358558e-05\n",
+ "\n",
+ "T-test results for Sp. Atk vs Sp. Def:\n",
+ "T-statistic: 0.853986188453353, p-value: 0.3933685997548122\n"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "from scipy.stats import ttest_rel\n",
+ "\n",
+ "t_stat_attack_defense, p_value_attack_defense = ttest_rel(pokemon_df['Attack'], pokemon_df['Defense'])\n",
+ "t_stat_sp_atk_sp_def, p_value_sp_atk_sp_def = ttest_rel(pokemon_df['Sp. Atk'], pokemon_df['Sp. Def'])\n",
+ "\n",
+ "print(f\"T-test results for Attack vs Defense:\")\n",
+ "print(f\"T-statistic: {t_stat_attack_defense}, p-value: {p_value_attack_defense}\")\n",
+ "\n",
+ "print(f\"\\nT-test results for Sp. Atk vs Sp. Def:\")\n",
+ "print(f\"T-statistic: {t_stat_sp_atk_sp_def}, p-value: {p_value_sp_atk_sp_def}\")\n"
]
},
{
@@ -219,7 +567,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "#There is a considerable difference between Attack and Defense, but not that much of a difference between Sp. Atk and Sp. Def"
]
}
],
diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb
index 1f0e335..26702fc 100755
--- a/your-code/challenge-2.ipynb
+++ b/your-code/challenge-2.ipynb
@@ -17,7 +17,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -27,11 +27,154 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"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": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Load the data:\n"
+ "pokemon_df = pd.read_csv('Pokemon.csv')\n",
+ "pokemon_df.head()\n"
]
},
{
@@ -58,11 +201,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "19"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n",
+ "unique_types = pd.unique(pokemon_df[['Type 1', 'Type 2']].values.ravel())\n",
"\n",
"\n",
"len(unique_types) # you should see 19"
@@ -85,13 +239,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "18"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"pokemon_totals = []\n",
"\n",
- "# Your code here\n",
+ "for type in unique_types:\n",
+ " if isinstance(type, str):\n",
+ " pokemon_totals.append(pokemon_df[(pokemon_df['Type 1'] == type) | (pokemon_df['Type 2'] == type)]['Total'])\n",
"\n",
"len(pokemon_totals) # you should see 18"
]
@@ -111,11 +278,25 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ANOVA F-statistic: 6.617538296005533\n",
+ "ANOVA p-value: 2.6457458815984803e-15\n"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "from scipy.stats import f_oneway\n",
+ "\n",
+ "anova = f_oneway(*pokemon_totals)\n",
+ "\n",
+ "print(\"ANOVA F-statistic:\", anova.statistic)\n",
+ "print(\"ANOVA p-value:\", anova.pvalue)"
]
},
{
@@ -131,7 +312,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "#They should be significantly different"
]
}
],
@@ -151,7 +332,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.11.4"
}
},
"nbformat": 4,