Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 243 additions & 26 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -38,11 +40,154 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>#</th>\n",
" <th>Name</th>\n",
" <th>Type 1</th>\n",
" <th>Type 2</th>\n",
" <th>Total</th>\n",
" <th>HP</th>\n",
" <th>Attack</th>\n",
" <th>Defense</th>\n",
" <th>Sp. Atk</th>\n",
" <th>Sp. Def</th>\n",
" <th>Speed</th>\n",
" <th>Generation</th>\n",
" <th>Legendary</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>Bulbasaur</td>\n",
" <td>Grass</td>\n",
" <td>Poison</td>\n",
" <td>318</td>\n",
" <td>45</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" <td>65</td>\n",
" <td>65</td>\n",
" <td>45</td>\n",
" <td>1</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>Ivysaur</td>\n",
" <td>Grass</td>\n",
" <td>Poison</td>\n",
" <td>405</td>\n",
" <td>60</td>\n",
" <td>62</td>\n",
" <td>63</td>\n",
" <td>80</td>\n",
" <td>80</td>\n",
" <td>60</td>\n",
" <td>1</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>Venusaur</td>\n",
" <td>Grass</td>\n",
" <td>Poison</td>\n",
" <td>525</td>\n",
" <td>80</td>\n",
" <td>82</td>\n",
" <td>83</td>\n",
" <td>100</td>\n",
" <td>100</td>\n",
" <td>80</td>\n",
" <td>1</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3</td>\n",
" <td>VenusaurMega Venusaur</td>\n",
" <td>Grass</td>\n",
" <td>Poison</td>\n",
" <td>625</td>\n",
" <td>80</td>\n",
" <td>100</td>\n",
" <td>123</td>\n",
" <td>122</td>\n",
" <td>120</td>\n",
" <td>80</td>\n",
" <td>1</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>4</td>\n",
" <td>Charmander</td>\n",
" <td>Fire</td>\n",
" <td>NaN</td>\n",
" <td>309</td>\n",
" <td>39</td>\n",
" <td>52</td>\n",
" <td>43</td>\n",
" <td>60</td>\n",
" <td>50</td>\n",
" <td>65</td>\n",
" <td>1</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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()"
]
},
{
Expand All @@ -58,7 +203,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
Expand All @@ -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)"
]
},
{
Expand All @@ -121,7 +287,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Your comment here"
"# We can say the two pokemons have significantly different stats on each feature."
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -153,7 +339,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Your comment here"
"# We can not say the two pokemons have significantly different stats on each feature."
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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."
]
},
{
Expand All @@ -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\"]))"
]
},
{
Expand All @@ -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"
},
Expand All @@ -239,7 +456,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down
Loading