From cab62c95957f3c8bc7fdc71e91fdd77e85dc408b Mon Sep 17 00:00:00 2001 From: sborto86 Date: Mon, 7 Nov 2022 17:46:59 +0100 Subject: [PATCH 1/3] lab finished --- your-code/main.ipynb | 632 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 593 insertions(+), 39 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 4128c1e..540469a 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ - "# import numpy and pandas\n" + "# import numpy and pandas\n", + "import pandas as pd\n", + "import numpy as np\n", + "from scipy.stats import trim_mean, mode, skew, gaussian_kde, pearsonr, spearmanr, beta\n", + "from statsmodels.stats.weightstats import ztest as ztest\n", + "\n", + "from scipy.stats import ttest_ind, norm, t\n", + "from scipy.stats import f_oneway\n", + "from scipy.stats import sem" ] }, { @@ -30,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -48,11 +56,130 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
NameJob TitlesDepartmentFull or Part-TimeSalary or HourlyTypical HoursAnnual SalaryHourly Rate
0AARON, JEFFERY MSERGEANTPOLICEFSalaryNaN101442.0NaN
1AARON, KARINAPOLICE OFFICER (ASSIGNED AS DETECTIVE)POLICEFSalaryNaN94122.0NaN
2AARON, KIMBERLEI RCHIEF CONTRACT EXPEDITERGENERAL SERVICESFSalaryNaN101592.0NaN
3ABAD JR, VICENTE MCIVIL ENGINEER IVWATER MGMNTFSalaryNaN110064.0NaN
4ABASCAL, REECE ETRAFFIC CONTROL AIDE-HOURLYOEMCPHourly20.0NaN19.86
\n", + "
" + ], + "text/plain": [ + " Name Job Titles \\\n", + "0 AARON, JEFFERY M SERGEANT \n", + "1 AARON, KARINA POLICE OFFICER (ASSIGNED AS DETECTIVE) \n", + "2 AARON, KIMBERLEI R CHIEF CONTRACT EXPEDITER \n", + "3 ABAD JR, VICENTE M CIVIL ENGINEER IV \n", + "4 ABASCAL, REECE E TRAFFIC CONTROL AIDE-HOURLY \n", + "\n", + " Department Full or Part-Time Salary or Hourly Typical Hours \\\n", + "0 POLICE F Salary NaN \n", + "1 POLICE F Salary NaN \n", + "2 GENERAL SERVICES F Salary NaN \n", + "3 WATER MGMNT F Salary NaN \n", + "4 OEMC P Hourly 20.0 \n", + "\n", + " Annual Salary Hourly Rate \n", + "0 101442.0 NaN \n", + "1 94122.0 NaN \n", + "2 101592.0 NaN \n", + "3 110064.0 NaN \n", + "4 NaN 19.86 " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "salaries.head()\n" ] }, { @@ -64,11 +191,30 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Name 0\n", + "Job Titles 0\n", + "Department 0\n", + "Full or Part-Time 0\n", + "Salary or Hourly 0\n", + "Typical Hours 25161\n", + "Annual Salary 8022\n", + "Hourly Rate 25161\n", + "dtype: int64" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "salaries.isna().sum()" ] }, { @@ -80,11 +226,32 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Name 0\n", + "Job Titles 0\n", + "Department 0\n", + "Full or Part-Time 0\n", + "Salary or Hourly 0\n", + "Typical Hours 0\n", + "Annual Salary 0\n", + "Hourly Rate 0\n", + "dtype: int64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n", + "salaries[(salaries[\"Hourly Rate\"].isna()) & (salaries[\"Annual Salary\"].isna())].count()\n", "\n" ] }, @@ -104,11 +271,57 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "POLICE 13414\n", + "FIRE 4641\n", + "STREETS & SAN 2198\n", + "OEMC 2102\n", + "WATER MGMNT 1879\n", + "AVIATION 1629\n", + "TRANSPORTN 1140\n", + "PUBLIC LIBRARY 1015\n", + "GENERAL SERVICES 980\n", + "FAMILY & SUPPORT 615\n", + "FINANCE 560\n", + "HEALTH 488\n", + "CITY COUNCIL 411\n", + "LAW 407\n", + "BUILDINGS 269\n", + "COMMUNITY DEVELOPMENT 207\n", + "BUSINESS AFFAIRS 171\n", + "COPA 116\n", + "BOARD OF ELECTION 107\n", + "DoIT 99\n", + "PROCUREMENT 92\n", + "INSPECTOR GEN 87\n", + "MAYOR'S OFFICE 85\n", + "CITY CLERK 84\n", + "ANIMAL CONTRL 81\n", + "HUMAN RESOURCES 79\n", + "CULTURAL AFFAIRS 65\n", + "BUDGET & MGMT 46\n", + "ADMIN HEARNG 39\n", + "DISABILITIES 28\n", + "TREASURER 22\n", + "HUMAN RELATIONS 16\n", + "BOARD OF ETHICS 8\n", + "POLICE BOARD 2\n", + "LICENSE APPL COMM 1\n", + "Name: Department, dtype: int64" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "salaries[\"Department\"].value_counts()\n" ] }, { @@ -122,11 +335,24 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Salary is significally different from $30/hr with a p-value of 1.8228873859286195e-94 \n" + ] + } + ], "source": [ - "# Your code here:\n" + "hourly=salaries[~salaries[\"Hourly Rate\"].isna()]\n", + "statistic, p_value = ztest(hourly[\"Hourly Rate\"], value = 30)\n", + "if p_value < 0.05:\n", + " print(f\"The Salary is significally different from $30/hr with a p-value of {p_value}\")\n", + "if p_value > 0.05:\n", + " print(\"The average hourly salary is not siginbfically different from $30/hr\")" ] }, { @@ -140,11 +366,24 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Salary is significally higher than $86000/year with a p-value of 0.0010280845287547855\n" + ] + } + ], "source": [ - "# Your code here:\n" + "police=salaries[(salaries[\"Department\"] == \"POLICE\") & (~salaries[\"Annual Salary\"].isna())]\n", + "statistic, p_value = ztest(police[\"Annual Salary\"], value=86000, alternative=\"larger\")\n", + "if p_value < 0.05:\n", + " print(f\"The Salary is significally higher than $86000/year with a p-value of {p_value}\")\n", + "if p_value > 0.05:\n", + " print(f\"The Salary is NOT significally higher than $86000/year (p-value of {p_value})\")" ] }, { @@ -156,11 +395,266 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Salary or HourlyHourlySalary
Department
ADMIN HEARNG039
POLICE BOARD02
BOARD OF ELECTION0107
BOARD OF ETHICS08
LICENSE APPL COMM01
BUILDINGS0269
INSPECTOR GEN087
CITY CLERK084
HUMAN RELATIONS016
TREASURER022
COPA0116
DoIT099
DISABILITIES028
PROCUREMENT290
FIRE24639
BUDGET & MGMT244
HEALTH3485
COMMUNITY DEVELOPMENT4203
HUMAN RESOURCES475
BUSINESS AFFAIRS7164
CULTURAL AFFAIRS758
MAYOR'S OFFICE877
POLICE1013404
ANIMAL CONTRL1962
LAW40367
FINANCE44516
CITY COUNCIL64347
FAMILY & SUPPORT287328
PUBLIC LIBRARY299716
TRANSPORTN725415
GENERAL SERVICES765215
AVIATION1082547
OEMC1273829
WATER MGMNT1513366
STREETS & SAN1862336
\n", + "
" + ], + "text/plain": [ + "Salary or Hourly Hourly Salary\n", + "Department \n", + "ADMIN HEARNG 0 39\n", + "POLICE BOARD 0 2\n", + "BOARD OF ELECTION 0 107\n", + "BOARD OF ETHICS 0 8\n", + "LICENSE APPL COMM 0 1\n", + "BUILDINGS 0 269\n", + "INSPECTOR GEN 0 87\n", + "CITY CLERK 0 84\n", + "HUMAN RELATIONS 0 16\n", + "TREASURER 0 22\n", + "COPA 0 116\n", + "DoIT 0 99\n", + "DISABILITIES 0 28\n", + "PROCUREMENT 2 90\n", + "FIRE 2 4639\n", + "BUDGET & MGMT 2 44\n", + "HEALTH 3 485\n", + "COMMUNITY DEVELOPMENT 4 203\n", + "HUMAN RESOURCES 4 75\n", + "BUSINESS AFFAIRS 7 164\n", + "CULTURAL AFFAIRS 7 58\n", + "MAYOR'S OFFICE 8 77\n", + "POLICE 10 13404\n", + "ANIMAL CONTRL 19 62\n", + "LAW 40 367\n", + "FINANCE 44 516\n", + "CITY COUNCIL 64 347\n", + "FAMILY & SUPPORT 287 328\n", + "PUBLIC LIBRARY 299 716\n", + "TRANSPORTN 725 415\n", + "GENERAL SERVICES 765 215\n", + "AVIATION 1082 547\n", + "OEMC 1273 829\n", + "WATER MGMNT 1513 366\n", + "STREETS & SAN 1862 336" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "pd.crosstab(salaries[\"Department\"], salaries[\"Salary or Hourly\"]).sort_values(by=[\"Hourly\"])\n" ] }, { @@ -172,11 +666,24 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Salary is significally smaller than $35/hour with a p-value of 5.478855641943434e-22 and a mean of 33.73\n" + ] + } + ], "source": [ - "# Your code here:\n" + "streets = salaries[(salaries[\"Department\"] == \"STREETS & SAN\") & (~salaries[\"Hourly Rate\"].isna())]\n", + "statistic, p_value = ztest(streets[\"Hourly Rate\"], value=35, alternative=\"smaller\")\n", + "if p_value < 0.05:\n", + " print(f\"The Salary is significally smaller than $35/hour with a p-value of {p_value} and a mean of {round(streets['Hourly Rate'].mean(), 2)}\")\n", + "if p_value > 0.05:\n", + " print(f\"The Salary is NOT significally smaller than $35/hour (p-value of {p_value})\")" ] }, { @@ -200,11 +707,23 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 64, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(32.52345834488529, 33.05365708767727)" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "sem_hourly = sem(hourly[\"Hourly Rate\"], nan_policy='omit')\n", + "t.interval(0.95, df = len(hourly)-1, loc=hourly[\"Hourly Rate\"].mean(), scale=sem_hourly)\n" ] }, { @@ -216,11 +735,24 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(86786.73471803166, 86787.2648622714)" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "yearly=salaries[salaries[\"Salary or Hourly\"]== \"Salary\"]\n", + "sem_yearly = sem(hourly[\"Hourly Rate\"], nan_policy='omit')\n", + "t.interval(0.95, df = len(yearly)-1, loc=yearly[\"Annual Salary\"].mean(), scale=sem_yearly)" ] }, { @@ -238,17 +770,39 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 72, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hourly workers in the City of Chicago is significantly different from 25% with a p-value of 0.0004481127249057967 and observed proportion of 24.18 %\n" + ] + } + ], "source": [ - "# Your code here:\n" + "from statsmodels.stats.proportion import proportions_ztest as proportions_ztest\n", + "count = len(salaries[salaries[\"Salary or Hourly\"]== \"Hourly\"])\n", + "nobs = len(salaries)\n", + "statistic, p_value = proportions_ztest(count, nobs, value=0.25, alternative='two-sided')\n", + "if p_value < 0.05:\n", + " print(f\"Hourly workers in the City of Chicago is significantly different from 25% with a p-value of {p_value} and observed proportion of {round((count/nobs)*100, 2)} %\")\n", + "if p_value > 0.05:\n", + " print(f\"The Salary is NOT significally smaller than $35/hour (p-value of {p_value})\")\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -262,7 +816,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.13" } }, "nbformat": 4, From 7af60604e421e580f719e4cda705068ac635cfbe Mon Sep 17 00:00:00 2001 From: sborto86 Date: Mon, 7 Nov 2022 17:57:33 +0100 Subject: [PATCH 2/3] lab finished --- your-code/main.ipynb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 540469a..9187271 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -735,23 +735,23 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(86786.73471803166, 86787.2648622714)" + "(86177.05631531784, 86795.77269094894)" ] }, - "execution_count": 66, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "yearly=salaries[salaries[\"Salary or Hourly\"]== \"Salary\"]\n", - "sem_yearly = sem(hourly[\"Hourly Rate\"], nan_policy='omit')\n", + "yearly=salaries[(salaries[\"Salary or Hourly\"]== \"Salary\")&(salaries[\"Department\"] == \"POLICE\")]\n", + "sem_yearly = sem(yearly[\"Annual Salary\"], nan_policy='omit')\n", "t.interval(0.95, df = len(yearly)-1, loc=yearly[\"Annual Salary\"].mean(), scale=sem_yearly)" ] }, From 799f861f6d36542547e7178cba42a9c8aa9cd3ec Mon Sep 17 00:00:00 2001 From: sborto86 Date: Mon, 7 Nov 2022 23:13:58 +0100 Subject: [PATCH 3/3] bonus lab finished --- your-code/bonus.ipynb | 597 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 571 insertions(+), 26 deletions(-) diff --git a/your-code/bonus.ipynb b/your-code/bonus.ipynb index 59dec71..2f68ac1 100755 --- a/your-code/bonus.ipynb +++ b/your-code/bonus.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -39,13 +39,155 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
01BulbasaurGrassPoison3184549496565451False
12IvysaurGrassPoison4056062638080601False
23VenusaurGrassPoison525808283100100801False
33VenusaurMega VenusaurGrassPoison62580100123122120801False
44CharmanderFireNaN3093952436050651False
\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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Import dataset\n", "\n", - "pokemon = pd.read_csv('../../lab-df-calculation-and-transformation/your-code/Pokemon.csv')\n", + "pokemon = pd.read_csv('Pokemon.csv')\n", "\n", "pokemon.head()" ] @@ -63,10 +205,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ + "from scipy.stats import ttest_ind\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", @@ -79,9 +222,8 @@ " 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", - " \n", + " for f in features:\n", + " results[f] = ttest_ind(s1[f], s2[f], nan_policy='omit')[1]\n", " return results" ] }, @@ -106,11 +248,28 @@ }, { "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" + "t_test_features(pokemon[pokemon[\"Legendary\"]==True], pokemon[pokemon[\"Legendary\"]==False])\n" ] }, { @@ -126,7 +285,345 @@ "metadata": {}, "outputs": [], "source": [ - "# Your comment here" + "# There are siginificant diferences in all stats" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
#TotalHPAttackDefenseSp. AtkSp. DefSpeedGeneration
count65.00000065.00000065.00000065.00000065.00000065.00000065.00000065.00000065.000000
mean470.215385637.38461592.738462116.67692399.661538122.184615105.938462100.1846153.769231
std173.65109560.93738921.72216430.34803728.25513131.10460828.82700422.9523231.455262
min144.000000580.00000050.00000050.00000020.00000050.00000020.00000050.0000001.000000
25%381.000000580.00000080.000000100.00000090.000000100.00000090.00000090.0000003.000000
50%483.000000600.00000091.000000110.000000100.000000120.000000100.000000100.0000004.000000
75%642.000000680.000000105.000000131.000000115.000000150.000000120.000000110.0000005.000000
max721.000000780.000000150.000000190.000000200.000000194.000000200.000000180.0000006.000000
\n", + "
" + ], + "text/plain": [ + " # Total HP Attack Defense Sp. Atk \\\n", + "count 65.000000 65.000000 65.000000 65.000000 65.000000 65.000000 \n", + "mean 470.215385 637.384615 92.738462 116.676923 99.661538 122.184615 \n", + "std 173.651095 60.937389 21.722164 30.348037 28.255131 31.104608 \n", + "min 144.000000 580.000000 50.000000 50.000000 20.000000 50.000000 \n", + "25% 381.000000 580.000000 80.000000 100.000000 90.000000 100.000000 \n", + "50% 483.000000 600.000000 91.000000 110.000000 100.000000 120.000000 \n", + "75% 642.000000 680.000000 105.000000 131.000000 115.000000 150.000000 \n", + "max 721.000000 780.000000 150.000000 190.000000 200.000000 194.000000 \n", + "\n", + " Sp. Def Speed Generation \n", + "count 65.000000 65.000000 65.000000 \n", + "mean 105.938462 100.184615 3.769231 \n", + "std 28.827004 22.952323 1.455262 \n", + "min 20.000000 50.000000 1.000000 \n", + "25% 90.000000 90.000000 3.000000 \n", + "50% 100.000000 100.000000 4.000000 \n", + "75% 120.000000 110.000000 5.000000 \n", + "max 200.000000 180.000000 6.000000 " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pokemon[pokemon[\"Legendary\"]==True].describe()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
#TotalHPAttackDefenseSp. AtkSp. DefSpeedGeneration
count735.000000735.000000735.000000735.000000735.000000735.000000735.000000735.000000735.000000
mean353.315646417.21360567.18231375.66938871.55918468.45442268.89251765.4557823.284354
std208.590419106.76041724.80884930.49015330.40819429.09170525.66931027.8430381.673471
min1.000000180.0000001.0000005.0000005.00000010.00000020.0000005.0000001.000000
25%175.500000324.00000050.00000054.50000050.00000045.00000050.00000045.0000002.000000
50%346.000000425.00000065.00000072.00000066.00000065.00000065.00000064.0000003.000000
75%533.500000498.00000079.50000095.00000085.00000085.00000085.00000085.0000005.000000
max715.000000700.000000255.000000185.000000230.000000175.000000230.000000160.0000006.000000
\n", + "
" + ], + "text/plain": [ + " # Total HP Attack Defense Sp. Atk \\\n", + "count 735.000000 735.000000 735.000000 735.000000 735.000000 735.000000 \n", + "mean 353.315646 417.213605 67.182313 75.669388 71.559184 68.454422 \n", + "std 208.590419 106.760417 24.808849 30.490153 30.408194 29.091705 \n", + "min 1.000000 180.000000 1.000000 5.000000 5.000000 10.000000 \n", + "25% 175.500000 324.000000 50.000000 54.500000 50.000000 45.000000 \n", + "50% 346.000000 425.000000 65.000000 72.000000 66.000000 65.000000 \n", + "75% 533.500000 498.000000 79.500000 95.000000 85.000000 85.000000 \n", + "max 715.000000 700.000000 255.000000 185.000000 230.000000 175.000000 \n", + "\n", + " Sp. Def Speed Generation \n", + "count 735.000000 735.000000 735.000000 \n", + "mean 68.892517 65.455782 3.284354 \n", + "std 25.669310 27.843038 1.673471 \n", + "min 20.000000 5.000000 1.000000 \n", + "25% 50.000000 45.000000 2.000000 \n", + "50% 65.000000 64.000000 3.000000 \n", + "75% 85.000000 85.000000 5.000000 \n", + "max 230.000000 160.000000 6.000000 " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pokemon[pokemon[\"Legendary\"]==False].describe()" ] }, { @@ -138,11 +635,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "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": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "t_test_features(pokemon[pokemon[\"Generation\"]==1], pokemon[pokemon[\"Generation\"]==2])\n" ] }, { @@ -158,7 +672,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your comment here" + "#Only speed seems to show significant diferences between Gen 1 and Gen 2" ] }, { @@ -170,11 +684,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "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": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "t_test_features(pokemon[pokemon[\"Type 2\"].isna()], pokemon[~pokemon[\"Type 2\"].isna()])\n" ] }, { @@ -190,7 +721,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your comment here" + "#There are significant differences in all stats except in HP" ] }, { @@ -204,11 +735,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "Ttest_relResult(statistic=5.299665422561717, pvalue=1.5019573188505383e-07)" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "from scipy.stats import ttest_rel\n", + "normal=pokemon['Attack']/pokemon['Defense']\n", + "special = pokemon['Sp. Atk']/pokemon['Sp. Def']\n", + "ttest_rel(normal, special, nan_policy='omit', alternative='two-sided')\n" ] }, { @@ -224,13 +769,13 @@ "metadata": {}, "outputs": [], "source": [ - "# Your comment here" + "#The ratio Attack / Defense is siginficatly diferent to ratio Sp. Atk / Sp. Def" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -244,7 +789,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.9.13" } }, "nbformat": 4,