In this lesson we introduce the group project, its evaluation criteria and a submission example.

Binder slides

A guide to structuring your group projects

Summary: In your group projects you will solve a data science problem end-to-end, pretending to be recently hired data scientists in a company. To help you get started, we've prepared a checklist to guide you through the project. Here are the main steps that you will go through:

  1. Frame the problem and look at the big picture
  2. Get the data
  3. Explore and visualise the data to gain insights
  4. Prepare the data to better expose the underlying data patterns to machine learning algorithms
  5. Explore many different models and short-list the best ones
  6. Fine-tune your models
  7. Present your solution

In each step we list a set of questions that one should have in mind when undertaking a data science project. The list is not meant to be exhaustive, but does contain a selection of the most important questions to ask. We will be available to provide assitance with each of the steps, and will allocate some part of each lesson towards working on the projects.

Our expectations

To streamline the grading, your group must submit a single Jupyter notebook, structured in terms of the first 6 sections listed in this guide (the seventh will be presented to the class). You are welcome to adapt code from the web (e.g. Kaggle kernels), but you must reference the original source in your notebook.

In addition to clean, well-documented code (i.e. functions with docstrings etc), your notebook will be judged according to how well each step is explained (using Markdown). The main goal is to simulate what it is like to work as a data scientist, where communication is arguably as important as the ability to extract insights from data.

The analysis in the Jupyter notebook will be evaluated according to a rubric similar to the assignments:

Critical Task Needs Improvement Basic Surpassed
Computation: Perform computations Computations contain errors and extraneous code Computations are correct but contain extraneous/unnecessary computations Computations are correct and properly identified and labeled
Analysis: Choose and carry out analysis appropriate for data and context Choice of analysis is overly simplistic, irrelevant, or missing key components Analysis appropriate, but incomplete, or important features and assumptions not made explicit Analysis appropriate, complete, advanced, relevant, and informative
Synthesis: Identify key features of the analysis, and interpret results (including context) Conclusions are missing, incorrect, or not made based on results of analysis Conclusions reasonable, but is partially correct or partially complete Make relevant conclusions explicitly connected to analysis and to context
Visual presentation: Communicate findings graphically clearly, precisely, and concisely Inappropriate choice of plots; poorly labeled plots; plots missing Plots convey information correctly but lack context for interpretation Plots convey information correctly with adequate/appropriate reference information
Written: Communicate findings clearly, precisely, and concisely Explanation is illogical, incorrect, or incoherent Explanation is partially correct but incomplete or unconvincing Explanation is correct, complete, and convincing

Grading split: The group project accounts for 50% of the final grading and is split equally between the notebook (25%) and the presentation (25%).

Submission deadline: Wednesday, June 2, 2021 before 23:59:59 CEST (Notebook + presentation recording)

Presentation date: Wednesday, June 9, 2021 (Discussion of group projects with questions)

Deliverables

The teams have to submit two deliverables before the submission deadline: 1) a notebook and 2) presentation video.

Notebook

The notebook contains all the code to explore the dataset, train the final model and documents each step clearly. If code is copied from another codebase such as Github or Stack Overflow it must be properly referenced.

Presentation

The presentation video should be 15min long and should highlight the problem you are solving, interesting things you found in the data and the step involved in building up your model. On the presentation date we will discuss the presentation and ask questions about your project and submissions.

Some examples

The Kaggle competitions page has hundreds of examples where people have applied machine learning to solve a variety of problems. Below are a few examples that you might find useful:

The is also the excellent Kaggle Learn resource that you might find useful too.

1. Frame the problem and look at the big picture

  1. Define the objective in business terms
  2. How should you frame the problem (supervised/unsupervised etc.)?
  3. How should performance be measured?
  4. How would you solve the problem manually?
  5. List the assumption you and your team have made so far
  6. Verify your assumptions if possible

2. Get the data

  1. Find and document where you can get the data from
  2. Create a workspace. We like to structure our project folders as follows:
