diff --git a/your-code/main.ipynb b/your-code/main.ipynb index cdc1acb..26f42e6 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -14,12 +14,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# import numpy and pandas\n", - "\n" + "import numpy as np\n", + "import pandas as pd" ] }, { @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -53,12 +53,154 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "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": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "pokemon.head(5)" ] }, { @@ -70,12 +212,79 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(# Name Type 1 Type 2 Total HP Attack Defense Sp. Atk Sp. Def Speed Generation Legendary\n", + " 144 Articuno Ice Flying 580 90 85 100 95 125 85 1 True 1\n", + " 145 Zapdos Electric Flying 580 90 90 85 125 90 100 1 True 1\n", + " 639 Terrakion Rock Fighting 580 91 129 90 72 90 108 5 True 1\n", + " 640 Virizion Grass Fighting 580 91 90 72 90 129 108 5 True 1\n", + " 642 ThundurusIncarnate Forme Electric Flying 580 79 115 70 125 80 111 5 True 1\n", + " ThundurusTherian Forme Electric Flying 580 79 105 70 145 80 101 5 True 1\n", + " 643 Reshiram Dragon Fire 680 100 120 100 150 120 90 5 True 1\n", + " 644 Zekrom Dragon Electric 680 100 150 120 120 100 90 5 True 1\n", + " 645 LandorusIncarnate Forme Ground Flying 600 89 125 90 115 80 101 5 True 1\n", + " LandorusTherian Forme Ground Flying 600 89 145 90 105 80 91 5 True 1\n", + " 646 Kyurem Dragon Ice 660 125 130 90 130 90 95 5 True 1\n", + " KyuremBlack Kyurem Dragon Ice 700 125 170 100 120 90 95 5 True 1\n", + " KyuremWhite Kyurem Dragon Ice 700 125 120 90 170 100 95 5 True 1\n", + " 717 Yveltal Dark Flying 680 126 131 95 131 98 99 6 True 1\n", + " 718 Zygarde50% Forme Dragon Ground 600 108 100 121 81 95 95 6 True 1\n", + " 719 Diancie Rock Fairy 600 50 100 150 100 150 50 6 True 1\n", + " DiancieMega Diancie Rock Fairy 700 50 160 110 160 110 110 6 True 1\n", + " 720 HoopaHoopa Confined Psychic Ghost 600 80 110 60 150 130 70 6 True 1\n", + " HoopaHoopa Unbound Psychic Dark 680 80 160 60 170 130 80 6 True 1\n", + " 638 Cobalion Steel Fighting 580 91 90 129 90 72 108 5 True 1\n", + " 494 Victini Psychic Fire 600 100 100 100 100 100 100 5 True 1\n", + " 492 ShayminSky Forme Grass Flying 600 100 103 75 120 75 127 4 True 1\n", + " 381 LatiosMega Latios Dragon Psychic 700 80 130 100 160 120 110 3 True 1\n", + " 146 Moltres Fire Flying 580 90 100 90 125 85 90 1 True 1\n", + " 150 MewtwoMega Mewtwo X Psychic Fighting 780 106 190 100 154 100 130 1 True 1\n", + " 249 Lugia Psychic Flying 680 106 90 130 90 154 110 2 True 1\n", + " 250 Ho-oh Fire Flying 680 106 130 90 110 154 90 2 True 1\n", + " 380 Latias Dragon Psychic 600 80 80 90 110 130 110 3 True 1\n", + " LatiasMega Latias Dragon Psychic 700 80 100 120 140 150 110 3 True 1\n", + " 381 Latios Dragon Psychic 600 80 90 80 130 110 110 3 True 1\n", + " 383 GroudonPrimal Groudon Ground Fire 770 100 180 160 150 90 90 3 True 1\n", + " 487 GiratinaOrigin Forme Ghost Dragon 680 150 120 100 120 100 90 4 True 1\n", + " 384 Rayquaza Dragon Flying 680 105 150 90 150 90 95 3 True 1\n", + " RayquazaMega Rayquaza Dragon Flying 780 105 180 100 180 100 115 3 True 1\n", + " 385 Jirachi Steel Psychic 600 100 100 100 100 100 100 3 True 1\n", + " 483 Dialga Steel Dragon 680 100 120 120 150 100 90 4 True 1\n", + " 484 Palkia Water Dragon 680 90 120 100 150 120 100 4 True 1\n", + " 485 Heatran Fire Steel 600 91 90 106 130 106 77 4 True 1\n", + " 487 GiratinaAltered Forme Ghost Dragon 680 150 100 120 100 120 90 4 True 1\n", + " 721 Volcanion Fire Water 600 80 110 120 130 90 70 6 True 1\n", + " Name: count, dtype: int64,\n", + " # Name Type 1 Type 2 Total HP Attack Defense Sp. Atk Sp. Def Speed Generation Legendary\n", + " 1 Bulbasaur Grass Poison 318 45 49 49 65 65 45 1 False 1\n", + " 462 Magnezone Electric Steel 535 70 70 115 130 90 60 4 False 1\n", + " 478 Froslass Ice Ghost 480 70 80 70 80 70 110 4 False 1\n", + " 476 Probopass Rock Steel 525 60 55 145 75 150 40 4 False 1\n", + " 475 GalladeMega Gallade Psychic Fighting 618 68 165 95 65 115 110 4 False 1\n", + " ..\n", + " 246 Larvitar Rock Ground 300 50 64 50 45 50 41 2 False 1\n", + " 238 Smoochum Ice Psychic 305 45 30 15 85 65 65 2 False 1\n", + " 230 Kingdra Water Dragon 540 75 95 95 95 95 85 2 False 1\n", + " 229 HoundoomMega Houndoom Dark Fire 600 75 90 90 140 90 115 2 False 1\n", + " 715 Noivern Flying Dragon 535 85 70 80 97 80 123 6 False 1\n", + " Name: count, Length: 374, dtype: int64)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "legendary_pok = pokemon[pokemon[\"Legendary\"] == True].value_counts()\n", + "non_legendary_pok = pokemon[pokemon[\"Legendary\"] == False].value_counts()\n", + "legendary_pok, non_legendary_pok\n" ] }, { @@ -87,12 +296,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(417.21360544217686, 106.7604174571302)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mean_non_legendary = pokemon[pokemon[\"Legendary\"]== False][\"Total\"].mean()\n", + "std_non_legendary = pokemon[pokemon[\"Legendary\"]== False][\"Total\"].std()\n", + "mean_non_legendary, std_non_legendary" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(637.3846153846154, 60.93738905315346)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "mean_legendary = pokemon[pokemon[\"Legendary\"] == True][\"Total\"].mean()\n", + "std_legendary = pokemon[pokemon[\"Legendary\"] == True][\"Total\"].std()\n", + "mean_legendary, std_legendary\n" ] }, { @@ -106,11 +350,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "TtestResult(statistic=16.386116965872425, pvalue=3.0952457469652825e-52, df=798.0)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", + "import scipy.stats as stats\n", + "ttest_ind = pokemon[pokemon[\"Legendary\"] == True][\"Total\"],pokemon[pokemon[\"Legendary\"]== False][\"Total\"]\n", + "stats.ttest_ind(*ttest_ind)\n", "\n" ] }, @@ -123,12 +381,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' \\nNull Hyphotesis : The difference between two groups are statistically not significant.\\nAlternative Hyphotesis : The difference between two groups are statistically significant.\\n\\nFrom comparing the means we understood that legendary pokemons have a higher total points than non-legendary pokemons.\\nthe p-value is less than 0.05, so we can reject the null hypothesis and conclude that the difference between the means is statistically significant.'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "''' \n", + "Null Hyphotesis : The difference between two groups are statistically not significant.\n", + "Alternative Hyphotesis : The difference between two groups are statistically significant.\n", + "\n", + "From comparing the means we understood that legendary pokemons have a higher total points than non-legendary pokemons.\n", + "the p-value is less than 0.05, so we can reject the null hypothesis and conclude that the difference between the means is statistically significant.'''\n" ] }, { @@ -140,12 +414,43 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "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": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "Type1_pok = pokemon[\"Type 1\"].value_counts()\n", + "Type1_pok\n" ] }, { @@ -157,12 +462,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(430.45535714285717,\n", + " 113.18826606431458,\n", + " 435.85901162790697,\n", + " 121.09168230208063)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "mean_water = pokemon[pokemon[\"Type 1\"] == \"Water\"][\"Total\"].mean()\n", + "std_water = pokemon[pokemon[\"Type 1\"] == \"Water\"][\"Total\"].std()\n", + "mean_rest = pokemon[pokemon[\"Type 1\"] != \"Water\"][\"Total\"].mean()\n", + "std_rest = pokemon[pokemon[\"Type 1\"] != \"Water\"][\"Total\"].std()\n", + "mean_water, std_water, mean_rest, std_rest\n" ] }, { @@ -174,12 +497,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here:\n", - "\n" + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): -0.44\n", + "P-Value: 0.65871403174887932507886034727562218904495239257812\n", + "\n", + "Fail to Reject the Null Hypothesis: No significant difference total points between water and the rest.\n" + ] + } + ], + "source": [ + "import scipy.stats as stats\n", + "\n", + "# Null hypothesis: Water pokemons and non-water pokemons have significantly same total points.\n", + "# Alternative hypothesis: Water pokemons and non-water pokemons have significantly different total points.\n", + "\n", + "t_stat, p_value = stats.ttest_ind(pokemon[pokemon[\"Type 1\"] == \"Water\"][\"Total\"], pokemon[pokemon[\"Type 1\"] != \"Water\"][\"Total\"], equal_var=True)\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\n", + "\n", + "# Decision-Making\n", + "if p_value > alpha:\n", + " print(\"Fail to Reject the Null Hypothesis: No significant difference total points between water and the rest.\")\n", + "else:\n", + " print(\"Reject the Null Hypothesis: There is a significant difference total points between the water and the rest.\")\n" ] }, { @@ -191,7 +541,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -210,12 +560,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): -4.3256 P-Value: 0.0000171403\n", + "Reject the null hypothesis: There is a significant difference between the defence and attack scores of pokemons.\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "# null hypothesis: There is no significant difference between the defence and attack scores of pokemons.\n", + "# alternative hypothesis: There is a significant difference between the defence and attack scores of pokemons.\n", + "\n", + "\n", + "t_stat, p_value = stats.ttest_rel(pokemon[\"Defense\"], pokemon[\"Attack\"])\n", + "print(f\"Test Statistic (t): {t_stat:.4f}\", f\"P-Value: {p_value:.10f}\")\n", + "if p_value > 0.05:\n", + " print(\"Fail to reject the null hypothesis: There is no significant difference between the defence and attack scores of pokemons.\")\n", + "else: \n", + " print(\"Reject the null hypothesis: There is a significant difference between the defence and attack scores of pokemons.\")" ] }, { @@ -230,6 +598,13 @@ "execution_count": null, "metadata": {}, "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], "source": [ "# Your conclusions here:\n", "\n" @@ -244,12 +619,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test Statistic (t): -0.8540 P-Value: 0.3933685998\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "mean_spdefensescores = pokemon[\"Sp. Def\"].mean()\n", + "std_spdefensescores = pokemon[\"Sp. Def\"].std()\n", + "mean_spattackscores = pokemon[\"Sp. Atk\"].mean()\n", + "std_spattackscores = pokemon[\"Sp. Atk\"].std()\n", + "mean_spdefensescores, std_spdefensescores, mean_spattackscores, std_spattackscores\n", + "\n", + "t_stat, p_value = stats.ttest_rel(pokemon[\"Sp. Def\"], pokemon[\"Sp. Atk\"])\n", + "print(f\"Test Statistic (t): {t_stat:.4f}\", f\"P-Value: {p_value:.10f}\")" ] }, { @@ -266,7 +656,9 @@ "outputs": [], "source": [ "# Your conclusions here:\n", - "\n" + "''' Means of Special attacks and Special defenses are close to each other. \n", + "As in T-test my result is very close to the 0 that means there is no significant difference between the Special Attack and Special Defense scores of pokemons.\n", + "Besides my p-value is greater than 0.05, so I fail to reject the null hypothesis. '''" ] }, { @@ -280,12 +672,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "TtestResult(statistic=-4.325566393330478, pvalue=1.7140303479358558e-05, df=799)" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - " \n", + "diff = pokemon[\"Defense\"] - pokemon[\"Attack\"]\n", + "ttest_1sample = stats.ttest_1samp(diff, 0)\n", + "ttest_1sample \n", " " ] }, @@ -302,7 +707,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -319,7 +724,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -336,7 +741,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -354,7 +759,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -368,7 +773,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.12.4" } }, "nbformat": 4,