Machine learning is based on probabilistic methods. The objective of a machine learning model is to define the probability distribution of the data used to accomplish a task. Once this distribution is known, it’s possible to predict the probability value for new data with respect to this task.
When it comes to probabilities, in order to build the probability distribution of the data one needs a training dataset representative of the real dataset. This dataset also needs to have a sufficiently large amount of data to apply the law of large numbers: "if an experiment is repeated a large number of times, the frequency of occurrence of an event then becomes close to its probability of occurrence" [1].
In addition, in order to maintain a good performance when processing new data to ensure the model "generalizes well", learning strategies are put in place.
In this article, we define data quality and introduce you to the methods and tools to implement and measure it.
Constitution of the dataset
This stage of a data analysis project is crucial. The quality of the dataset depends on the quality of the model.
What do we mean by "data quality"?
Training datasets are a sample of the real data. With sampling theory, the main concerns are:
- the ability to capture the variability of the studied phenomenon
- the absence of bias or systematic error
- the relationship between sample size and the confidence that can be placed in the generalization of the results [2]
The first two concerns result in a mean and variance of the learning sample close to those of the actual data. The last concern translates into collecting sufficient data to apply the law of large numbers, which is the basis of probability theory.
The first step in building the dataset is to define the use of the model:
- What data will it eventually process?
- What task will it have to accomplish?
- What will be the context in which the model will be used?
For example, in the case of a project to develop a classification algorithm of CT images of the Thorax-Abdomen-Pelvis area, using the same scanner from a clinic:
- the data to be processed are CT images from the general population
- the task is to determine whether the images represent the Thorax-Abdomen-Pelvis zone or not
- the use of the algorithm will be restricted to one clinic and on images from a single scanner
The dataset will therefore have to be composed of CT images from the general population. These images should represent in balanced proportion the Thorax-Abdomen-Pelvis area and the other areas of the human body. They should be collected from the same scanner, but should have variability in the values of the image capture parameters (e.g. windowing) so that the algorithm is robust to them.
Data model quality
In machine learning, the best model is the one that obtains the best bias-variance trade-off. The validation of the quality of the model is based on the study of performance metrics that calculate these indicators. These performance metrics make sense if the model is isolated from the data according to the learning phase.
The bias-variance trade-off
In statistics, a machine learning model can calculate erroneous probabilities due to two types of errors: bias and variance.
- Bias is the error due to the fact that the model failed to extract the most discriminating characteristics from the data. Without these "essential" characteristics, it’s unable to analyze current data or new data. The model deviates, this is called under-fitting.
- Variance is the error due to the fact that the model extracted non-discriminatory characteristics from the data. It’s sensitive to small fluctuations in the data set. The model doesn’t generalize, this is called over-fitting.
Here we see that to solve one, we must degrade the other:
- If the model is unbiased, then it has extracted all the characteristics of the dataset. It perfectly defines the function of the training data, including random noise. However, it is unable to process new data outside the training dataset (i.e. zero variance).
- Similarly, if the model has a large variance, then it has extracted few discriminating characteristics from the training data set. It constructed a function of the data which is dissimilar to the function of the training dataset (i.e. very large bias).
The bias-variance trade-off emerges when one wishes to minimize both types of errors simultaneously to obtain a model that generalizes well with new data.
Isolation of the model from the data according to the training phases
The confirmation of the quality of the model is based on the study of performance metrics. These performance metrics make sense if the model is isolated from the data according to the training phase. More specifically, the initial data set must be separated into two (or even three) parts.
The model infers the probability distribution of the data from training datasets. To attest to the quality of this model, it must be validated from data that it did not analyze in the parameter estimation phase (i.e. the training phase): the validation dataset. With deep learning methods, a third dataset is commonly used to test the final model: the test dataset.
There are several validation strategies:
- Holdout method: Generally, the separation of the dataset is done according to the following proportions:
- 70% training dataset
- 30% validation dataset
When a test dataset is also present, the proportions are divided into:
- 70% training dataset,
- 20% validation dataset,
- 10% test dataset - Cross-validation method:
- k-fold method
The initial dataset is divided into k parts, often k = 5. The model is trained with data from 4 parts of the dataset, and the fifth part is used as a validation dataset. This process is repeated 4 times so that each part is used as a validation dataset once.
At the end of the procedure we obtain k performance measures, one for each part of the initial dataset. The mean and standard deviation of the k performance measures can be calculated to estimate the bias and variance of the validation performance.
- n-fold method (or "leave-one-out method")
This method has a similar approach to the k-fold method. The difference lies in the number of cuts made on the initial dataset. The nth element of the dataset is used for model validation and the n-1 elements for model training. The process is repeated n times, so that all elements of the dataset have been used for model validation.
Définition of performance metrics
The performance metrics of the model used to measure its quality (i.e. its ability to generalize) are based on two statistical indicators: variance and bias.
Among the most commonly used metrics for any learning task and domain are:
- precision (or positive predictive value) is the number of correct positive results divided by the number of positive results predictive by the model. Formally, it is written:
tp being the number of "true positive" (i.e. data correctly classified by the model as belonging to the positive class) and fp the number of "false positive" (i.e. data misclassified by the model as belonging to the positive class, whereas they belong to the negative class);
- sensitivity (or recall) is the proportion of data that is correctly classified as positive relative to the total positive data in the dataset. Formally:
fn being the number of "false negative" (i.e. data misclassified by the model as belonging to the negative class, whereas they belong to the positive class)
- specificity is the proportion of data correctly classified as negative relative to the total negative data in the dataset. Formally:
tn being the number of "true negative" (i.e. data correctly classified by the model as belonging to the negative class);
- the F1 score: harmonic mean of precision and recall. Formally:
These measurements are based on the notions of true-positive, true-negative, false-positive and false-negative. For example, an image classification model to determine if it is a representation of the Thorax-Abdomen-Pelvis area (TAP):
- the image is a true positive if the model classifies it as a representation of the TAP zone and it really is;
- the image is a true negative if the model classifies it as not being a representation of the TAP zone and it really isn’t;
- the image is a false positive if the model classifies it as a representation of the TAP area, but really it isn’t;
- the image is a false negative if the model classifies it as not being a representation of the TAP area, but it really is.
In medical image analysis, for object detection and segmentation tasks, the DICE coefficient is used to measure the similarity between the annotations (bounding box, binary mask) proposed by the model and those of the observation. Formally, in the case of any finite X and Y sets, written:
s = 2.|X|∩|Y| / |X|+|Y|
|X| being the number of elements of X and |Y| the number of elements of Y. It takes the value 0 when the two sets X and Y are disjoint, and the value 1 when they are equal.
The loss function of a model is also a measure of its performance, but it intervenes during the learning process to refine the parameter estimates. In contrast to the above-mentioned functions, which intervene a posteriori of the estimation as a final validation of the quality of the model.
The loss function calculates the deviation (or error) between the model's estimated value and the observation. The choice of the type of function depends on the learning task. For regression tasks, the following 4 are available [3]:
- the Sum of Squared Errors (SCR), where squares are measured, so the importance of large errors is increased. Formally written:
y being the observation, ŷ the estimated value and n the total number of observations;
- the Mean Absolute Error (MAE), is the calculation of the arithmetic mean of the absolute values of the deviations. Formally:
ŷ being the estimated value, y the observation and n the total number of observations;
- the Mean Squared Error (MSE), is the calculation of the arithmetic mean of the squares of the differences between model predictions and observations. The objective is its minimization to obtain a better model. Formally:
y being the observation, ŷ the estimated value and E the expectation;
- the Root Mean Squared Error (RMSE) is the square root of the mean squared of the errors
For classification tasks, the most common loss functions are those based on cross-entropy. They are suitable for discrete data.
Coming from the field of information theory, cross-entropy measures the overall difference between two probability distributions (the model prediction distribution, the observed distribution) for a random variable or a set of events [4]. Formally written:
ŷ being the estimated probability that x belongs to class i and y the observed probability that x belongs to class i, knowing that there are C classes.
Want to go deeper into the subject? Here are two more articles about learning strategies, how convolutional neural networks work and the most common architectures for medical image classification.