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
254 changes: 227 additions & 27 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -38,11 +38,119 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"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",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here:\n"
"# Your code here:\n",
"pokemon = pd.read_csv('Pokemon.csv')\n",
"pokemon.head(3)\n"
]
},
{
Expand All @@ -58,10 +166,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.t_test_features(s1, s2, features=['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total'])>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from scipy import stats\n",
"\n",
"def t_test_features(s1, s2, features=['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total']):\n",
" \"\"\"Test means of a feature set of two samples\n",
" \n",
Expand All @@ -73,11 +194,11 @@
" Returns:\n",
" 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",
" results = {k:stats.ttest_ind(s1[k], s2[k])[1] for k in features}\n",
" \n",
" return results"
" return results\n",
"\n",
"t_test_features"
]
},
{
Expand All @@ -101,11 +222,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'HP': 3.330647684846191e-15,\n",
" 'Attack': 7.827253003205333e-24,\n",
" 'Defense': 1.5842226094427255e-12,\n",
" 'Sp. Atk': 6.314915770427266e-41,\n",
" 'Sp. Def': 1.8439809580409594e-26,\n",
" 'Speed': 2.3540754436898437e-21,\n",
" 'Total': 3.0952457469652825e-52}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"legendary = t_test_features(pokemon[pokemon['Legendary'] == True], pokemon[pokemon['Legendary'] == False])\n",
"legendary\n"
]
},
{
Expand All @@ -121,7 +260,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Your comment here"
"# Yeah, specially on attack and sp. atk"
]
},
{
Expand All @@ -133,11 +272,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'HP': 0.13791881412813622,\n",
" 'Attack': 0.24050968418101457,\n",
" 'Defense': 0.5407630349194362,\n",
" 'Sp. Atk': 0.14119788176331508,\n",
" 'Sp. Def': 0.16781226231606386,\n",
" 'Speed': 0.0028356954812578704,\n",
" 'Total': 0.5599140649014442}"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"generation = t_test_features(pokemon[pokemon['Generation'] == 1], pokemon[pokemon['Generation'] == 2])\n",
"generation\n"
]
},
{
Expand All @@ -153,7 +310,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Your comment here"
"# It seems the values are pretty stable and homogeneous,\n",
" # maybe speed is the only outlier"
]
},
{
Expand All @@ -165,11 +323,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'HP': 0.11060643144431842,\n",
" 'Attack': 0.00015741395666164396,\n",
" 'Defense': 3.250594205757004e-08,\n",
" 'Sp. Atk': 0.0001454917404035147,\n",
" 'Sp. Def': 0.00010893304795534396,\n",
" 'Speed': 0.024051410794037463,\n",
" 'Total': 1.1749035008828752e-07}"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"types = t_test_features(pokemon[pokemon['Type 2'].isnull() == False], pokemon[pokemon['Type 2'].isnull() == True])\n",
"types\n"
]
},
{
Expand All @@ -185,7 +361,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Your comment here"
"# We see that pokemon with 2 types have higher defense"
]
},
{
Expand All @@ -199,11 +375,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"TtestResult(statistic=4.325566393330478, pvalue=1.7140303479358558e-05, df=799)"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"TtestResult(statistic=0.853986188453353, pvalue=0.3933685997548122, df=799)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Your code here\n"
"# if it's all pokemons it's the same population, types, legendaries, etc.\n",
"att_def = stats.ttest_rel(pokemon['Attack'], pokemon['Defense'])\n",
"sp_att_def = stats.ttest_rel(pokemon['Sp. Atk'], pokemon['Sp. Def'])\n",
"display(att_def)\n",
"display(sp_att_def)"
]
},
{
Expand All @@ -219,7 +418,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Your comment here"
"\"\"\" Because of the low values of sp_att_sp_df we cannot reject the null hypothesis that the values are different,\n",
"but because of the higher values of att_def, we can reject it\"\"\""
]
}
],
Expand All @@ -239,7 +439,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
Loading