Skip to content

Commit e7eba23

Browse files
committed
Add lesson 4 activities
1 parent 6adc598 commit e7eba23

17 files changed

+5800
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Intelligent quotient\n",
8+
"In this activity, we will compare IQ scores among different test groups using Seaborn."
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"metadata": {},
15+
"outputs": [],
16+
"source": [
17+
"# Import statements\n"
18+
]
19+
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": null,
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"group_a = [118, 103, 125, 107, 111, 96, 104, 97, 96, 114, 96, 75, 114,\n",
27+
" 107, 87, 117, 117, 114, 117, 112, 107, 133, 94, 91, 118, 110,\n",
28+
" 117, 86, 143, 83, 106, 86, 98, 126, 109, 91, 112, 120, 108,\n",
29+
" 111, 107, 98, 89, 113, 117, 81, 113, 112, 84, 115, 96, 93,\n",
30+
" 128, 115, 138, 121, 87, 112, 110, 79, 100, 84, 115, 93, 108,\n",
31+
" 130, 107, 106, 106, 101, 117, 93, 94, 103, 112, 98, 103, 70,\n",
32+
" 139, 94, 110, 105, 122, 94, 94, 105, 129, 110, 112, 97, 109,\n",
33+
" 121, 106, 118, 131, 88, 122, 125, 93, 78]\n",
34+
"group_b = [126, 89, 90, 101, 102, 74, 93, 101, 66, 120, 108, 97, 98,\n",
35+
" 105, 119, 92, 113, 81, 104, 108, 83, 102, 105, 111, 102, 107,\n",
36+
" 103, 89, 89, 110, 71, 110, 120, 85, 111, 83, 122, 120, 102,\n",
37+
" 84, 118, 100, 100, 114, 81, 109, 69, 97, 95, 106, 116, 109,\n",
38+
" 114, 98, 90, 92, 98, 91, 81, 85, 86, 102, 93, 112, 76,\n",
39+
" 89, 110, 75, 100, 90, 96, 94, 107, 108, 95, 96, 96, 114,\n",
40+
" 93, 95, 117, 141, 115, 95, 86, 100, 121, 103, 66, 99, 96,\n",
41+
" 111, 110, 105, 110, 91, 112, 102, 112, 75]\n",
42+
"group_c = [108, 89, 114, 116, 126, 104, 113, 96, 69, 121, 109, 102, 107,\n",
43+
" 122, 104, 107, 108, 137, 107, 116, 98, 132, 108, 114, 82, 93,\n",
44+
" 89, 90, 86, 91, 99, 98, 83, 93, 114, 96, 95, 113, 103,\n",
45+
" 81, 107, 85, 116, 85, 107, 125, 126, 123, 122, 124, 115, 114,\n",
46+
" 93, 93, 114, 107, 107, 84, 131, 91, 108, 127, 112, 106, 115,\n",
47+
" 82, 90, 117, 108, 115, 113, 108, 104, 103, 90, 110, 114, 92,\n",
48+
" 101, 72, 109, 94, 122, 90, 102, 86, 119, 103, 110, 96, 90,\n",
49+
" 110, 96, 69, 85, 102, 69, 96, 101, 90]\n",
50+
"group_d = [ 93, 99, 91, 110, 80, 113, 111, 115, 98, 74, 96, 80, 83,\n",
51+
" 102, 60, 91, 82, 90, 97, 101, 89, 89, 117, 91, 104, 104,\n",
52+
" 102, 128, 106, 111, 79, 92, 97, 101, 106, 110, 93, 93, 106,\n",
53+
" 108, 85, 83, 108, 94, 79, 87, 113, 112, 111, 111, 79, 116,\n",
54+
" 104, 84, 116, 111, 103, 103, 112, 68, 54, 80, 86, 119, 81,\n",
55+
" 84, 91, 96, 116, 125, 99, 58, 102, 77, 98, 100, 90, 106,\n",
56+
" 109, 114, 102, 102, 112, 103, 98, 96, 85, 97, 110, 131, 92,\n",
57+
" 79, 115, 122, 95, 105, 74, 85, 85, 95]\n",
58+
"data = pd.DataFrame({'Groups': ['Group A'] * len(group_a) + ['Group B'] * len(group_b) + ['Group C'] * len(group_c) + ['Group D'] * len(group_d),\n",
59+
" 'IQ score': group_a + group_b + group_c + group_d})"
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"Create a box plot for each of the IQ scores of different test groups using Seaborn's boxplot function. Use the whitegrid style, set the context to talk, and remove all axes splines, except the one on the bottom. Add a title."
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"metadata": {},
73+
"outputs": [],
74+
"source": [
75+
"# Create figure\n",
76+
"plt.figure(dpi=150)\n",
77+
"# Set style and context\n",
78+
"\n",
79+
"# Create boxplot\n",
80+
"\n",
81+
"# Despine\n",
82+
"\n",
83+
"# Add title\n",
84+
"\n",
85+
"# Show plot\n"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": []
94+
}
95+
],
96+
"metadata": {
97+
"kernelspec": {
98+
"display_name": "Python 3",
99+
"language": "python",
100+
"name": "python3"
101+
},
102+
"language_info": {
103+
"codemirror_mode": {
104+
"name": "ipython",
105+
"version": 3
106+
},
107+
"file_extension": ".py",
108+
"mimetype": "text/x-python",
109+
"name": "python",
110+
"nbconvert_exporter": "python",
111+
"pygments_lexer": "ipython3",
112+
"version": "3.6.6"
113+
}
114+
},
115+
"nbformat": 4,
116+
"nbformat_minor": 2
117+
}

