diff --git a/your-code/main.ipynb b/your-code/main.ipynb index cdc1acb..fbe7fb3 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -14,12 +14,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "# import numpy and pandas\n", - "\n" + "import numpy as np\n", + "import pandas as pd\n", + "import scipy.stats as st" ] }, { @@ -35,12 +37,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Run this code:\n", - "\n", "pokemon = pd.read_csv('../pokemon.csv')" ] }, @@ -53,12 +54,154 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
01BulbasaurGrassPoison3184549496565451False
12IvysaurGrassPoison4056062638080601False
23VenusaurGrassPoison525808283100100801False
33VenusaurMega VenusaurGrassPoison62580100123122120801False
44CharmanderFireNaN3093952436050651False
\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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "pokemon.head()" ] }, { @@ -70,12 +213,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of legendary and non legendary Pokemons:\n", + " Legendary count\n", + "0 False 735\n", + "1 True 65\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "print(\"Number of legendary and non legendary Pokemons:\\n\", pokemon['Legendary'].value_counts().reset_index())" ] }, { @@ -87,12 +241,69 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
meanstd
Legendary
False417.213605106.760417
True637.38461560.937389
\n", + "
" + ], + "text/plain": [ + " mean std\n", + "Legendary \n", + "False 417.213605 106.760417\n", + "True 637.384615 60.937389" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "pokemon.groupby('Legendary')['Total'].agg(['mean','std'])" ] }, { @@ -106,12 +317,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): 25.83\n", + "P-Value: 0.0000\n", + "\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "legendary_stats = pokemon[pokemon['Legendary'] == True][\"Total\"].dropna()\n", + "non_legendary_stats = pokemon[pokemon['Legendary'] == False][\"Total\"].dropna()\n", + "\n", + "t_stat, p_value = st.ttest_ind(legendary_stats, non_legendary_stats, equal_var=False)\n", + "print(f\"Test Statistic (t): {t_stat:.2f}\")\n", + "print(f\"P-Value: {p_value:.4f}\")\n", + "print()\n", + "\n", + "# Significance level\n", + "alpha = 0.05" ] }, { @@ -123,12 +353,24 @@ }, { "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 sufficient evidence to conclude that the mean stats are different for legendary and non legendary pokemons\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "\n", + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: The mean stats for legendary and non legendary pokemons are not significantly different.\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is sufficient evidence to conclude that the mean stats are different for legendary and non legendary pokemons\")" ] }, { @@ -140,12 +382,42 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 41, + "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": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "pokemon['Type 1'].value_counts()" ] }, { @@ -157,12 +429,166 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
meanstd
Type 1
Bug378.927536117.875223
Dark445.741935109.126217
Dragon550.531250146.267538
Electric443.409091105.721952
Fairy413.176471123.781680
Fighting416.444444102.464378
Fire458.076923109.760496
Flying485.000000161.400124
Ghost439.562500110.072685
Grass421.142857106.650626
Ground437.500000123.913081
Ice433.458333108.281027
Normal401.683673115.733038
Poison399.14285792.358687
Psychic475.947368139.026645
Rock453.750000108.059227
Steel487.703704115.420907
Water430.455357113.188266
\n", + "
" + ], + "text/plain": [ + " mean std\n", + "Type 1 \n", + "Bug 378.927536 117.875223\n", + "Dark 445.741935 109.126217\n", + "Dragon 550.531250 146.267538\n", + "Electric 443.409091 105.721952\n", + "Fairy 413.176471 123.781680\n", + "Fighting 416.444444 102.464378\n", + "Fire 458.076923 109.760496\n", + "Flying 485.000000 161.400124\n", + "Ghost 439.562500 110.072685\n", + "Grass 421.142857 106.650626\n", + "Ground 437.500000 123.913081\n", + "Ice 433.458333 108.281027\n", + "Normal 401.683673 115.733038\n", + "Poison 399.142857 92.358687\n", + "Psychic 475.947368 139.026645\n", + "Rock 453.750000 108.059227\n", + "Steel 487.703704 115.420907\n", + "Water 430.455357 113.188266" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "pokemon.groupby('Type 1')['Total'].agg(['mean','std'])" ] }, { @@ -174,12 +600,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): -0.44\n", + "P-Value: 0.6587\n", + "\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "water_stats = pokemon[pokemon['Type 1'] == 'Water'][\"Total\"].dropna()\n", + "non_water_stats = pokemon[pokemon['Type 1'] != 'Water'][\"Total\"].dropna()\n", + "\n", + "t_stat, p_value = st.ttest_ind(water_stats, non_water_stats, equal_var=True)\n", + "print(f\"Test Statistic (t): {t_stat:.2f}\")\n", + "print(f\"P-Value: {p_value:.4f}\")\n", + "print()\n", + "\n", + "# Significance level\n", + "alpha = 0.05" ] }, { @@ -191,12 +636,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fail to Reject the Null Hypothesis: The mean stats for water and non water pokemons are not significantly different.\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "\n", + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: The mean stats for water and non water pokemons are not significantly different.\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is sufficient evidence to conclude that the mean stats are different for water and non water pokemons\")" ] }, { @@ -210,12 +667,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here:\n", - "\n" + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): 4.33\n", + "P-Value: 0.00001714030347935855799128106180528874347146484070\n", + "\n" + ] + } + ], + "source": [ + "# Perform paired t-test\n", + "t_stat, p_value = st.ttest_rel(pokemon['Attack'], pokemon['Defense'])\n", + "print(f\"Test Statistic (t): {t_stat:.2f}\")\n", + "print(f\"P-Value: {p_value:.50f}\")\n", + "print()\n", + "\n", + "# Significance level\n", + "alpha = 0.05" ] }, { @@ -227,12 +700,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Reject the Null Hypothesis: There is a significant change in blood pressure after treatment.\n" + ] + } + ], "source": [ - "# Your conclusions here:\n", - "\n" + "# Decision-Making\n", + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: No significant difference between attack and defense\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is a significant difference between attack and defense\")" ] }, { @@ -244,12 +728,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): 0.60\n", + "P-Value: 0.5458\n", + "\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "t_stat, p_value = st.ttest_ind(pokemon[\"Sp. Atk\"].dropna(), pokemon[\"Sp. Def\"].dropna())\n", + "print(f\"Test Statistic (t): {t_stat:.2f}\")\n", + "print(f\"P-Value: {p_value:.4f}\")\n", + "print()\n", + "\n", + "# Significance level\n", + "alpha = 0.05" ] }, { @@ -261,12 +761,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 103, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fail to Reject the Null Hypothesis: The mean sp.def and sp.atk of pokemons are not significantly different.\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "\n", + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: The mean sp.def and sp.atk of pokemons are not significantly different.\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is sufficient evidence to conclude that the mean sp.def and sp.atk of pokemons are different\")" ] }, { @@ -280,13 +792,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here:\n", - " \n", - " " + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): 4.33\n", + "P-Value: 0.0000\n", + "\n", + "Reject the Null Hypothesis: There is evidence to say the attack is different from defense.\n" + ] + } + ], + "source": [ + "pokemon['Difference'] = pokemon[\"Attack\"] - pokemon[\"Defense\"]\n", + "\n", + "t_stat, p_value = st.ttest_1samp(pokemon['Difference'].dropna(), 0)\n", + "print(f\"Test Statistic (t): {t_stat:.2f}\")\n", + "print(f\"P-Value: {p_value:.4f}\")\n", + "print()\n", + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: Not enough evidence to say the attack is different from defense.\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is evidence to say the attack is different from defense.\")" ] }, { @@ -302,12 +832,70 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Water TypeFalseTrue
Legendary
False627108
True614
\n", + "
" + ], + "text/plain": [ + "Water Type False True \n", + "Legendary \n", + "False 627 108\n", + "True 61 4" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "contingency_table = pd.crosstab(pokemon['Legendary'],pokemon['Type 1'].apply(lambda x: x == 'Water'), colnames=['Water Type'])\n", + "contingency_table" ] }, { @@ -319,12 +907,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chi-squared Statistic: 2.9429200762850503\n", + "p-value: 0.08625467249550949\n", + "Degrees of Freedom: 1\n", + "Expected Frequencies:\n", + " [[632.1 102.9]\n", + " [ 55.9 9.1]]\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "chi2, p, dof, expected = st.chi2_contingency(contingency_table)\n", + "\n", + "# Print results\n", + "print(\"Chi-squared Statistic:\", chi2)\n", + "print(\"p-value:\", p)\n", + "print(\"Degrees of Freedom:\", dof)\n", + "print(\"Expected Frequencies:\\n\", expected)" ] }, { @@ -336,12 +943,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Fail to Reject the Null Hypothesis: Not enough evidence to say that are significant difference in frequencies.\n" + ] + } + ], "source": [ "# Your answer here:\n", - "\n" + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: Not enough evidence to say that are significant difference in frequencies.\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is evidence to say that are significant difference in frequencies.\")" ] }, { @@ -354,7 +972,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -368,9 +986,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.12.4" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }