How to visualize cleaning issues

Problem statement

Exploratory data analysis (EDA) can be overwhelming. There are so many things to check. Duplicates in your dataset, bad/corrupted images in the set, blurred or bright/dark images, the list goes on.

DataEval created a data cleaning class to assist you with your EDA so you can start training your models on high quality data.

When to use

The cleaning class should be used during the initial EDA process or if you are trying to verify that you have the right data in your dataset.

What you will need

  1. A dataset to analyze

  2. A Python environment with the following packages installed:

    • dataeval

    • maite-datasets

Getting started

Let’s import the required libraries needed to set up a minimal working example

import polars as pl
from maite_datasets.image_classification import CIFAR10

from dataeval import Metadata
from dataeval.quality import Outliers

_ = pl.Config.set_tbl_rows(-1)

Loading in the data

We are going to start by loading in the CIFAR-10 dataset.

The CIFAR-10 dataset contains 60,000 images - 50,000 in the train set and 10,000 in the test set. For the purposes of this demonstration, we are just going to use the test set.

# Load in the CIFAR10 dataset
testing_dataset = CIFAR10("./data", image_set="test", download=True)

Cleaning the dataset

Now we can begin finding those images which are significantly different from the rest of the data.

# Initialize the Duplicates class
outliers = Outliers(outlier_method="zscore", outlier_threshold=3.5)

# Evaluate the data
results = outliers.evaluate(testing_dataset)

The results are a dictionary with the keys being the image that has an issue in one of the listed properties below:

  • Brightness

  • Blurriness

  • Missing

  • Zero

  • Width

  • Height

  • Size

  • Aspect Ratio

  • Channels

  • Depth

print(f"Total number of images with an issue: {len(results.aggregate_by_item())}")
Total number of images with an issue: 318
# View issues by metric
results.aggregate_by_metric()
shape: (11, 2)
metric_nameTotal
catu32
"entropy"148
"zeros"79
"kurtosis"78
"skew"51
"brightness"49
"contrast"41
"var"36
"mean"10
"std"3
"darkness"2
"sharpness"2
# View issues by class
results.aggregate_by_class(Metadata(testing_dataset))
shape: (11, 13)
class_namebrightnesscontrastdarknessentropykurtosismeansharpnessskewstdvarzerosTotal
catu32u32u32u32u32u32u32u32u32u32u32u32
"airplane"322064407132147190
"bird"6100241620814778
"cat"24185004051342
"automobile"050140000051135
"deer"17010700300735
"frog"05073001041434
"horse"04161000061028
"ship"5004511213123
"dog"2204000003718
"truck"1207100102216
"Total"49412148781025133679499