my-awesome-project
├── data
│   ├── external       <- Data from third party sources.
│   ├── interim        <- Intermediate data that has been transformed.
│   ├── processed      <- The final, canonical data sets for modeling.
│   └── raw            <- The original, immutable data dump.
│
├── notebooks          <- Jupyter notebooks. Naming convention is a number (for ordering),
│                         the creator's initials, and a short "-" delimited description, e.g.
│                         1.0-vwl-initial-data-exploration.
│
├── reports            <- Generated analysis as HTML, PDF, LaTeX, etc.
│   └── figures        <- Generated graphics and figures to be used in reporting
│
└── requirements.txt   <- The requirements file for reproducing the analysis environment.
  1. Once you and your team have agreed on the folder structure, we suggest creating a new virtual environment as follows in the root of my-awesome-project.
  2. Get the data
  3. Check the size and type of data (time series, geographical etc)

3. Explore the data

  1. Create a copy of the data for explorations (sampling it down to a manageable size if necessary)
  2. Create a Jupyter notebook to keep a record of your data exploration
  3. Study each feature and its characteristics:
    • Name
    • Type (categorical, int/float, bounded/unbounded, text, structured, etc)
    • Percentage of missing values
    • Check for outliers, rounding errors etc
  4. For supervised learning tasks, identify the target(s)
  5. Visualise the data
  6. Study the correlations between features
  7. Study how you would solve the problem manually
  8. Identify the promising transformations you may want to apply (e.g. convert skewed targets to normal via a log transformation)
  9. Document what you have learned

4. Prepare the data

Notes:

  • Work on copies of the data (keep the original dataset intact).
  • Write functions for all data transformations you apply, for three reasons:
    • So you can easily prepare the data the next time you run your code
    • So you can apply these transformations in future projects
    • To clean and prepare the test set
  1. Data cleaning:
    • Fix or remove outliers (optional)
    • Fill in missing values (e.g. with zero, mean, median, ...) or drop their rows (or columns)
  2. Feature selection (optional):
    • Drop the features that provide no useful information for the task (e.g. a customer ID is usually useless for modelling).
  3. Feature engineering, where appropriate:
    • Discretize continuous features
    • Add promising transformations of features (e.g. $\log(x)$, $\sqrt{x}$, $x^2$, etc)
    • Aggregate features into promising new features
  4. Feature scaling: standardise or normalise features

5. Short-list promising models

We expect you to do some additional research and train at least one model per team member. You use a Random Forest model, but each team memeber has to investigate one additional model. So you may want to investigate the following alternatives for regression:

  • Linear Regression
  • Extra Trees
  • Histogram-based Gradient Boosting Regression Tree.
  • Multi-layer Perceptron regressor
  • Elastic-Net

These additional models don't need to contribute to your final submission but there should for the individual models should be annotated with the student who created it. Each section should have the student name annotated. Each student should understand his model to the point where you can explain how it works and answer simple questions about it.

  1. Train mainy quick and dirty models from different categories (e.g. linear, SVM, Random Forests etc) using default parameters
  2. Measure and compare their performance
  3. Analyse the most significant variables for each algorithm
  4. Analyse the types of errors the models make
  5. Have a quick round of feature selection and engineering
  6. Have one or two more quick iterations of the five previous steps
  7. Short-list the top three to five most promising models, preferring models that make different types of errors

6. Fine-tune the system

  1. Fine-tune the hyperparameters
  2. Once you are confident about your final model, measure its performance on the test set to estimate the generalisation error

7. Present your solution

  1. Document what you have done
  2. Create a nice 15 minute video presentation with slides
    • Make sure you highlight the big picture first
  3. Explain why your solution achieves the business objective
  4. Don't forget to present interesting points you noticed along the way:
    • Describe what worked and what did not
    • List your assumptions and you model's limitations
  5. Ensure your key findings are communicated through nice visualisations or easy-to-remember statements (e.g. "the median income is the number-one predictor of housing prices")

References

The competition

Dataset

The dataset for the competition consists of a regression problem for music popularity. The data was scraped from the Spotify API and contains several features, such as the name of the song and how much accoustics is used in the song. In total there are 17 features in the dataset. The target for the competition is to predict the popularity of a song from these features. In total, the dataset contains 130'326 samples which are split into a train (9/10) and test (1/10) sets. The training data contains the feature a and label columns whereas the test set only contains the feature columns. The goal of the competition is to train a model on the training set and then use this model to predict the labels on the test set. A more detailed description of the data is available on the competition website.

