Notebooks
W
Weights and Biases
Train Val Test Split With Tabular Data

Train Val Test Split With Tabular Data

wandb-examplescolabswandb-artifacts

Open In Colab

Weights & Biases

Tabular Data Versioning and Deduplication with Weights & Biases

Weights & Biases

Introduction

This walkthrough focuses on using W&B to version control and iterate on tabular data. We will use Artifacts and Tables to load in a dataset and split it into train, validation, and test subsets. Thanks to the versioning capability of Artifacts, we will use minimal storage space and have persistent version labels to easily share dataset iterations with colleagues.

For this project, we will be working with tabular medical data that has great potential for predicting outcomes of heart attack patients. If you'd rather learn about similar features applied to classification tasks on image data, see this other example.

You can also find an overview report on this topic here.

About the data

Our dataset is a collection of measurements and survey answers from hospital patients that have heart attack-related symptoms. It's not a stretch to say datasets like these -- and the models built from them -- can improve patient outcomes and save lives. On a purely machine learning level, this particular dataset is interesting because it has:

  • Mixed types: entries can be binary, ordinal, numeric, or categorical
  • Missing data: almost all features have some fraction of missing data
  • Real-world complexity: feature values are not uniformly distributed and have outliers
  • Limited size: collecting data is difficult and so the dataset is small

Helper functions

Below we will keep all of our imports and helper functions. Reading through them is optional, and only recommended after you have looked over the rest of the report.

[ ]
[ ]
[ ]

The following list contains the data types for each feature in the Myocardial Infarction dataset.

More detailed information can be found via this pdf file

[ ]

Loading the dataset into an artifact

Our first step is to load in the dataset from a CSV file, which we accomplish with Artifacts and Tables. The wandb Artifact has two very useful features for our application: 1) it supports versioning, which will allow us to track changes we make to the original datset and 2) it supports deduplication, which will minimize the amount of storage space we use when generating modified versions of the dataset.

In the code below we use the python requests and csv libararies to load in each line of the CSV file into a wandb Table. Then we store the table in a wandb Artifact.

[ ]

Splitting the data into training, validation, and test sets

As is typical with most machine learning applications, we want to grab a majority of our data for training and use a smaller subset for validation and testing. The validation set will be used to help us tune our parameters and modify the preprocessing steps.

To avoid saving multiple copies of the dataset, we will only store corresponding indices for the train/val/test splits. This is also version controlled in case you decide you need more training data or you want to redo the shuffles.

[ ]

Packaging the data into PyTorch data loaders

Next we will package the data into a PyTorch DataLoader to make it easier to work with. The DataLoader includes a list of preprocessing steps that are to be performed on the data. We want to be able to iterate and version control preprocessing pipeline, so we also have to write some code to store it as an artifact.

[ ]

Done! Time to train

That concludes this part of the tutorial. In a future tutorial we will use this same data to train and iterate on our model. This will also use Artifacts to version control iterations on the preprocessing pipeline, parameters, and model architecture.