From 5a6d7ff2c99710b61c2e60a204a6499e5a296731 Mon Sep 17 00:00:00 2001 From: CevicX <134785214+CevicX@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:56:34 +0100 Subject: [PATCH 1/3] done --- your-code/main.ipynb | 65 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 332f496..3f01be8 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,11 +9,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Libraries" + "# Libraries\n", + "import pandas as pd\n", + "import numpy as np\n", + "import scipy.stats as st" ] }, { @@ -32,11 +35,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(172.14308590115726, 174.79024743217607)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "heights = np.array([167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195])\n", + "mean=np.mean(heights)\n", + "std=4\n", + "st.norm.interval(0.8,loc=mean,scale=std/np.sqrt(len(heights)))" ] }, { @@ -51,11 +69,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code \n", + "n = 105\n", + "negative = 27\n", + "sample_proportion = negative/n\n", + "confidence_levels = [0.80, 0.90]\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.2571428571428571" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sample_proportion" ] }, { @@ -76,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -94,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -121,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -145,7 +188,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.11.4" } }, "nbformat": 4, From c8caf50faed4851800bae57a3d22f0d7031c365c Mon Sep 17 00:00:00 2001 From: CevicX <134785214+CevicX@users.noreply.github.com> Date: Fri, 11 Aug 2023 15:17:53 +0100 Subject: [PATCH 2/3] done --- your-code/main.ipynb | 99 ++++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 3f01be8..17abb09 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -44,7 +44,7 @@ "(172.14308590115726, 174.79024743217607)" ] }, - "execution_count": 2, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -52,53 +52,92 @@ "source": [ "# your code here\n", "heights = np.array([167, 167, 168, 168, 168, 169, 171, 172, 173, 175, 175, 175, 177, 182, 195])\n", + "alpha=0.8\n", "mean=np.mean(heights)\n", "std=4\n", + "n=(len(heights)-1)\n", "st.norm.interval(0.8,loc=mean,scale=std/np.sqrt(len(heights)))" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 16, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(170.9019616724727, 176.03137166086063)" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "## Challenge 2 \n", - "In a sample of 105 shops selected randomly from an area, we note that 27 of them have had losses in this month. Get an interval for the proportion of businesses in the area with losses to a confidence level of 80% and a confidence level of 90%.\n", - "\n", - "**Hint**: function `stats.norm.interval` from `scipy` can help you get through this exercise. " + "#With t distribuiton because we dont have more than 30 \n", + "std=heights.std(ddof=1)\n", + "st.t.interval(0.8,n-1,loc=mean,scale=std/np.sqrt(len(heights)))" ] }, { - "cell_type": "code", - "execution_count": 3, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# your code \n", - "n = 105\n", - "negative = 27\n", - "sample_proportion = negative/n\n", - "confidence_levels = [0.80, 0.90]\n", - "\n" + "## Challenge 2 \n", + "In a sample of 105 shops selected randomly from an area, we note that 27 of them have had losses in this month. Get an interval for the proportion of businesses in the area with losses to a confidence level of 80% and a confidence level of 90%.\n", + "\n", + "**Hint**: function `stats.norm.interval` from `scipy` can help you get through this exercise. " ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 36, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "0.2571428571428571" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "Our CI for 80% proportion is [0.20248138545542083] [0.3118043288302934]\n", + "Our CI for 90% proportion is [0.18698561776452813] [0.3273000965211861]\n", + "Python Way (0.20248138545542083, 0.3118043288302934) \n", + " (0.1869856177645281, 0.3273000965211861)\n" + ] } ], "source": [ - "sample_proportion" + "# your code \n", + "n=105\n", + "losses=27\n", + "p=losses/n\n", + "confidence_levels=[0.80, 0.90]\n", + "ste=2\n", + "#80% confidence\n", + "\n", + "z_value=st.norm.ppf(1-(1-0.80)/2)\n", + "\n", + "margin_of_error= z_value*np.sqrt((p*(1-p))/n)\n", + "lower_bound= p-margin_of_error\n", + "upper_bound=p+margin_of_error\n", + "\n", + "print(f'Our CI for 80% proportion is [{lower_bound}] [{upper_bound}]')\n", + "#90% confidence\n", + "\n", + "z_value=st.norm.ppf(1-(1-0.90)/2)\n", + "se=np.sqrt((p*(1-p))/n)\n", + "margin_of_error= z_value*se\n", + "lower_bound= p-margin_of_error\n", + "upper_bound=p+margin_of_error\n", + "\n", + "print(f'Our CI for 90% proportion is [{lower_bound}] [{upper_bound}]')\n", + "\n", + "#python way\n", + "\n", + "print('Python Way',\n", + " st.norm.interval(0.80, loc = p, scale = se),'\\n',\n", + " st.norm.interval(0.90, loc = p, scale = se))" ] }, { @@ -119,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -137,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -164,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ From dd8e925b8f8a935979380edc2aa97b037aa7f13f Mon Sep 17 00:00:00 2001 From: CevicX <134785214+CevicX@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:10:51 +0100 Subject: [PATCH 3/3] done --- your-code/main.ipynb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 17abb09..15b7e89 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -44,7 +44,7 @@ "(172.14308590115726, 174.79024743217607)" ] }, - "execution_count": 13, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -61,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -70,7 +70,7 @@ "(170.9019616724727, 176.03137166086063)" ] }, - "execution_count": 16, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -158,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -176,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -203,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [