Skip to content

Commit e8717ba

Browse files
Created using Colaboratory
1 parent 15cb701 commit e8717ba

File tree

1 file changed

+276
-0
lines changed

1 file changed

+276
-0
lines changed

Measure_of_Variability.ipynb

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": [],
7+
"collapsed_sections": [],
8+
"authorship_tag": "ABX9TyOV87J8C5fXRut2bqYuzsIz",
9+
"include_colab_link": true
10+
},
11+
"kernelspec": {
12+
"name": "python3",
13+
"display_name": "Python 3"
14+
},
15+
"language_info": {
16+
"name": "python"
17+
}
18+
},
19+
"cells": [
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {
23+
"id": "view-in-github",
24+
"colab_type": "text"
25+
},
26+
"source": [
27+
"<a href=\"https://colab.research.google.com/github/DeepthiTabithaBennet/Python_AppliedStatistics/blob/main/Measure_of_Variability.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
28+
]
29+
},
30+
{
31+
"cell_type": "markdown",
32+
"metadata": {
33+
"id": "CL891ro7yhxS"
34+
},
35+
"source": [
36+
"**MEASURE OF VARIABILITY**"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"metadata": {
42+
"id": "p3JwtRYEdkiC"
43+
},
44+
"source": [
45+
"# Written by Deepthi Tabitha Bennet\n",
46+
"\n",
47+
"import numpy as np\n",
48+
"import math\n",
49+
"\n",
50+
"arr = np.array([32, 56, 47, 87, 98, 36, 87, 38, 97, 4, 26, 94, 95, 90, 24, 7, 90, 63])\n",
51+
"arr.sort()"
52+
],
53+
"execution_count": null,
54+
"outputs": []
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {
59+
"id": "p4n01pG0o4Ms"
60+
},
61+
"source": [
62+
"**Range**"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"metadata": {
68+
"colab": {
69+
"base_uri": "https://localhost:8080/"
70+
},
71+
"id": "_cQd7VrXo97b",
72+
"outputId": "825db697-58e9-42bb-d783-6aa473fc0775"
73+
},
74+
"source": [
75+
"range = arr[len(arr)-1] - arr[0]\n",
76+
"print(range)"
77+
],
78+
"execution_count": null,
79+
"outputs": [
80+
{
81+
"output_type": "stream",
82+
"name": "stdout",
83+
"text": [
84+
"94\n"
85+
]
86+
}
87+
]
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {
92+
"id": "P9wy5d8jibQE"
93+
},
94+
"source": [
95+
"**Inter Quartile Range**"
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"metadata": {
101+
"colab": {
102+
"base_uri": "https://localhost:8080/"
103+
},
104+
"id": "lJM23sdpe7ne",
105+
"outputId": "83bee92b-d957-489f-fde3-e047158cb506"
106+
},
107+
"source": [
108+
"Q1 = np.quantile(arr,.25)\n",
109+
"Q3 = np.quantile(arr,.75)\n",
110+
"\n",
111+
"IQR = Q3 - Q1\n",
112+
"print(IQR)"
113+
],
114+
"execution_count": null,
115+
"outputs": [
116+
{
117+
"output_type": "stream",
118+
"name": "stdout",
119+
"text": [
120+
"57.0\n"
121+
]
122+
}
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {
128+
"id": "-od66TYhpBgb"
129+
},
130+
"source": [
131+
"**Variance**"
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"metadata": {
137+
"colab": {
138+
"base_uri": "https://localhost:8080/"
139+
},
140+
"id": "9VPJgK-kpGDT",
141+
"outputId": "c6da936f-bd43-404d-bc7e-46102af40d63"
142+
},
143+
"source": [
144+
"sum = arr.sum()\n",
145+
"mean = sum / len(arr)\n",
146+
"\n",
147+
"difference_squared = 0\n",
148+
"\n",
149+
"for i in arr:\n",
150+
" difference_squared += (i - mean) ** 2\n",
151+
"\n",
152+
"variance = (difference_squared / (len(arr)) - 1)\n",
153+
"print(variance)"
154+
],
155+
"execution_count": null,
156+
"outputs": [
157+
{
158+
"output_type": "stream",
159+
"name": "stdout",
160+
"text": [
161+
"1048.0277777777778\n"
162+
]
163+
}
164+
]
165+
},
166+
{
167+
"cell_type": "markdown",
168+
"metadata": {
169+
"id": "CfDqx8FSpHIK"
170+
},
171+
"source": [
172+
"**Standard Deviation**"
173+
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"metadata": {
178+
"colab": {
179+
"base_uri": "https://localhost:8080/"
180+
},
181+
"id": "nP7IHJI0pKeL",
182+
"outputId": "432a7890-57f1-49f4-8625-4165f6a71b40"
183+
},
184+
"source": [
185+
"sum = arr.sum()\n",
186+
"mean = sum / len(arr)\n",
187+
"\n",
188+
"difference_squared = 0\n",
189+
"\n",
190+
"for i in arr:\n",
191+
" difference_squared += (i - mean) ** 2\n",
192+
"\n",
193+
"SD = math.sqrt(difference_squared / (len(arr)) - 1)\n",
194+
"print(SD)"
195+
],
196+
"execution_count": null,
197+
"outputs": [
198+
{
199+
"output_type": "stream",
200+
"name": "stdout",
201+
"text": [
202+
"32.373257138844984\n"
203+
]
204+
}
205+
]
206+
},
207+
{
208+
"cell_type": "markdown",
209+
"metadata": {
210+
"id": "QPp6ZuddinHD"
211+
},
212+
"source": [
213+
"**Coefficient of Variance**"
214+
]
215+
},
216+
{
217+
"cell_type": "code",
218+
"metadata": {
219+
"colab": {
220+
"base_uri": "https://localhost:8080/"
221+
},
222+
"id": "zu_vI8A7kBhj",
223+
"outputId": "b4861865-5dac-4248-bc0b-cd36f06d52b5"
224+
},
225+
"source": [
226+
"COV = (SD / mean) * 100\n",
227+
"print(COV)"
228+
],
229+
"execution_count": null,
230+
"outputs": [
231+
{
232+
"output_type": "stream",
233+
"name": "stdout",
234+
"text": [
235+
"54.408835527470565\n"
236+
]
237+
}
238+
]
239+
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {
243+
"id": "3Ll6eh-lxIsb"
244+
},
245+
"source": [
246+
"**Z - Score**"
247+
]
248+
},
249+
{
250+
"cell_type": "code",
251+
"metadata": {
252+
"id": "xE_JeW51xM7i",
253+
"colab": {
254+
"base_uri": "https://localhost:8080/"
255+
},
256+
"outputId": "d0977237-ca73-4f22-e2da-4062fbce2440"
257+
},
258+
"source": [
259+
"q = int(input(\"Enter the Index of the number, whose Z - Score is to be calculated : \"))\n",
260+
"z = (arr[q-1] - mean) / SD\n",
261+
"print(z)"
262+
],
263+
"execution_count": null,
264+
"outputs": [
265+
{
266+
"output_type": "stream",
267+
"name": "stdout",
268+
"text": [
269+
"Enter the Index of the number, whose Z - Score is to be calculated : 3\n",
270+
"-1.0965841295407748\n"
271+
]
272+
}
273+
]
274+
}
275+
]
276+
}

0 commit comments

Comments
 (0)