Skip to content

Commit 662e936

Browse files
committed
Merge branch 'master' of github.com:TrainingByPackt/Data-Visualization-with-Python
2 parents bb4a97e + b73b8da commit 662e936

18 files changed

+3918
-3918
lines changed
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Activity 01: Use NumPy to compute the Mean, median, and Variance"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"In this activity, you will consolidate the skills you've acquired in the last exercise and use NumPy to do some very basic mathematical calculations on our `normal_distribution` dataset. \n",
15+
"NumPy has a consistent API, so it should be rather easy to transfer your knowledge of the mean method to median and variance. "
16+
]
17+
},
18+
{
19+
"cell_type": "markdown",
20+
"metadata": {},
21+
"source": [
22+
"#### Loading the dataset"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 55,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# importing the necessary dependencies\n",
32+
"import numpy as np"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 4,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"# loading the Dataset\n",
42+
"dataset = np.genfromtxt('./data/normal_distribution.csv', delimiter=',')"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 45,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"# looking at the first two rows of the dataset\n"
52+
]
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"---"
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"#### Mean"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 46,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"# calculate the mean of the third row\n"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": 47,
80+
"metadata": {},
81+
"outputs": [],
82+
"source": [
83+
"# calculate the mean of the last column\n"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 48,
89+
"metadata": {},
90+
"outputs": [],
91+
"source": [
92+
"# calculate the mean of the intersection of the first 3 rows and first 3 columns\n"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"---"
100+
]
101+
},
102+
{
103+
"cell_type": "markdown",
104+
"metadata": {},
105+
"source": [
106+
"#### Median"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": 49,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"# calculate the median of the last row\n"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": 50,
121+
"metadata": {},
122+
"outputs": [],
123+
"source": [
124+
"# calculate the median of the last 3 columns\n"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": 51,
130+
"metadata": {},
131+
"outputs": [],
132+
"source": [
133+
"# calculate the median of each row\n"
134+
]
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"metadata": {},
139+
"source": [
140+
"---"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"#### Variance"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": 52,
153+
"metadata": {},
154+
"outputs": [],
155+
"source": [
156+
"# calculate the variance of each column\n"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": 53,
162+
"metadata": {},
163+
"outputs": [],
164+
"source": [
165+
"# calculate the variance of the intersection of the last 2 rows and first 2 columns\n"
166+
]
167+
},
168+
{
169+
"cell_type": "markdown",
170+
"metadata": {},
171+
"source": [
172+
"The values of the variance might seem a little bit strange at first. \n",
173+
"You can always go back to the topic that gives you a quick statistical overview to recap what you've learned so far. \n",
174+
"\n",
175+
"> **Note:** \n",
176+
"Just remember, the variance is not the standard deviation. \n",
177+
"\n",
178+
"Try calculation the standard deviation with NumPy to get a more descriptive value when comparing it to our dataset"
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": 1,
184+
"metadata": {},
185+
"outputs": [],
186+
"source": [
187+
"# calculate the standard deviation for the dataset\n"
188+
]
189+
}
190+
],
191+
"metadata": {
192+
"kernelspec": {
193+
"display_name": "Python 3",
194+
"language": "python",
195+
"name": "python3"
196+
},
197+
"language_info": {
198+
"codemirror_mode": {
199+
"name": "ipython",
200+
"version": 3
201+
},
202+
"file_extension": ".py",
203+
"mimetype": "text/x-python",
204+
"name": "python",
205+
"nbconvert_exporter": "python",
206+
"pygments_lexer": "ipython3",
207+
"version": "3.6.5"
208+
}
209+
},
210+
"nbformat": 4,
211+
"nbformat_minor": 2
212+
}

lesson01/Activity02/activity02_solution.ipynb renamed to lesson01/Activity01/activity01_solution.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## Activity 02: Use NumPy to compute the Mean, Median, and Variance"
7+
"## Activity 01: Use NumPy to compute the Mean, Median, and Variance"
88
]
99
},
1010
{
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
99.14931546, 104.03852715, 107.43534677, 97.85230675, 98.74986914, 98.80833412, 96.81964892, 98.56783189, 101.34745901
2-
92.02628776, 97.10439252, 99.32066924, 97.24584816, 92.9267508, 92.65657752, 105.7197853, 101.23162942, 93.87155456
3-
95.66253664, 95.17750125, 90.93318132, 110.18889465, 98.80084371, 105.95297652, 98.37481387, 106.54654286, 107.22482426
4-
91.37294597, 100.96781394, 100.40118279, 113.42090475, 105.48508838, 91.6604946, 106.1472841, 95.08715803, 103.40412146
5-
101.20862522, 103.5730309, 100.28690912, 105.85269352, 93.37126331, 108.57980357, 100.79478953, 94.20019732, 96.10020311
6-
102.80387079, 98.29687616, 93.24376389, 97.24130034, 89.03452725, 96.2832753, 104.60344836, 101.13442416, 97.62787811
7-
106.71751618, 102.97585605, 98.45723272, 100.72418901, 106.39798503, 95.46493436, 94.35373179, 106.83273763, 100.07721494
8-
96.02548256, 102.82360856, 106.47551845, 101.34745901, 102.45651798, 98.74767493, 97.57544275, 92.5748759, 91.37294597
9-
105.30350449, 92.87730812, 103.19258339, 104.40518318, 101.29326772, 100.85447132, 101.2226037, 106.03868807, 97.85230675
10-
110.44484313, 93.87155456, 101.5363647, 97.65393524, 92.75048583, 101.72074646, 96.96851209, 103.29147111, 99.14931546
11-
101.3514185, 100.37372248, 106.6471081, 100.61742813, 105.0320535, 99.35999981, 98.87007532, 95.85284217, 93.97853495
12-
97.21315663, 107.02874163, 102.17642112, 96.74630281, 95.93799169, 102.62384733, 105.07475277, 97.59572169, 106.57364584
13-
95.65982034, 107.22482426, 107.19119932, 102.93039474, 85.98839623, 95.19184343, 91.32093303, 102.35313953, 100.39303522
14-
100.39303522, 92.0108226, 97.75887636, 93.18884302, 100.44940274, 108.09423367, 96.50342927, 99.58664719, 95.19184343
15-
103.1521596, 109.40523174, 93.83969256, 99.95827854, 101.83462816, 99.69982772, 103.05289628, 103.93383957, 104.15899829
16-
106.11454989, 88.80221141, 94.5081787, 94.59300658, 101.08830521, 96.34622848, 96.89244283, 98.07122664, 100.28690912
17-
96.78266211, 99.84251605, 104.03478031, 106.57052697, 105.13668343, 105.37011896, 99.07551254, 104.15899829, 98.75108352
18-
101.86186193, 103.61720152, 99.57859892, 99.4889538, 103.05541444, 98.65912661, 98.72774132, 104.70526438, 110.44484313
19-
97.49594839, 96.59385486, 104.63817694, 102.55198606, 105.86078488, 96.5937781, 93.04610867, 99.92159953, 100.96781394
20-
96.76814836, 91.6779221, 101.79132774, 101.20773355, 98.29243952, 101.83845792, 97.94046856, 102.20618501, 91.37294597
21-
106.89005002, 106.57364584, 102.26648279, 107.40064604, 99.94318168, 103.40412146, 106.38276709, 98.00253006, 97.10439252
22-
99.80873105, 101.63973121, 106.46476468, 110.43976681, 100.69156231, 99.99579473, 101.32113654, 94.76253572, 97.24130034
23-
96.10020311, 94.57421727, 100.80409326, 105.02389857, 98.61325194, 95.62359311, 97.99762409, 103.83852459, 101.2226037
24-
94.11176915, 99.62387832, 104.51786419, 97.62787811, 93.97853495, 98.75108352, 106.05042487, 100.07721494, 106.89005002
1+
99.14931546, 104.03852715, 107.43534677, 97.85230675, 98.74986914, 98.80833412, 96.81964892, 98.56783189
2+
92.02628776, 97.10439252, 99.32066924, 97.24584816, 92.9267508, 92.65657752, 105.7197853, 101.23162942
3+
95.66253664, 95.17750125, 90.93318132, 110.18889465, 98.80084371, 105.95297652, 98.37481387, 106.54654286
4+
91.37294597, 100.96781394, 100.40118279, 113.42090475, 105.48508838, 91.6604946, 106.1472841, 95.08715803
5+
101.20862522, 103.5730309, 100.28690912, 105.85269352, 93.37126331, 108.57980357, 100.79478953, 94.20019732
6+
102.80387079, 98.29687616, 93.24376389, 97.24130034, 89.03452725, 96.2832753, 104.60344836, 101.13442416
7+
106.71751618, 102.97585605, 98.45723272, 100.72418901, 106.39798503, 95.46493436, 94.35373179, 106.83273763
8+
96.02548256, 102.82360856, 106.47551845, 101.34745901, 102.45651798, 98.74767493, 97.57544275, 92.5748759
9+
105.30350449, 92.87730812, 103.19258339, 104.40518318, 101.29326772, 100.85447132, 101.2226037, 106.03868807
10+
110.44484313, 93.87155456, 101.5363647, 97.65393524, 92.75048583, 101.72074646, 96.96851209, 103.29147111
11+
101.3514185, 100.37372248, 106.6471081, 100.61742813, 105.0320535, 99.35999981, 98.87007532, 95.85284217
12+
97.21315663, 107.02874163, 102.17642112, 96.74630281, 95.93799169, 102.62384733, 105.07475277, 97.59572169
13+
95.65982034, 107.22482426, 107.19119932, 102.93039474, 85.98839623, 95.19184343, 91.32093303, 102.35313953
14+
100.39303522, 92.0108226, 97.75887636, 93.18884302, 100.44940274, 108.09423367, 96.50342927, 99.58664719
15+
103.1521596, 109.40523174, 93.83969256, 99.95827854, 101.83462816, 99.69982772, 103.05289628, 103.93383957
16+
106.11454989, 88.80221141, 94.5081787, 94.59300658, 101.08830521, 96.34622848, 96.89244283, 98.07122664
17+
96.78266211, 99.84251605, 104.03478031, 106.57052697, 105.13668343, 105.37011896, 99.07551254, 104.15899829
18+
101.86186193, 103.61720152, 99.57859892, 99.4889538, 103.05541444, 98.65912661, 98.72774132, 104.70526438
19+
97.49594839, 96.59385486, 104.63817694, 102.55198606, 105.86078488, 96.5937781, 93.04610867, 99.92159953
20+
96.76814836, 91.6779221, 101.79132774, 101.20773355, 98.29243952, 101.83845792, 97.94046856, 102.20618501
21+
106.89005002, 106.57364584, 102.26648279, 107.40064604, 99.94318168, 103.40412146, 106.38276709, 98.00253006
22+
99.80873105, 101.63973121, 106.46476468, 110.43976681, 100.69156231, 99.99579473, 101.32113654, 94.76253572
23+
96.10020311, 94.57421727, 100.80409326, 105.02389857, 98.61325194, 95.62359311, 97.99762409, 103.83852459
24+
94.11176915, 99.62387832, 104.51786419, 97.62787811, 93.97853495, 98.75108352, 106.05042487, 100.07721494

0 commit comments

Comments
 (0)