diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb
index c1bb43d..180780a 100755
--- a/your-code/challenge-1.ipynb
+++ b/your-code/challenge-1.ipynb
@@ -19,12 +19,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "import scipy.stats as st"
]
},
{
@@ -38,11 +40,154 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"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",
+ " | 3 | \n",
+ " 3 | \n",
+ " VenusaurMega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 625 | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 309 | \n",
+ " 39 | \n",
+ " 52 | \n",
+ " 43 | \n",
+ " 60 | \n",
+ " 50 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ "
\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": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here:\n"
+ "pokemon = pd.read_csv(\"Pokemon.csv\")\n",
+ "pokemon.head()"
]
},
{
@@ -58,7 +203,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -74,8 +219,9 @@
" dict: a dictionary of t-test scores for each feature where the feature name is the key and the p-value is the value\n",
" \"\"\"\n",
" results = {}\n",
- "\n",
- " # Your code here\n",
+ " for feature in features:\n",
+ " pvalue = st.ttest_ind(s1[feature], s2[feature], equal_var = False)[1]\n",
+ " results[feature] = pvalue\n",
" \n",
" return results"
]
@@ -101,11 +247,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 1.0026911708035284e-13,\n",
+ " 'Attack': 2.520372449236646e-16,\n",
+ " 'Defense': 4.8269984949193316e-11,\n",
+ " 'Sp. Atk': 1.5514614112239812e-21,\n",
+ " 'Sp. Def': 2.2949327864052826e-15,\n",
+ " 'Speed': 1.049016311882451e-18,\n",
+ " 'Total': 9.357954335957446e-47}"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "s1 = pokemon[pokemon[\"Legendary\"]==True]\n",
+ "s2 = pokemon[pokemon[\"Legendary\"]==False]\n",
+ "\n",
+ "t_test_features(s1,s2)"
]
},
{
@@ -121,7 +287,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# We can say the two pokemons have significantly different stats on each feature."
]
},
{
@@ -133,11 +299,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 0.14551697834219623,\n",
+ " 'Attack': 0.24721958967217725,\n",
+ " 'Defense': 0.5677711011725426,\n",
+ " 'Sp. Atk': 0.12332165977104388,\n",
+ " 'Sp. Def': 0.18829872292645752,\n",
+ " 'Speed': 0.00239265937312135,\n",
+ " 'Total': 0.5631377907941676}"
+ ]
+ },
+ "execution_count": 13,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "s1 = pokemon[pokemon[\"Generation\"]==1]\n",
+ "s2 = pokemon[pokemon[\"Generation\"]==2]\n",
+ "\n",
+ "t_test_features(s1,s2)"
]
},
{
@@ -153,7 +339,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# We can not say the two pokemons have significantly different stats on each feature."
]
},
{
@@ -165,11 +351,31 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 17,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'HP': 0.11314389855379414,\n",
+ " 'Attack': 0.00014932578145948305,\n",
+ " 'Defense': 2.7978540411514693e-08,\n",
+ " 'Sp. Atk': 0.00013876216585667907,\n",
+ " 'Sp. Def': 0.00010730610934512779,\n",
+ " 'Speed': 0.02421703281819093,\n",
+ " 'Total': 1.1157056505229961e-07}"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "s1 = pokemon[pd.isnull(pokemon[\"Type 2\"])]\n",
+ "s2 = pokemon[pd.notnull(pokemon[\"Type 2\"])]\n",
+ "\n",
+ "t_test_features(s1,s2)"
]
},
{
@@ -185,7 +391,7 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Except for HP, we can say the two pokemons have significantly different stats on each feature."
]
},
{
@@ -199,11 +405,21 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 19,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "TtestResult(statistic=4.325566393330478, pvalue=1.7140303479358558e-05, df=799)\n",
+ "TtestResult(statistic=0.853986188453353, pvalue=0.3933685997548122, df=799)\n"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "print(st.ttest_rel(pokemon[\"Attack\"], pokemon[\"Defense\"]))\n",
+ "print(st.ttest_rel(pokemon[\"Sp. Atk\"], pokemon[\"Sp. Def\"]))"
]
},
{
@@ -219,13 +435,14 @@
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Attack vs Defense - we can say the two features have significantly different stats.\n",
+ "# Sp. Atk vs Sp. Def - we cannot say the two features have significantly different stats."
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -239,7 +456,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.11.3"
}
},
"nbformat": 4,
diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb
index 1f0e335..a82717f 100755
--- a/your-code/challenge-2.ipynb
+++ b/your-code/challenge-2.ipynb
@@ -17,21 +17,167 @@
},
{
"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 numpy as np\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",
+ " | 3 | \n",
+ " 3 | \n",
+ " VenusaurMega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 625 | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 309 | \n",
+ " 39 | \n",
+ " 52 | \n",
+ " 43 | \n",
+ " 60 | \n",
+ " 50 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ "
\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": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Load the data:\n"
+ "# Load the data:\n",
+ "pokemon = pd.read_csv(\"Pokemon.csv\")\n",
+ "pokemon.head()"
]
},
{
@@ -58,13 +204,33 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['Grass' 'Fire' 'Water' 'Bug' 'Normal' 'Poison' 'Electric' 'Ground'\n",
+ " 'Fairy' 'Fighting' 'Psychic' 'Rock' 'Ghost' 'Ice' 'Dragon' 'Dark' 'Steel'\n",
+ " 'Flying' nan]\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "19"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n",
- "\n",
+ "unique_types = pd.concat([pokemon[\"Type 1\"], pokemon[\"Type 2\"]]).unique()\n",
"\n",
+ "print(unique_types)\n",
"len(unique_types) # you should see 19"
]
},
@@ -85,15 +251,35 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "18"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"pokemon_totals = []\n",
"\n",
- "# Your code here\n",
+ "for i in unique_types:\n",
"\n",
- "len(pokemon_totals) # you should see 18"
+ " total_values = pokemon[((pokemon[\"Type 1\"] == i) | (pokemon[\"Type 2\"] == i))][\"Total\"]\n",
+ " \n",
+ " valid_values = total_values[total_values.notnull()]\n",
+ " valid_values = valid_values.astype(float) \n",
+ " \n",
+ " if not valid_values.empty:\n",
+ " sampled_values = valid_values.sample(n=30) \n",
+ " pokemon_totals.append(sampled_values)\n",
+ " \n",
+ "len(pokemon_totals) "
]
},
{
@@ -111,11 +297,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "F_onewayResult(statistic=4.236183975152492, pvalue=4.031210344809833e-08)"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "st.f_oneway(*pokemon_totals)"
]
},
{
@@ -127,17 +324,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# We can reject the null hypothesis (there is significant difference among the pokemon groups)."
]
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -151,7 +348,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.11.3"
}
},
"nbformat": 4,