Skip to content

Commit 89e9af4

Browse files
committed
Added challenges
1 parent b6175e2 commit 89e9af4

File tree

421 files changed

+279011
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

421 files changed

+279011
-21
lines changed

01 - Data Exploration.ipynb

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"\n",
2828
"Suppose a college takes a sample of student grades for a data science class.\n",
2929
"\n",
30-
"Run the code in the cell below to see the data."
30+
"Run the code in the cell below by clicking the **► Run** button to see the data."
3131
]
3232
},
3333
{
@@ -612,7 +612,41 @@
612612
"cell_type": "markdown",
613613
"metadata": {},
614614
"source": [
615-
"DataFrames are amazingly versatile, and make it easy to manipulate data. Most DataFrame operations return a new copy of the DataFrame; so if you want to modify a DataFrame but keep the existing variable, you need to assign the result of the operation to the existing variable. For example, the following code sorts the student data into descending order of Grade, and assigns the resulting sorted DataFrame to the original **df_students** variable."
615+
"DataFrames are designed for tabular data, and you can use them to perform many of the kinds of data analytics operation you can do in a relational database; such as grouping and aggregating tables of data.\n",
616+
"\n",
617+
"For example, you can use the **groupby** method to group the student data into groups based on the **Pass** column you added previously, and count the number of names in each group - in other words, you can determine how many students passed and failed."
618+
]
619+
},
620+
{
621+
"cell_type": "code",
622+
"execution_count": null,
623+
"metadata": {},
624+
"outputs": [],
625+
"source": [
626+
"print(df_students.groupby(df_students.Pass).Name.count())"
627+
]
628+
},
629+
{
630+
"cell_type": "markdown",
631+
"metadata": {},
632+
"source": [
633+
"You can aggregate multiple fields in a group using any available aggregation function. For example, you can find the mean study time and grade for the groups of students who passed and failed the course."
634+
]
635+
},
636+
{
637+
"cell_type": "code",
638+
"execution_count": null,
639+
"metadata": {},
640+
"outputs": [],
641+
"source": [
642+
"print(df_students.groupby(df_students.Pass)['StudyHours', 'Grade'].mean())"
643+
]
644+
},
645+
{
646+
"cell_type": "markdown",
647+
"metadata": {},
648+
"source": [
649+
"DataFrames are amazingly versatile, and make it easy to manipulate data. Many DataFrame operations return a new copy of the DataFrame; so if you want to modify a DataFrame but keep the existing variable, you need to assign the result of the operation to the existing variable. For example, the following code sorts the student data into descending order of Grade, and assigns the resulting sorted DataFrame to the original **df_students** variable."
616650
]
617651
},
618652
{
@@ -1072,6 +1106,28 @@
10721106
"cell_type": "markdown",
10731107
"metadata": {},
10741108
"source": [
1109+
"In thie example, the datadt is small enough to clearly see that the value **1** is an outlier for the **StudyHours** column, so you can exclude it explicitly. In most real-world cases, it's easier to consider outliers as being values that fall below or above percentiles within which most of the data lie. For example, the following code uses the Pandas **quantile** function to exclude observations below the 0.01th percentile (the value above which 99% of the data reside)."
1110+
]
1111+
},
1112+
{
1113+
"cell_type": "code",
1114+
"execution_count": null,
1115+
"metadata": {},
1116+
"outputs": [],
1117+
"source": [
1118+
"q01 = df_students.StudyHours.quantile(0.01)\n",
1119+
"# Get the variable to examine\n",
1120+
"col = df_students[df_students.StudyHours>q01]['StudyHours']\n",
1121+
"# Call the function\n",
1122+
"show_distribution(col)"
1123+
]
1124+
},
1125+
{
1126+
"cell_type": "markdown",
1127+
"metadata": {},
1128+
"source": [
1129+
"> **Tip**: You can also eliminate outliers at the upper end of the distribution by defining a threshold at a high percentile value - for example, you could use the **quantile** function to find the 0.99 percentile below which 99% of the data reside.\n",
1130+
"\n",
10751131
"With the outliers removed, the box plot shows all data within the four quartiles. Note that the distribution is not symmetric like it is for the grade data though - there are some students with very high study times of around 16 hours, but the bulk of the data is between 7 and 13 hours; The few extremely high values pull the mean towards the higher end of the scale.\n",
10761132
"\n",
10771133
"Let's look at the density for this distribution."
@@ -1471,7 +1527,13 @@
14711527
"\n",
14721528
"- [NumPy](https://numpy.org/doc/stable/)\n",
14731529
"- [Pandas](https://pandas.pydata.org/pandas-docs/stable/)\n",
1474-
"- [Matplotlib](https://matplotlib.org/contents.html)"
1530+
"- [Matplotlib](https://matplotlib.org/contents.html)\n",
1531+
"\n",
1532+
"## Challenge: Analyze Flight Data\n",
1533+
"\n",
1534+
"If this notebook has inspired you to try exploring data for yourself, why not take on the challenge of a real-world dataset containing flight records from the US Department of Transportation? You'll find the challenge in the [/challenges/01 - Flights Challenge.ipynb](./challenges/01%20-%20Flights%20Challenge.ipynb) notebook!\n",
1535+
"\n",
1536+
"> **Note**: The time to complete this optional challenge is not included in the estimated time for this exercise - you can spend as little or as much time on it as you like!"
14751537
]
14761538
}
14771539
],

