diff --git a/Image20250607120457.jpg b/Image20250607120457.jpg new file mode 100644 index 0000000..a2f0fe9 Binary files /dev/null and b/Image20250607120457.jpg differ diff --git a/Image20250607120510.jpg b/Image20250607120510.jpg new file mode 100644 index 0000000..52b250d Binary files /dev/null and b/Image20250607120510.jpg differ diff --git a/lab-hypothesis-testing.ipynb b/lab-hypothesis-testing.ipynb index 0cc26d5..f49e3bb 100644 --- a/lab-hypothesis-testing.ipynb +++ b/lab-hypothesis-testing.ipynb @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -278,7 +278,7 @@ "[800 rows x 11 columns]" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -297,11 +297,39 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T-statistic: 4.4991348531252635\n", + "P-value: 7.0097137393088205e-06\n", + "Reject the null hypothesis: Dragon-type Pokémon have significantly higher average HP than Grass-type Pokémon.\n" + ] + } + ], "source": [ - "#code here" + "# MOD: considerar Type 1 y Type 2 para Dragon/Grass (pequeña mejora)\n", + "dragon_mask = (df['Type 1'] == 'Dragon') | ((\"Type 2\" in df.columns) & (df['Type 2'] == 'Dragon'))\n", + "grass_mask = (df['Type 1'] == 'Grass') | ((\"Type 2\" in df.columns) & (df['Type 2'] == 'Grass'))\n", + "dragon_hp = df.loc[dragon_mask, 'HP'].dropna()\n", + "grass_hp = df.loc[grass_mask, 'HP'].dropna()\n", + "# Filter HP values for Dragon and Grass types\n", + "\n", + "# Perform a one-tailed t-test\n", + "t_stat, p_value = st.ttest_ind(dragon_hp, grass_hp, alternative='greater')\n", + "\n", + "# Print the results\n", + "print(f\"T-statistic: {t_stat}\")\n", + "print(f\"P-value: {p_value}\")\n", + "\n", + "# Conclusion\n", + "if p_value < 0.05:\n", + " print(\"Reject the null hypothesis: Dragon-type Pokémon have significantly higher average HP than Grass-type Pokémon.\")\n", + "else:\n", + " print(\"Fail to reject the null hypothesis: No significant difference in average HP between Dragon and Grass types.\")" ] }, { @@ -313,11 +341,139 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HP: t-statistic = 8.98, p-value = 0.0000\n", + " -> Significant difference in HP between Legendary and Non-Legendary Pokémon.\n", + "Attack: t-statistic = 10.44, p-value = 0.0000\n", + " -> Significant difference in Attack between Legendary and Non-Legendary Pokémon.\n", + "Defense: t-statistic = 7.64, p-value = 0.0000\n", + " -> Significant difference in Defense between Legendary and Non-Legendary Pokémon.\n", + "Sp. Atk: t-statistic = 13.42, p-value = 0.0000\n", + " -> Significant difference in Sp. Atk between Legendary and Non-Legendary Pokémon.\n", + "Sp. Def: t-statistic = 10.02, p-value = 0.0000\n", + " -> Significant difference in Sp. Def between Legendary and Non-Legendary Pokémon.\n", + "Speed: t-statistic = 11.48, p-value = 0.0000\n", + " -> Significant difference in Speed between Legendary and Non-Legendary Pokémon.\n" + ] + } + ], "source": [ - "#code here" + "# Separate Legendary and Non-Legendary Pokémon\n", + "legendary = df[df['Legendary'] == True]\n", + "non_legendary = df[df['Legendary'] == False]\n", + "\n", + "# List of stats to compare\n", + "stats = ['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed']\n", + "\n", + "# Perform t-tests for each stat\n", + "results = {}\n", + "for stat in stats:\n", + " t_stat, p_value = st.ttest_ind(legendary[stat], non_legendary[stat], equal_var=False) # Welch's t-test\n", + " results[stat] = {'t_stat': t_stat, 'p_value': p_value}\n", + "\n", + "# Print the results\n", + "for stat, result in results.items():\n", + " print(f\"{stat}: t-statistic = {result['t_stat']:.2f}, p-value = {result['p_value']:.4f}\")\n", + " if result['p_value'] < 0.05:\n", + " print(f\" -> Significant difference in {stat} between Legendary and Non-Legendary Pokémon.\")\n", + " else:\n", + " print(f\" -> No significant difference in {stat} between Legendary and Non-Legendary Pokémon.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Legendary | \n", + "Non-Legendary | \n", + "Legendary | \n", + "
---|---|---|
HP | \n", + "67.182313 | \n", + "92.738462 | \n", + "
Attack | \n", + "75.669388 | \n", + "116.676923 | \n", + "
Defense | \n", + "71.559184 | \n", + "99.661538 | \n", + "
Sp. Atk | \n", + "68.454422 | \n", + "122.184615 | \n", + "
Sp. Def | \n", + "68.892517 | \n", + "105.938462 | \n", + "
Speed | \n", + "65.455782 | \n", + "100.184615 | \n", + "