Skip to content

Commit c43841a

Browse files
committed
Inital commit for notebooks
1 parent 634172c commit c43841a

29 files changed

+21794
-0
lines changed
Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Mean"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import numpy as np"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 2,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"my_list = [1, 2, 2, 2, 4, 5, 6, 6, 6, 9, 10, 10, 10, 11, 14, 14, 15, 18, 19, 20]"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 3,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"def get_mean(my_data):\n",
35+
" return sum(my_data)/(len(my_data)*1.0)"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 4,
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/plain": [
46+
"9.2"
47+
]
48+
},
49+
"execution_count": 4,
50+
"metadata": {},
51+
"output_type": "execute_result"
52+
}
53+
],
54+
"source": [
55+
"get_mean(my_list)"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 5,
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"my_np_list = np.asarray(my_list)"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": 6,
70+
"metadata": {},
71+
"outputs": [
72+
{
73+
"data": {
74+
"text/plain": [
75+
"9.2"
76+
]
77+
},
78+
"execution_count": 6,
79+
"metadata": {},
80+
"output_type": "execute_result"
81+
}
82+
],
83+
"source": [
84+
"np.mean(my_np_list)"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"metadata": {},
90+
"source": [
91+
"### How mean is affected by extreme points"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 7,
97+
"metadata": {},
98+
"outputs": [],
99+
"source": [
100+
"my_list.append(100)"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 8,
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"data": {
110+
"text/plain": [
111+
"13.523809523809524"
112+
]
113+
},
114+
"execution_count": 8,
115+
"metadata": {},
116+
"output_type": "execute_result"
117+
}
118+
],
119+
"source": [
120+
"get_mean(my_list)"
121+
]
122+
},
123+
{
124+
"cell_type": "markdown",
125+
"metadata": {},
126+
"source": [
127+
"# Median"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": 9,
133+
"metadata": {},
134+
"outputs": [
135+
{
136+
"data": {
137+
"text/plain": [
138+
"10.0"
139+
]
140+
},
141+
"execution_count": 9,
142+
"metadata": {},
143+
"output_type": "execute_result"
144+
}
145+
],
146+
"source": [
147+
"np.median(my_list)"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": 10,
153+
"metadata": {},
154+
"outputs": [
155+
{
156+
"data": {
157+
"text/plain": [
158+
"[1, 2, 2, 2, 4, 5, 6, 6, 6, 9, 10, 10, 10, 11, 14, 14, 15, 18, 19, 20, 100]"
159+
]
160+
},
161+
"execution_count": 10,
162+
"metadata": {},
163+
"output_type": "execute_result"
164+
}
165+
],
166+
"source": [
167+
"my_list"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 11,
173+
"metadata": {},
174+
"outputs": [
175+
{
176+
"data": {
177+
"text/plain": [
178+
"9.5"
179+
]
180+
},
181+
"execution_count": 11,
182+
"metadata": {},
183+
"output_type": "execute_result"
184+
}
185+
],
186+
"source": [
187+
"np.median(my_np_list)"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": 12,
193+
"metadata": {},
194+
"outputs": [
195+
{
196+
"data": {
197+
"text/plain": [
198+
"array([ 1, 2, 2, 2, 4, 5, 6, 6, 6, 9, 10, 10, 10, 11, 14, 14, 15,\n",
199+
" 18, 19, 20])"
200+
]
201+
},
202+
"execution_count": 12,
203+
"metadata": {},
204+
"output_type": "execute_result"
205+
}
206+
],
207+
"source": [
208+
"my_np_list"
209+
]
210+
},
211+
{
212+
"cell_type": "markdown",
213+
"metadata": {},
214+
"source": [
215+
"# Mode"
216+
]
217+
},
218+
{
219+
"cell_type": "code",
220+
"execution_count": 13,
221+
"metadata": {},
222+
"outputs": [],
223+
"source": [
224+
"from scipy.stats import mode"
225+
]
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": 14,
230+
"metadata": {},
231+
"outputs": [
232+
{
233+
"data": {
234+
"text/plain": [
235+
"ModeResult(mode=array([2]), count=array([3]))"
236+
]
237+
},
238+
"execution_count": 14,
239+
"metadata": {},
240+
"output_type": "execute_result"
241+
}
242+
],
243+
"source": [
244+
"mode(my_list)"
245+
]
246+
},
247+
{
248+
"cell_type": "markdown",
249+
"metadata": {},
250+
"source": [
251+
"## Can be used over non-numeric data"
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"execution_count": 15,
257+
"metadata": {},
258+
"outputs": [],
259+
"source": [
260+
"my_list_str = ['a', 'b', 'c', 'a', 'b', 'b', 'c', 'a', 'a', 'b', 'd']"
261+
]
262+
},
263+
{
264+
"cell_type": "code",
265+
"execution_count": 16,
266+
"metadata": {},
267+
"outputs": [
268+
{
269+
"name": "stderr",
270+
"output_type": "stream",
271+
"text": [
272+
"/usr/local/lib/python3.5/dist-packages/scipy/stats/stats.py:248: RuntimeWarning: The input array could not be properly checked for nan values. nan values will be ignored.\n",
273+
" \"values. nan values will be ignored.\", RuntimeWarning)\n"
274+
]
275+
},
276+
{
277+
"data": {
278+
"text/plain": [
279+
"ModeResult(mode=array(['a'], dtype='<U1'), count=array([4]))"
280+
]
281+
},
282+
"execution_count": 16,
283+
"metadata": {},
284+
"output_type": "execute_result"
285+
}
286+
],
287+
"source": [
288+
"mode(my_list_str)"
289+
]
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": null,
294+
"metadata": {},
295+
"outputs": [],
296+
"source": []
297+
}
298+
],
299+
"metadata": {
300+
"kernelspec": {
301+
"display_name": "Python 3",
302+
"language": "python",
303+
"name": "python3"
304+
},
305+
"language_info": {
306+
"codemirror_mode": {
307+
"name": "ipython",
308+
"version": 3
309+
},
310+
"file_extension": ".py",
311+
"mimetype": "text/x-python",
312+
"name": "python",
313+
"nbconvert_exporter": "python",
314+
"pygments_lexer": "ipython3",
315+
"version": "3.5.2"
316+
}
317+
},
318+
"nbformat": 4,
319+
"nbformat_minor": 2
320+
}

0 commit comments

Comments
 (0)