02 - Regression.ipynb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"\n",
2424
"In this notebook, we'll focus on *regression*, using an example based on a real study in which data for a bicycle sharing scheme was collected and used to predict the number of rentals based on seasonality and weather conditions. We'll use a simplified version of the dataset from that study.\n",
2525
"\n",
26+
"> **Citation**: The data used in this exercise is derived from [Capital Bikeshare](https://www.capitalbikeshare.com/system-data) and is used in accordance with the published [license agreement](https://www.capitalbikeshare.com/data-license-agreement).\n",
27+
"\n",
2628
"## Explore the Data\n",
2729
"\n",
2830
"The first step in any machine learning project is to explore the data that you will use to train a model. The goal of this exploration is to try to understand the relationships between its attributes; in particular, any apparent correlation between the *features* and the *label* your model will try to predict. This may require some work to detect and fix issues in the data (such as dealing with missing values, errors, or outlier values), deriving new feature columns by transforming or combining existing features (a process known as *feature engineering*), *normalizing* numeric features (values you can measure or count) so they're on a similar scale, and *encoding* categorical features (values that represent discrete categories) as numeric indicators.\n",
@@ -740,15 +742,23 @@
740742
"\n",
741743
"### Encoding categorical variables\n",
742744
"\n",
743-
"achine learning models work best with numeric features rather than text values, so you generally need to convert categorical features into numeric representations. A common technique is to use *one hot encoding* to create individual binary (0 or 1) features for each possible category value. For example, suppose your data includes the following categorical feature.\n",
745+
"achine learning models work best with numeric features rather than text values, so you generally need to convert categorical features into numeric representations. For example, suppose your data includes the following categorical feature. \n",
744746
"\n",
745747
"| Size |\n",
746748
"| ---- |\n",
747749
"| S |\n",
748750
"| M |\n",
749751
"| L |\n",
750752
"\n",
751-
"You could use one-hot encoding to translate the possible categories into binary columns like this:\n",
753+
"You can apply *ordinal encoding* to substitute a unique integer value for each category, like this:\n",
754+
"\n",
755+
"| Size |\n",
756+
"| ---- |\n",
757+
"| 0 |\n",
758+
"| 1 |\n",
759+
"| 2 |\n",
760+
"\n",
761+
"Another common technique is to use *one hot encoding* to create individual binary (0 or 1) features for each possible category value. For example, you could use one-hot encoding to translate the possible categories into binary columns like this:\n",
752762
"\n",
753763
"| Size_S | Size_M | Size_L |\n",
754764
"| ------- | -------- | -------- |\n",
@@ -960,18 +970,15 @@
960970
"cell_type": "markdown",
961971
"metadata": {},
962972
"source": [
963-
"## Learn More\n",
973+
"## Further Reading\n",
964974
"\n",
965-
"To learn more about Scikit-Learn, see the [Scikit-Learn documentation](https://scikit-learn.org/stable/user_guide.html)."
966-
]
967-
},
968-
{
969-
"cell_type": "markdown",
970-
"metadata": {},
971-
"source": [
972-
"## Citation\n",
975+
"To learn more about Scikit-Learn, see the [Scikit-Learn documentation](https://scikit-learn.org/stable/user_guide.html).\n",
976+
"\n",
977+
"## Challenge: Predict Real Estate Prices\n",
978+
"\n",
979+
"Think you're ready to create your own regression model? Try the challenge of predicting real estate property prices in the [/challenges/02 - Real Estate Regression Challenge.ipynb](./challenges/02%20-%20Real%20Estate%20Regression%20Challenge.ipynb) notebook!\n",
973980
"\n",
974-
"The data used in this exercise is derived from [Capital Bikeshare](https://www.capitalbikeshare.com/system-data) and is used in accordance with the published [license agreement](https://www.capitalbikeshare.com/data-license-agreement)."
981+
"> **Note**: The time to complete this optional challenge is not included in the estimated time for this exercise - you can spend as little or as much time on it as you like!"
975982
]
976983
}
977984
],

