Skip to content

Commit 1fa1e83

Browse files
Created using Colaboratory
1 parent 9c6b765 commit 1fa1e83

File tree

1 file changed

+218
-0
lines changed

1 file changed

+218
-0
lines changed

Mean_Median_Mode.ipynb

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": [],
7+
"collapsed_sections": [],
8+
"authorship_tag": "ABX9TyN7ZUg62afIuPWZjGbBV9eF",
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/Mean_Median_Mode.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": "MteebtjDu5rU"
34+
},
35+
"source": [
36+
"**Central Tendency of Data**"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"metadata": {
42+
"id": "JdiuOctquOSx"
43+
},
44+
"source": [
45+
"# Written by Deepthi Tabitha Bennet\n",
46+
"\n",
47+
"import numpy as np\n",
48+
"import statistics\n",
49+
"import math"
50+
],
51+
"execution_count": null,
52+
"outputs": []
53+
},
54+
{
55+
"cell_type": "code",
56+
"metadata": {
57+
"colab": {
58+
"base_uri": "https://localhost:8080/"
59+
},
60+
"id": "tvJLKIV28Wbq",
61+
"outputId": "ddbf4ccf-3c90-4486-dcda-c156684e4247"
62+
},
63+
"source": [
64+
"data = np.array([1,2,4,9,6,3,2,4,6,9,0,8,9,5,3,5,8,5,4,9])\n",
65+
"Data = [1,2,4,9,6,3,2,4,6,9,0,8,9,5,3,5,8,5,4,9]\n",
66+
"sum = data.sum()\n",
67+
"print(sum)"
68+
],
69+
"execution_count": null,
70+
"outputs": [
71+
{
72+
"output_type": "stream",
73+
"name": "stdout",
74+
"text": [
75+
"102\n"
76+
]
77+
}
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {
83+
"id": "S_WThNZ-x_Zz"
84+
},
85+
"source": [
86+
"**Mean**"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"metadata": {
92+
"id": "9LkiFMOkyA0k",
93+
"colab": {
94+
"base_uri": "https://localhost:8080/"
95+
},
96+
"outputId": "e5f27fed-8073-4e69-ed25-449dcb5b0af7"
97+
},
98+
"source": [
99+
"# Without using Libraries\n",
100+
"mean1 = sum // len(data)\n",
101+
"print(mean1)\n",
102+
"\n",
103+
"# Using Libraries\n",
104+
"mean2 = statistics.mean(data)\n",
105+
"print(mean2)"
106+
],
107+
"execution_count": null,
108+
"outputs": [
109+
{
110+
"output_type": "stream",
111+
"name": "stdout",
112+
"text": [
113+
"5\n",
114+
"5\n"
115+
]
116+
}
117+
]
118+
},
119+
{
120+
"cell_type": "markdown",
121+
"metadata": {
122+
"id": "2D2HPtJjygGj"
123+
},
124+
"source": [
125+
"**Median**"
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"metadata": {
131+
"id": "aL5CChrEyhQ7",
132+
"colab": {
133+
"base_uri": "https://localhost:8080/"
134+
},
135+
"outputId": "a5762490-f4d3-4f2c-b518-6f7f2753c052"
136+
},
137+
"source": [
138+
"# Without using Libraries\n",
139+
"n = len(data)\n",
140+
"data.sort()\n",
141+
"\n",
142+
"if n % 2 == 0:\n",
143+
" median1a = data[n//2]\n",
144+
" median1b = data[n//2 - 1]\n",
145+
" median1 = (median1a + median1b)/2\n",
146+
"else:\n",
147+
" median1 = data[n//2]\n",
148+
"\n",
149+
"print(median1)\n",
150+
"\n",
151+
"# Using Libraries\n",
152+
"median2 = statistics.median(data)\n",
153+
"print(median2)"
154+
],
155+
"execution_count": null,
156+
"outputs": [
157+
{
158+
"output_type": "stream",
159+
"name": "stdout",
160+
"text": [
161+
"5.0\n",
162+
"5.0\n"
163+
]
164+
}
165+
]
166+
},
167+
{
168+
"cell_type": "markdown",
169+
"metadata": {
170+
"id": "xsapd9PQ1KLK"
171+
},
172+
"source": [
173+
"**Mode**"
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"metadata": {
179+
"id": "ajG-q6Nk1OIK",
180+
"colab": {
181+
"base_uri": "https://localhost:8080/"
182+
},
183+
"outputId": "e3bfa02d-c764-44ec-9c6c-ba8d868a326f"
184+
},
185+
"source": [
186+
"# Without using Libraries\n",
187+
"freq = {}\n",
188+
"\n",
189+
"for value in data:\n",
190+
" freq[value] = freq.get(value, 0) + 1\n",
191+
"\n",
192+
"MostFreq = max(freq.values())\n",
193+
"mode1 = [key for key, value in freq.items() if value == MostFreq]\n",
194+
"\n",
195+
"print(mode1[0])\n",
196+
"\n",
197+
"mode3 = max(data, key = Data.count)\n",
198+
"print(mode3)\n",
199+
"\n",
200+
"# Using Libraries\n",
201+
"mode2 = statistics.mode(data)\n",
202+
"print(mode2)"
203+
],
204+
"execution_count": null,
205+
"outputs": [
206+
{
207+
"output_type": "stream",
208+
"name": "stdout",
209+
"text": [
210+
"9\n",
211+
"9\n",
212+
"9\n"
213+
]
214+
}
215+
]
216+
}
217+
]
218+
}

0 commit comments

Comments
 (0)