diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb
index c1bb43d..4d5a492 100755
--- a/your-code/challenge-1.ipynb
+++ b/your-code/challenge-1.ipynb
@@ -19,12 +19,13 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 75,
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import scipy.stats as st"
]
},
{
@@ -38,11 +39,119 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 76,
"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",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " # Name Type 1 Type 2 Total HP Attack Defense Sp. Atk Sp. Def \\\n",
+ "0 1 Bulbasaur Grass Poison 318 45 49 49 65 65 \n",
+ "1 2 Ivysaur Grass Poison 405 60 62 63 80 80 \n",
+ "2 3 Venusaur Grass Poison 525 80 82 83 100 100 \n",
+ "\n",
+ " Speed Generation Legendary \n",
+ "0 45 1 False \n",
+ "1 60 1 False \n",
+ "2 80 1 False "
+ ]
+ },
+ "execution_count": 76,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here:\n"
+ "# Your code here:\n",
+ "pokemon = pd.read_csv(\"Pokemon.csv\")\n",
+ "pokemon.head(3)"
]
},
{
@@ -58,7 +167,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 77,
"metadata": {},
"outputs": [],
"source": [
@@ -75,8 +184,14 @@
" \"\"\"\n",
" results = {}\n",
"\n",
- " # Your code here\n",
- " \n",
+ " for feature in features:\n",
+ " feature_s1 = s1[feature]\n",
+ " feature_s2 = s2[feature]\n",
+ " \n",
+ " comparisson = st.ttest_ind(feature_s1, feature_s2, equal_var = False, alternative = \"less\")\n",
+ " \n",
+ " results[feature] = comparisson[1]\n",
+ "\n",
" return results"
]
},
@@ -101,11 +216,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 64,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 5.013455854017642e-14,\n",
+ " 'Attack': 1.260186224618323e-16,\n",
+ " 'Defense': 2.4134992474596658e-11,\n",
+ " 'Sp. Atk': 7.757307056119906e-22,\n",
+ " 'Sp. Def': 1.1474663932026413e-15,\n",
+ " 'Speed': 5.245081559412255e-19,\n",
+ " 'Total': 4.678977167978723e-47}"
+ ]
+ },
+ "execution_count": 64,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "feature_s1 = pokemon[pokemon[\"Legendary\"] == False]\n",
+ "feature_s2 = pokemon[pokemon[\"Legendary\"] == True]\n",
+ "\n",
+ "t_test_features(feature_s1, feature_s2)"
]
},
{
@@ -121,7 +256,9 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "\"\"\"\n",
+ "They do have some significantly differences, especially on \"HP\", \"Sp. Atk\" and \"Speed\".\n",
+ "\"\"\""
]
},
{
@@ -133,11 +270,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 65,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 0.07275848917109812,\n",
+ " 'Attack': 0.8763902051639113,\n",
+ " 'Defense': 0.2838855505862713,\n",
+ " 'Sp. Atk': 0.9383391701144781,\n",
+ " 'Sp. Def': 0.09414936146322876,\n",
+ " 'Speed': 0.9988036703134393,\n",
+ " 'Total': 0.7184311046029161}"
+ ]
+ },
+ "execution_count": 65,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "generation_s1 = pokemon[pokemon[\"Generation\"] == 1]\n",
+ "generation_s2 = pokemon[pokemon[\"Generation\"] == 2]\n",
+ "\n",
+ "t_test_features(generation_s1, generation_s2)"
]
},
{
@@ -149,11 +306,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "\"\"\"\n",
+ "There is no strong evidence to suggest a significant difference between Generation 1 and Generation 2 Pokémon for \n",
+ "these attributes. \n",
+ "\"\"\""
]
},
{
@@ -165,11 +325,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 78,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 0.943428050723103,\n",
+ " 'Attack': 0.9999253371092702,\n",
+ " 'Defense': 0.9999999860107298,\n",
+ " 'Sp. Atk': 0.9999306189170717,\n",
+ " 'Sp. Def': 0.9999463469453275,\n",
+ " 'Speed': 0.9878914835909045,\n",
+ " 'Total': 0.9999999442147175}"
+ ]
+ },
+ "execution_count": 78,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "type_s1 = pokemon[~pokemon[\"Type 2\"].isnull()]\n",
+ "type_s2 = pokemon[pokemon[\"Type 2\"].isnull()]\n",
+ "\n",
+ "t_test_features(type_s1, type_s2)"
]
},
{
@@ -181,11 +361,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "\"\"\"\n",
+ "There is no strong evidence to suggest a significant difference between Pokémon with single types and those with \n",
+ "two types for any of the attributes being tested. \n",
+ "\"\"\""
]
},
{
@@ -199,11 +382,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 82,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Difference Attack vs. Defense: TtestResult(statistic=4.325566393330478, pvalue=1.7140303479358558e-05, df=799)\n",
+ "Difference Sp. Atk vs. Sp. Def: TtestResult(statistic=0.853986188453353, pvalue=0.3933685997548122, df=799)\n"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "attack_defense = st.ttest_rel(pokemon[\"Attack\"], pokemon[\"Defense\"])\n",
+ "sp_atk_def = st.ttest_rel(pokemon[\"Sp. Atk\"], pokemon[\"Sp. Def\"])\n",
+ "\n",
+ "print(f\"Difference Attack vs. Defense: {attack_defense}\")\n",
+ "print(f\"Difference Sp. Atk vs. Sp. Def: {sp_atk_def}\")"
]
},
{
@@ -215,17 +411,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "\"\"\" \n",
+ "Because of the low values of \"Attack\" vs. \"Defense\" we cannot reject the null hypothesis that the values are different,\n",
+ "but because of the higher values of \"Sp. Atk\" vs. \"Sp. Def\", we can reject it.\n",
+ "\"\"\""
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -239,7 +438,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.10.9"
}
},
"nbformat": 4,
diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb
index 1f0e335..0166fc4 100755
--- a/your-code/challenge-2.ipynb
+++ b/your-code/challenge-2.ipynb
@@ -17,21 +17,130 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import scipy.stats as st"
]
},
{
"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",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " # Name Type 1 Type 2 Total HP Attack Defense Sp. Atk Sp. Def \\\n",
+ "0 1 Bulbasaur Grass Poison 318 45 49 49 65 65 \n",
+ "1 2 Ivysaur Grass Poison 405 60 62 63 80 80 \n",
+ "2 3 Venusaur Grass Poison 525 80 82 83 100 100 \n",
+ "\n",
+ " Speed Generation Legendary \n",
+ "0 45 1 False \n",
+ "1 60 1 False \n",
+ "2 80 1 False "
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Load the data:\n"
+ "# Load the data:\n",
+ "pokemon = pd.read_csv(\"Pokemon.csv\")\n",
+ "pokemon.head(3)"
]
},
{
@@ -58,14 +167,25 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array(['Grass', 'Fire', 'Water', 'Bug', 'Normal', 'Poison', 'Electric',\n",
+ " 'Ground', 'Fairy', 'Fighting', 'Psychic', 'Rock', 'Ghost', 'Ice',\n",
+ " 'Dragon', 'Dark', 'Steel', 'Flying'], dtype=object)"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n",
- "\n",
- "\n",
- "len(unique_types) # you should see 19"
+ "unique_types = pd.concat([pokemon[\"Type 1\"], pokemon[\"Type 2\"]]).dropna().unique()\n",
+ "unique_types"
]
},
{
@@ -85,15 +205,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "18"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"pokemon_totals = []\n",
"\n",
- "# Your code here\n",
+ "for pokemon_type in unique_types:\n",
+ " type_totals = pokemon[pokemon[\"Type 1\"] == pokemon_type][\"Total\"]\n",
+ " pokemon_totals.append(type_totals)\n",
"\n",
- "len(pokemon_totals) # you should see 18"
+ "len(pokemon_totals)"
]
},
{
@@ -111,11 +244,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "F_onewayResult(statistic=4.63876748166055, pvalue=2.077215448842098e-09)"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "st.f_oneway(*pokemon_totals)"
]
},
{
@@ -127,17 +271,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'\\nThe p-value suggests that there is strong evidence to reject the null hypothesis. \\nThe null hypothesis assumes that there is no significant difference between the means of the groups.\\n'"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your comment here"
+ "\"\"\"\n",
+ "The p-value suggests that there is strong evidence to reject the null hypothesis. \n",
+ "The null hypothesis assumes that there is no significant difference between the means of the groups.\n",
+ "\"\"\""
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -151,7 +309,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.10.9"
}
},
"nbformat": 4,