03 - Classification.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,15 @@
11711171
"cell_type": "markdown",
11721172
"metadata": {},
11731173
"source": [
1174-
"## Learn More\n",
1174+
"## Further Reading\n",
11751175
"\n",
1176-
"Classification is one of the most common forms of machine learning, and by following the basic principles we've discussed in this notebook you should be able to train and evaluate classification models with scikit-learn. It's worth spending some time investigating classification algorithms in more depth, and a good starting point is the [Scikit-Learn documentation](https://scikit-learn.org/stable/user_guide.html)."
1176+
"Classification is one of the most common forms of machine learning, and by following the basic principles we've discussed in this notebook you should be able to train and evaluate classification models with scikit-learn. It's worth spending some time investigating classification algorithms in more depth, and a good starting point is the [Scikit-Learn documentation](https://scikit-learn.org/stable/user_guide.html).\n",
1177+
"\n",
1178+
"## Challenge: Classify Wines\n",
1179+
"\n",
1180+
"Feel like challenging yourself to train a classification model? Try the challenge in the [/challenges/03 - Wine Classification Challenge.ipynb](./challenges/03%20-%20Wine%20Classification%20Challenge.ipynb) notebook to see if you can classify wines into their grape varietals!\n",
1181+
"\n",
1182+
"> **Note**: The time to complete this optional challenge is not included in the estimated time for this exercise - you can spend as little or as much time on it as you like!"
11771183
]
11781184
}
11791185
],

04 - Clustering.ipynb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,23 @@
291291
"cell_type": "markdown",
292292
"metadata": {},
293293
"source": [
294-
"In this notebook, you've explored clustering; an unsupervised form of machine learning.\n",
294+
"## Further Reading\n",
295295
"\n",
296-
"To learn more about clustering with scikit-learn, see the [scikit-learn documentation](https://scikit-learn.org/stable/modules/clustering.html)."
296+
"To learn more about clustering with scikit-learn, see the [scikit-learn documentation](https://scikit-learn.org/stable/modules/clustering.html).\n",
297+
"\n",
298+
"## Further Reading\n",
299+
"\n",
300+
"To learn more about the Python packages you explored in this notebook, see the following documentation:\n",
301+
"\n",
302+
"- [NumPy](https://numpy.org/doc/stable/)\n",
303+
"- [Pandas](https://pandas.pydata.org/pandas-docs/stable/)\n",
304+
"- [Matplotlib](https://matplotlib.org/contents.html)\n",
305+
"\n",
306+
"## Challenge: Cluster Unlabelled Data\n",
307+
"\n",
308+
"Now that you've seen how to create a clustering model, why not try for yourself? You'll find a clustering challenge in the [/challenges/04 - Clustering Challenge.ipynb](./challenges/04%20-%20Clustering%20Challenge.ipynb) notebook!\n",
309+
"\n",
310+
"> **Note**: The time to complete this optional challenge is not included in the estimated time for this exercise - you can spend as little or as much time on it as you like!"
297311
]
298312
}
299313
],

05b - Convolutional Neural Networks (PyTorch).ipynb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,15 @@
539539
"cell_type": "markdown",
540540
"metadata": {},
541541
"source": [
542-
"In this notebook, you used PyTorch to train an image classification model based on a convolutional neural network."
542+
"## Further Reading\n",
543+
"\n",
544+
"To learn more about training convolutional neural networks with PyTorch, see the [PyTorch documentation](https://pytorch.org/).\n",
545+
"\n",
546+
"## Challenge: Safari Image Classification\n",
547+
"\n",
548+
"Hopefully this notebook has shown you the main steps in training and evaluating a CNN. Why not put what you've learned into practice with our Safari image classification challenge in the [/challenges/05 - Safari CNN Challenge.ipynb](./challenges/05%20-%20Safari%20CNN%20Challenge.ipynb) notebook?\n",
549+
"\n",
550+
"> **Note**: The time to complete this optional challenge is not included in the estimated time for this exercise - you can spend as little or as much time on it as you like!"
543551
]
544552
}
545553
],