Kaggle

The competition is organized as a Kaggle challenge. The data is available on the Kaggle page and you have to upload you model predictions on the Kaggle page. Your results will automatically be evaluated and you will see your scores as well as the scores of the other teams on the leaderboard. Note that the test set is split into two parts: 50% is used to evaluate your predictions every time you upload them. The remaining 50% of the test set are not evaluated until the competition finishes and is used to calculate the final score. This split aims at avoiding teams improving overfitting their models to the test set score. The number of team submissions per day are limited to 20. Therefore, make sure you distribute the work such that you can evaluate all your ideas during the competition.

Signup

Go to the Kaggle website and click on Register to create an account. Once you have set up your account go the the competition page and click on Teams. Invite your fellow team member and name your team according the the MS Teams names.

Submission

To upload your predictions store them as a csv file (see the sample_submission.csv for reference) and click on the Submit Predictions button on the competition page. Upload your submission in the dialog and add a short description of the steps that led these particular descriptions. After a few minutes you should see your score under My submissions and if its your best run also on the Leaderboard.

Example: The median regressor

Imports

import pandas as pd
from pathlib import Path

Load data

datapath = Path('../data/spotify')
train = pd.read_csv(datapath/'train.csv')
test = pd.read_csv(datapath/'test.csv')
train.shape, test.shape
((117293, 18), (13033, 17))
train.head()
artist_name track_id track_name acousticness danceability duration_ms energy instrumentalness key liveness loudness mode speechiness tempo time_signature valence popularity collection_date
0 Netherfriends 7luDJV4DDZmjH3QDdCqpcO Money Everyday 0.0722 0.790 186410 0.384 0.000002 7 0.1000 -11.201 1 0.2310 156.077 4 0.203 2 april-2019
1 Maxo Kream 1F09jtMfeYNkUj6piQjXwM ATW 0.1550 0.677 149967 0.747 0.000000 6 0.2390 -5.680 0 0.3180 153.921 4 0.371 41 april-2019
2 Drebae 2tR2VS8rAndKb0C5hS3IpD Trust in Me (feat. Allura) 0.2390 0.661 231732 0.625 0.000000 6 0.0971 -8.090 0 0.1010 132.899 4 0.385 9 april-2019
3 TWICE 1U3cHXWaa0FqlUWLLBL7Kz BRAND NEW GIRL 0.0160 0.674 213956 0.965 0.000096 7 0.1450 -3.754 1 0.0696 157.041 4 0.750 41 april-2019
4 Lisa Howard 1vAP99gg1HzuUUITxJPdyn Cheeseburger In Paradise 0.2810 0.607 228556 0.771 0.000005 2 0.2210 -5.106 1 0.1120 138.087 4 0.496 19 april-2019

Make predictions

In this example we build a simple model that just consists of the training set median of the target variable.

median = train['popularity'].median()
median
21.0

Predict on the test set

Normally you would then use the trained model to predict the target on the test set with .predict(X). Our simple model does not depend on the features so we can just assign the median value to all test samples.

submission = test[['track_id']].copy()
submission.head()
track_id
0 7rrY55kdGxRC65rfeeJkG0
1 0bLPm7gEeoNtn6R0YNAcBS
2 4pRyBsQtXo9nCkPjFQJmZT
3 6zngmeIx1bCRvgLM53NJ2e
4 01XKJqKTothbGn7VOzQcdb
submission['popularity'] = median
submission.head()
track_id popularity
0 7rrY55kdGxRC65rfeeJkG0 21.0
1 0bLPm7gEeoNtn6R0YNAcBS 21.0
2 4pRyBsQtXo9nCkPjFQJmZT 21.0
3 6zngmeIx1bCRvgLM53NJ2e 21.0
4 01XKJqKTothbGn7VOzQcdb 21.0

Save submission

Finally, we take the predictions on the test set and save them in a submission file.

submission.to_csv(datapath/'median_submission.csv', index=False)

You can now upload this file on the Kaggle competition webpage under Submit Prediction.