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
257 changes: 228 additions & 29 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -38,11 +39,119 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 76,
"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": 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)"
]
},
{
Expand All @@ -58,7 +167,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 77,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
},
Expand All @@ -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)"
]
},
{
Expand All @@ -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",
"\"\"\""
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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",
"\"\"\""
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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",
"\"\"\""
]
},
{
Expand All @@ -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}\")"
]
},
{
Expand All @@ -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"
},
Expand All @@ -239,7 +438,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
Loading