05b - Convolutional Neural Networks (Tensorflow).ipynb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,15 @@
396396
"cell_type": "markdown",
397397
"metadata": {},
398398
"source": [
399-
"In this notebook, you used Tensorflow to train an image classification model based on a convolutional neural network."
399+
"## Further Reading\n",
400+
"\n",
401+
"To learn more about training convolutional neural networks with TensorFlow, see the [TensorFlow documentation](https://www.tensorflow.org/overview).\n",
402+
"\n",
403+
"## Challenge: Safari Image Classification\n",
404+
"\n",
405+
"Hopefully this notebook has shown you the main steps in training and evaluating a CNN. Why not put what you've learned into practice with our Safari image classification challenge in the [/challenges/05 - Safari CNN Challenge.ipynb](./challenges/05%20-%20Safari%20CNN%20Challenge.ipynb) notebook?\n",
406+
"\n",
407+
"> **Note**: The time to complete this optional challenge is not included in the estimated time for this exercise - you can spend as little or as much time on it as you like!"
400408
]
401409
}
402410
],
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Flights Data Exploration Challenge\n",
8+
"\n",
9+
"In this challge, you'll explore a real-world dataset containing flights data from the US Department of Transportation.\n",
10+
"\n",
11+
"Let's start by loading and viewing the data."
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"import pandas as pd\n",
21+
"\n",
22+
"df_flights = pd.read_csv('data/flights.csv')\n",
23+
"df_flights.head()"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"metadata": {},
29+
"source": [
30+
"The dataset contains observations of US domestic flights in 2013, and consists of the following fields:\n",
31+
"\n",
32+
"- **Year**: The year of the flight (all records are from 2013)\n",
33+
"- **Month**: The month of the flight\n",
34+
"- **DayofMonth**: The day of the month on which the flight departed\n",
35+
"- **DayOfWeek**: The day of the week on which the flight departed - from 1 (Monday) to 7 (Sunday)\n",
36+
"- **Carrier**: The two-letter abbreviation for the airline.\n",
37+
"- **OriginAirportID**: A unique numeric identifier for the departure aiport\n",
38+
"- **OriginAirportName**: The full name of the departure airport\n",
39+
"- **OriginCity**: The departure airport city\n",
40+
"- **OriginState**: The departure airport state\n",
41+
"- **DestAirportID**: A unique numeric identifier for the destination aiport\n",
42+
"- **DestAirportName**: The full name of the destination airport\n",
43+
"- **DestCity**: The destination airport city\n",
44+
"- **DestState**: The destination airport state\n",
45+
"- **CRSDepTime**: The scheduled departure time\n",
46+
"- **DepDelay**: The number of minutes departure was delayed (flight that left ahead of schedule have a negative value)\n",
47+
"- **DelDelay15**: A binary indicator that departure was delayed by more than 15 minutes (and therefore considered \"late\")\n",
48+
"- **CRSArrTime**: The scheduled arrival time\n",
49+
"- **ArrDelay**: The number of minutes arrival was delayed (flight that arrived ahead of schedule have a negative value)\n",
50+
"- **ArrDelay15**: A binary indicator that arrival was delayed by more than 15 minutes (and therefore considered \"late\")\n",
51+
"- **Cancelled**: A binary indicator that the flight was cancelled\n",
52+
"\n",
53+
"Your challenge is to explore the flight data to analyze possible factors that affect delays in departure or arrival of a flight.\n",
54+
"\n",
55+
"1. Start by cleaning the data.\n",
56+
" - Identify any null or missing data, and impute appropriate replacement values.\n",
57+
" - Identify and eliminate any outliers in the **DepDelay** and **ArrDelay** columns.\n",
58+
"2. Explore the cleaned data.\n",
59+
" - View summary statistics for the numeric fields in the dataset.\n",
60+
" - Determine the distribution of the **DepDelay** and **ArrDelay** columns.\n",
61+
" - Use statistics, aggregate functions, and visualizations to answer the following questions:\n",
62+
" - *What are the average (mean) departure and arrival delays?*\n",
63+
" - *How do the carriers compare in terms of arrival delay performance?*\n",
64+
" - *Is there a noticable difference in arrival delays for different days of the week?*\n",
65+
" - *Which departure airport has the highest average departure delay?*\n",
66+
" - *Do **late** departures tend to result in longer arrival delays than on-time departures?*\n",
67+
" - *Which route (from origin airport to destination airport) has the most **late** arrivals?*\n",
68+
" - *Which route has the highest average arrival delay?*\n",
69+
" \n",
70+
"Add markdown and code cells as required to create your solution.\n",
71+
"\n",
72+
"> **Note**: There is no single \"correct\" solution. A sample solution is provided in [01 - Flights Challenge.ipynb](01%20-%20Flights%20Solution.ipynb)."
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {},
79+
"outputs": [],
80+
"source": [
81+
"# Your code to explore the data"
82+
]
83+
}
84+
],
85+
"metadata": {
86+
"kernelspec": {
87+
"display_name": "Python 3.6 - AzureML",
88+
"language": "python",
89+
"name": "python3-azureml"
90+
},
91+
"language_info": {
92+
"codemirror_mode": {
93+
"name": "ipython",
94+
"version": 3
95+
},
96+
"file_extension": ".py",
97+
"mimetype": "text/x-python",
98+
"name": "python",
99+
"nbconvert_exporter": "python",
100+
"pygments_lexer": "ipython3",
101+
"version": "3.6.9"
102+
}
103+
},
104+
"nbformat": 4,
105+
"nbformat_minor": 4
106+
}

0 commit comments

Comments
 (0)