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: Thursday, May 28, 2020 before 23:59:59 CEST (Notebook + presentation recording)

Presentation date: Thursday, June 4, 2020 (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-ltu-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 car pricing. The data was scraped from eBay on contains several features, such as the age of the cars and the model type. In total there are 19 features in the dataset. The target for the competition is to predict the car price from these features. In total, the dataset contains 371'528 samples which are split into a train (2/3) and test (1/3) 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: 70% is used to evaluate your predictions every time you upload them. The remaining 30% 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/')
train = pd.read_csv(datapath/'train.csv')
test = pd.read_csv(datapath/'test.csv')
train.shape, test.shape
((248923, 21), (122541, 20))
train.head()
carId dateCrawled name seller offerType price abtest vehicleType yearOfRegistration gearbox ... model kilometer monthOfRegistration fuelType brand notRepairedDamage dateCreated nrOfPictures postalCode lastSeen
0 0 2016-04-01 18:39:16 Volvo_S80_2.4 privat Angebot 999 control limousine 1999 manuell ... andere 150000 9 benzin volvo ja 2016-04-01 00:00:00 0 26810 2016-04-05 14:16:56
1 1 2016-03-17 18:39:35 BMW_Kombi privat Angebot 900 control NaN 2017 manuell ... 3er 150000 2 NaN bmw nein 2016-03-17 00:00:00 0 27804 2016-03-23 07:17:16
2 2 2016-03-16 12:50:34 BMW_E39_525d_Exclusive_Automa_Vollausstattung_... privat Angebot 6700 test kombi 2004 automatik ... 5er 150000 2 diesel bmw nein 2016-03-16 00:00:00 0 12435 2016-03-22 12:50:21
3 3 2016-03-25 15:55:43 BMW_320d_DPF_Touring_Aut. privat Angebot 5500 test kombi 2006 automatik ... 3er 150000 10 diesel bmw nein 2016-03-25 00:00:00 0 4158 2016-04-06 20:16:52
4 4 2016-03-12 22:40:32 Schrott_Auto_Seat_Marbella_Altmetall_Schrottau... privat Angebot 16 control kleinwagen 1989 manuell ... andere 100000 10 benzin seat nein 2016-03-12 00:00:00 0 27755 2016-03-12 22:40:32

5 rows × 21 columns

Make predictions

In this example we build a simple model that just consists of the training set median of the target variable. This corresponds to the step where train your model with .fit(X, y).

median = train['price'].median()
median
2950.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 = pd.read_csv(datapath/'sample_submission.csv')
submission.head()
Id Predicted
0 248923 0
1 248924 0
2 248925 0
3 248926 0
4 248927 0
submission['Predicted'] = median
submission.head()
Id Predicted
0 248923 2950.0
1 248924 2950.0
2 248925 2950.0
3 248926 2950.0
4 248927 2950.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. The general procedure to fit a scikit-learn model and make a submission looks as follows:

# train model
X_train, y_train = train.drop('price', axis=1), train['price']
my_model.fit(X_train, y_train)

# predict on test set
y_pred = my_model.predict(test)

# create submission
submission['Prediction'] = y_pred
submission.to_csv(datapath/'median_submission.csv', index=False)