diff --git a/your-code/main.ipynb b/your-code/main.ipynb index cdc1acb..57e8e65 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" + "import pandas as pd\n", + "import numpy as np\n", + "import scipy.stats as sts" ] }, { @@ -35,7 +37,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -53,12 +55,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(5)" ] }, { @@ -70,12 +214,26 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Legendary\n", + "False 735\n", + "True 65\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "pokemon.Legendary.value_counts()" ] }, { @@ -87,12 +245,47 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Legendary Pokemon : Mean - 637.38, Standard Deviation - 60.94\n", + "Non-Legendary Pokemon : Mean - 417.21, Standard Deviation - 106.76\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "legends = pokemon[pokemon['Legendary'] == True]\n", + "non_legends = pokemon[pokemon['Legendary'] == False]\n", + "\n", + "#Mean and Standard Deviation of Legendary Pokemons\n", + "print(\"Legendary Pokemon : Mean - {}, Standard Deviation - {}\".format(np.round(legends.Total.mean(),2), np.round(legends.Total.std(),2)))\n", + "print(\"Non-Legendary Pokemon : Mean - {}, Standard Deviation - {}\".format(np.round(non_legends.Total.mean(),2), np.round(non_legends.Total.std(),2)))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis : The legendary and non-legendary pokemon has similar avg. values\n", + "\n", + "Alternate Hypothesis : The legendary and non-legendary pokemon doesn't similar avg. values\n" + ] + } + ], + "source": [ + "# Null Hypothesis & Alternate Hypothesis\n", + "print(\"Null Hypothesis : The legendary and non-legendary pokemon has similar avg. values\\n\")\n", + "print(\"Alternate Hypothesis : The legendary and non-legendary pokemon doesn't similar avg. values\")" ] }, { @@ -106,12 +299,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T-Statistic : 25.8335743895517\n", + "P-Value : 9.357954335957446e-47\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "t_stat, p_value = sts.ttest_ind(legends['Total'],non_legends['Total'],equal_var=False,alternative='two-sided')\n", + "print(\"T-Statistic : {}\".format(t_stat))\n", + "print(\"P-Value : {}\".format(p_value))" ] }, { @@ -123,12 +327,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis that the two Pokemon groups have similar avg. values can be rejected with 95% confidence\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "\n", + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that the two Pokemon groups have similar avg. values can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")" ] }, { @@ -140,12 +356,42 @@ }, { "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", + "Rock 44\n", + "Electric 44\n", + "Ground 32\n", + "Ghost 32\n", + "Dragon 32\n", + "Dark 31\n", + "Poison 28\n", + "Fighting 27\n", + "Steel 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['Type 1'].value_counts()" ] }, { @@ -157,12 +403,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Water Pokemon : Mean - 430.46, Standard Deviation - 113.19\n", + "Non-Water Pokemon : Mean - 435.86, Standard Deviation - 121.09\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "water_pk = pokemon[pokemon['Type 1'] == 'Water']\n", + "non_water_pk = pokemon[pokemon['Type 1'] != 'Water']\n", + "\n", + "#Mean and Standard Deviation of Legendary Pokemons\n", + "print(\"Water Pokemon : Mean - {}, Standard Deviation - {}\".format(np.round(water_pk.Total.mean(),2), np.round(water_pk.Total.std(),2)))\n", + "print(\"Non-Water Pokemon : Mean - {}, Standard Deviation - {}\".format(np.round(non_water_pk.Total.mean(),2), np.round(non_water_pk.Total.std(),2)))" ] }, { @@ -174,12 +435,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis : The water and non-water pokemon has similar avg. values\n", + "Alternate Hypothesis : The water and non-water pokemon doesn't similar avg. values\n", + "\n", + "T-Statistic : -0.4418547448849676\n", + "P-Value : 0.6587140317488793\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "# Null Hypothesis & Alternate Hypothesis\n", + "print(\"Null Hypothesis : The water and non-water pokemon has similar avg. values\")\n", + "print(\"Alternate Hypothesis : The water and non-water pokemon doesn't similar avg. values\\n\")\n", + "\n", + "t_stat, p_value = sts.ttest_ind(water_pk['Total'],non_water_pk['Total'],equal_var=True,alternative='two-sided')\n", + "print(\"T-Statistic : {}\".format(t_stat))\n", + "print(\"P-Value : {}\".format(p_value))" ] }, { @@ -191,12 +470,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis cannot be rejected\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "\n", + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that the two Pokemon groups have similar avg. values can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")" ] }, { @@ -210,12 +501,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis : The attack and defense scores of all pokemon are equal\n", + "Alternate Hypothesis : The attack and defense scores of all pokemon are not equal\n", + "\n", + "T-Statistic : 4.325566393330478\n", + "P-Value : 1.7140303479358558e-05\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "print(\"Null Hypothesis : The attack and defense scores of all pokemon are equal\")\n", + "print(\"Alternate Hypothesis : The attack and defense scores of all pokemon are not equal\\n\")\n", + "\n", + "t_stat, p_value = sts.ttest_rel(pokemon['Attack'],pokemon['Defense'],alternative='two-sided')\n", + "print(\"T-Statistic : {}\".format(t_stat))\n", + "print(\"P-Value : {}\".format(p_value))" ] }, { @@ -227,12 +535,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis that attack and defense scores of all pokemon are equal can be rejected with 95% confidence\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that attack and defense scores of all pokemon are equal can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")" ] }, { @@ -244,12 +563,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis : The special attack and special defense scores of all pokemon are equal\n", + "Alternate Hypothesis : The special attack and special defense scores of all pokemon are not equal\n", + "\n", + "T-Statistic : 0.853986188453353\n", + "P-Value : 0.3933685997548122\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "print(\"Null Hypothesis : The special attack and special defense scores of all pokemon are equal\")\n", + "print(\"Alternate Hypothesis : The special attack and special defense scores of all pokemon are not equal\\n\")\n", + "\n", + "t_stat, p_value = sts.ttest_rel(pokemon['Sp. Atk'],pokemon['Sp. Def'],alternative='two-sided')\n", + "print(\"T-Statistic : {}\".format(t_stat))\n", + "print(\"P-Value : {}\".format(p_value))" ] }, { @@ -261,12 +597,23 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis cannot be rejected\n" + ] + } + ], "source": [ "# Your conclusions here:\n", - "\n" + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that special attack and special defense scores of all pokemon are equal can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")\n" ] }, { @@ -280,12 +627,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis : The attack and defense scores of all pokemon are equal\n", + "Alternate Hypothesis : The attack and defense scores of all pokemon are not equal\n", + "\n", + "T-Statistic : 4.325566393330478\n", + "P-Value : 1.7140303479358558e-05\n", + "Null Hypothesis that attack and defense scores of all pokemon are equal can be rejected with 95% confidence\n" + ] + } + ], "source": [ "# Your code here:\n", - " \n", + "print(\"Null Hypothesis : The attack and defense scores of all pokemon are equal\")\n", + "print(\"Alternate Hypothesis : The attack and defense scores of all pokemon are not equal\\n\")\n", + "\n", + "t_stat, p_value = sts.ttest_1samp(pokemon['Attack']-pokemon['Defense'],popmean=0)\n", + "print(\"T-Statistic : {}\".format(t_stat))\n", + "print(\"P-Value : {}\".format(p_value)) \n", + "\n", + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that attack and defense scores of all pokemon are equal can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")\n", " " ] }, @@ -302,12 +672,139 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 69, + "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", + "
Type 1BugDarkDragonElectricFairyFightingFireFlyingGhostGrassGroundIceNormalPoisonPsychicRockSteelWater
Legendary
False692920401627472306728229628434023108
True02124105223422014444
\n", + "
" + ], + "text/plain": [ + "Type 1 Bug Dark Dragon Electric Fairy Fighting Fire Flying Ghost \\\n", + "Legendary \n", + "False 69 29 20 40 16 27 47 2 30 \n", + "True 0 2 12 4 1 0 5 2 2 \n", + "\n", + "Type 1 Grass Ground Ice Normal Poison Psychic Rock Steel Water \n", + "Legendary \n", + "False 67 28 22 96 28 43 40 23 108 \n", + "True 3 4 2 2 0 14 4 4 4 " + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "pk_cross_tab = pd.crosstab(pokemon['Legendary'],pokemon['Type 1'])\n", + "pk_cross_tab" ] }, { @@ -319,12 +816,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "P-Value : 5.118547414721704e-12\n" + ] + } + ], "source": [ "# Your code here:\n", - "\n" + "_, p_value,_,_ = sts.chi2_contingency(pk_cross_tab)\n", + "print(\"P-Value : {}\".format(p_value))" ] }, { @@ -336,12 +842,82 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis that there is no relationship between Legendary and Type 1 variables in Pokemon dataset can be rejected with 95% confidence\n" + ] + } + ], + "source": [ + "# Your answer here:\n", + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that there is no relationship between Legendary and Type 1 variables in Pokemon dataset can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [], + "source": [ + "# Changing the distribution to binary mode\n", + "pokemon['Type 1 Mod'] = np.where(pokemon['Type 1'] != 'Water', 'Other', pokemon['Type 1'])" + ] + }, + { + "cell_type": "code", + "execution_count": 79, "metadata": {}, "outputs": [], + "source": [ + "pk_cross_tab_mod = pd.crosstab(pokemon['Legendary'],pokemon['Type 1 Mod'])" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "P-Value : 0.08625467249550949\n" + ] + } + ], + "source": [ + "# Your code here:\n", + "_, p_value,_,_ = sts.chi2_contingency(pk_cross_tab_mod)\n", + "print(\"P-Value : {}\".format(p_value))" + ] + }, + { + "cell_type": "code", + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Null Hypothesis cannot be rejected\n" + ] + } + ], "source": [ "# Your answer here:\n", - "\n" + "if p_value < 0.05:\n", + " print(\"Null Hypothesis that there is no relationship between Legendary and Type 1 variables in Pokemon dataset can be rejected with 95% confidence\")\n", + "else:\n", + " print(\"Null Hypothesis cannot be rejected\")" ] }, { @@ -354,7 +930,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -368,9 +944,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 }