lesson04/Activity01/activity01_solution.ipynb

Lines changed: 138 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Flight passengers across years and months\n",
8+
"In this activity, we will use a heatmap to find patterns in flight passenger data."
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"metadata": {},
15+
"outputs": [],
16+
"source": [
17+
"# Import statements\n",
18+
"import numpy as np\n",
19+
"import pandas as pd\n",
20+
"import matplotlib.pyplot as plt\n",
21+
"import seaborn as sns\n",
22+
"\n",
23+
"%matplotlib inline"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"# Load dataset\n",
33+
"data = sns.load_dataset('flights')\n",
34+
"data = data.pivot('month', 'year', 'passengers')"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"metadata": {},
40+
"source": [
41+
"Use a heatmap to visualize the given data. The given dataset contains the monthly figures fpr flight passengers for multiple years. Use your own color map. Make sure that the lowest value is the darkest and the highest the brightest color."
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"# Create figure\n",
51+
"\n",
52+
"# Create heatmap\n",
53+
"\n",
54+
"# Add title\n",
55+
"\n",
56+
"# Show plot\n"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": []
65+
}
66+
],
67+
"metadata": {
68+
"kernelspec": {
69+
"display_name": "Python 3",
70+
"language": "python",
71+
"name": "python3"
72+
},
73+
"language_info": {
74+
"codemirror_mode": {
75+
"name": "ipython",
76+
"version": 3
77+
},
78+
"file_extension": ".py",
79+
"mimetype": "text/x-python",
80+
"name": "python",
81+
"nbconvert_exporter": "python",
82+
"pygments_lexer": "ipython3",
83+
"version": "3.7.1"
84+
}
85+
},
86+
"nbformat": 4,
87+
"nbformat_minor": 2
88+
}

lesson04/Activity02/activity02_solution.ipynb

Lines changed: 101 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Movie comparison revisited"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"In this activity, we will use a bar plot to compare movie scores. You are given five movies with scores from Rotten Tomatoes. The Tomatometer is the percentage of approved Tomatometer critics who have given a positive review for the movie. The Audience Score is the percentage of users who have given a score of 3.5 or higher out of 5. Compare these two scores among the five movies."
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"# Import statements\n",
24+
"import numpy as np\n",
25+
"import pandas as pd\n",
26+
"\n",
27+
"import matplotlib.pyplot as plt\n",
28+
"import seaborn as sns\n",
29+
"\n",
30+
"%matplotlib inline"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"Use pandas to read the data located in the subfolder data and transform the data into a useable format for Seaborn's barplot function."
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": null,
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"# Load dataset\n"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"metadata": {},
52+
"source": [
53+
"Use Seaborn to create a visually-appealing bar plot comparing the two scores for all five movies."
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": null,
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"# Create figure\n",
63+
"sns.set()\n",
64+
"plt.figure(figsize=(10, 5), dpi=300)\n",
65+
"# Create bar plot\n",
66+
"\n",
67+
"# Add title\n",
68+
"\n",
69+
"# Show plot\n"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": []
78+
}
79+
],
80+
"metadata": {
81+
"kernelspec": {
82+
"display_name": "Python 3",
83+
"language": "python",
84+
"name": "python3"
85+
},
86+
"language_info": {
87+
"codemirror_mode": {
88+
"name": "ipython",
89+
"version": 3
90+
},
91+
"file_extension": ".py",
92+
"mimetype": "text/x-python",
93+
"name": "python",
94+
"nbconvert_exporter": "python",
95+
"pygments_lexer": "ipython3",
96+
"version": "3.6.6"
97+
}
98+
},
99+
"nbformat": 4,
100+
"nbformat_minor": 2
101+
}

lesson04/Activity03/activity02_solution.ipynb

Lines changed: 118 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
,MovieTitle,Tomatometer,AudienceScore
2+
0,The Shape of Water,91,73
3+
1,Black Panther,97,79
4+
2,Dunkirk,92,81
5+
3,The Martian,91,91
6+
4,The Hobbit: An Unexpected Journey,64,83

0 commit comments

Comments
 (0)