From ddaa2a380ae58c574415dd7d862d95e151c8f730 Mon Sep 17 00:00:00 2001 From: Imtiaz Faruk Date: Tue, 14 Jan 2025 12:51:22 +0100 Subject: [PATCH] Lab Submitted --- your-code/main.ipynb | 61 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index cdc1acb..1cfc3a2 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -18,7 +18,9 @@ "metadata": {}, "outputs": [], "source": [ - "# import numpy and pandas\n", + "import pandas as pd\n", + "import numpy as np\n", + "from scipy.stats import ttest_ind, ttest_rel, ttest_1samp, chi2_contingency\n", "\n" ] }, @@ -39,9 +41,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Run this code:\n", "\n", - "pokemon = pd.read_csv('../pokemon.csv')" + "# Load the dataset\n", + "pokemon = pd.read_csv('pokemon.csv')" ] }, { @@ -57,7 +59,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "pokemon.head(6)\n", "\n" ] }, @@ -74,7 +76,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "# Count of Legendary vs Non-Legendary Pokémon\n", + "legendary_count = pokemon['Legendary'].value_counts()\n", + "print(\"Legendary vs Non-Legendary Count:\\n\", legendary_count)\n", "\n" ] }, @@ -91,7 +95,10 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "# Mean and Standard Deviation of Total points for Legendary and Non-Legendary Pokémon\n", + "legendary_stats = pokemon.groupby('Legendary')['Total'].agg(['mean', 'std'])\n", + "print(\"Mean and Std of Total points:\\n\", legendary_stats)\n", + "\n", "\n" ] }, @@ -110,7 +117,11 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "# Independent T-Test (unequal variance) between Legendary and Non-Legendary Pokémon\n", + "test_legendary = ttest_ind(pokemon[pokemon['Legendary'] == True]['Total'],\n", + " pokemon[pokemon['Legendary'] == False]['Total'],\n", + " equal_var=False)\n", + "print(\"T-Test Result (Legendary vs Non-Legendary):\", test_legendary)\n", "\n" ] }, @@ -127,7 +138,8 @@ "metadata": {}, "outputs": [], "source": [ - "# Your conclusions here:\n", + "\n", + "\n", "\n" ] }, @@ -144,7 +156,10 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "# Pokémon Type counts\n", + "type_counts = pokemon['Type 1'].value_counts()\n", + "print(\"Pokémon Type Counts:\\n\", type_counts)\n", + "\n", "\n" ] }, @@ -161,7 +176,14 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "# Mean and Standard Deviation of Water Pokémon vs. Others\n", + "water_pokemon = pokemon[pokemon['Type 1'] == 'Water']\n", + "non_water_pokemon = pokemon[pokemon['Type 1'] != 'Water']\n", + "\n", + "water_stats = water_pokemon['Total'].agg(['mean', 'std'])\n", + "non_water_stats = non_water_pokemon['Total'].agg(['mean', 'std'])\n", + "print(\"Water Pokémon Stats:\\n\", water_stats)\n", + "print(\"Non-Water Pokémon Stats:\\n\", non_water_stats)\n", "\n" ] }, @@ -178,7 +200,24 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", + "# Independent T-Test (equal variance) between Water and Non-Water Pokémon\n", + "test_water = ttest_ind(water_pokemon['Total'], non_water_pokemon['Total'], equal_var=True)\n", + "print(\"T-Test Result (Water vs Non-Water):\", test_water)\n", + "\n", + "# Matched Pairs T-Test: Defense vs Attack\n", + "defense_attack_test = ttest_rel(pokemon['Defense'], pokemon['Attack'])\n", + "print(\"Matched Pairs T-Test (Defense vs Attack):\", defense_attack_test)\n", + "\n", + "# Matched Pairs T-Test: Special Defense vs Special Attack\n", + "sp_def_sp_atk_test = ttest_rel(pokemon['Sp. Def'], pokemon['Sp. Atk'])\n", + "print(\"Matched Pairs T-Test (Special Defense vs Special Attack):\", sp_def_sp_atk_test)\n", + "\n", + "# One-Sample T-Test for the difference between Defense and Attack\n", + "diff_def_attack = pokemon['Defense'] - pokemon['Attack']\n", + "one_sample_test = ttest_1samp(diff_def_attack, 0)\n", + "print(\"One-Sample T-Test (Defense - Attack):\", one_sample_test)\n", + "\n", + "\n", "\n" ] },