A dataset, in the context of machine learning, is a collection of data used as training or evaluation material for a model. The shape and content of a dataset varies widely depending on the learning technique, scope, purpose and architecture of the model and available resources. Datasets are commonly called learning or training sets when used for the learning phase and test sets when used for the assessment phase.
The word "set" can be a bit misleading because datasets are not traditional mathematical sets. This is because they may contain duplicates, which is disallowed by definition in sets. A set that allows duplicates is known as a multiset (or bag). Datasets are therefore multisets (or bags) of data.
Supervised learning#
In supervised machine learning, the dataset is composed of pairs of inputs and outputs:
where is an input, is an output and is the total number of examples pairs (the cardinality of the set, ). Indexes are written as superscript since inputs and outputs are usually vectors and this notation avoids conflict with component indexes.
In supervised learning sets, the dataset must be consistent with the domain and codomain of the prediction function to be learned. Formally, is an element of a space , where
- is the Cartesian product of the input and output spaces;
- is the power set of ;
- is the power set with duplicates of (a "multipowerset" if you prefer). It is the set of all possible multisets of .
A dataset can be seen as a matrix where each row is a input-output pair and each column is a component of the pair. For example, a dataset of pairs, where and is any one-dimensional variable, can be written as
Some common nomenclature about this matrix is
- Each row is an observation.
- Each column is a feature.
- Each cell is the value of the -th observation for the -th feature.
- Each is a response. If is a categorical variable, it's also called a class label.
Here is the number of independent variables and is the number of pairs in the dataset. Other common letters are for the variables and for the pairs. On the assumption that the dataset describes the whole problem, these quantities then define the "size" of the problem.
Unsupervised learning#
In unsupervised machine learning, the dataset is just a bag of inputs:
Balancing#
The distribution of the data inside the dataset is important in Classification. A dataset is said to be balanced with respect to the response variable if the frequency of each category in the dataset is roughly the same. In Binary classification specifically, this means that the dataset about half positive and half negative cases. This means that . We can make some considerations on the inherent accuracy of the dataset by expressing error rate through FPR and FNR:
On a balanced dataset, the error rate is the average of FPR and FNR. The accuracy is
The more unbalanced the dataset is, the further the accuracy or error diverges from this mean, making the model progressively more misleading if the only metric that is provided is error or accuracy. This is why FPR and FNR should be provided alongside the accuracy.
In Multiclass classification, the definition of balancing gets more complicate. In general, in unbalanced dataset it's common to use weighted accuracy (or balanced accuracy). It is defined as
It's the unweighted average of the accuracy of each class. It's called weighed because it ignores the exact amount of data points for each class, unlike usual accuracy. It is therefore resilient even in unbalanced datasets. As usual, the greater the better. This is the multiclass equivalent of .
Learning data, testing data#
Datasets aren't just used for training. Assessing the quality of a model is a necessary part of a machine learning pipeline and the assessment process also relies on data. A model is considered to work well if it predicts the same outcomes as the real world process it's modeling. In order to run test predictions, we need test data, and we also need some testing function that measures how effective the model is1. This function takes the learning technique and a dataset as input, and returns a numerical output representing the model's effectiveness. Formally
where is the effectiveness. Essentially, it trains a model on the dataset using the learning technique, then tests it, and finally returns the model's effectiveness. This function requires training the entire model every time it's used! Be mindful of this in the rest of this section.
There are arguments to be made regarding how to pick this test data. In principle, we could use the same dataset that we used to train the model, . But in practice, that's a bad idea. This is because this does not test the model's ability to generalize. Generalization is the model's ability to perform well on data that it did not see during its training, so-called unseen data. Testing on the training set will almost always give greatly exaggerated performance values.
Realistically, test data should never be present in the training set2. The data you have access to should be split in two parts: the training set and the test set . The ratio of data split between the two is up to you, but a common split is 70% training data, 30% test data. If you are short on training data, you can remove some test data to turn it into training data, but not too much. This process does measure generalization ability because the test data is unseen and is the standard way of doing model testing. It does however have a flaw: since the split is static, meaning it's decided once and never changed, it leads to this process having robustness issues. That means that the training/test data split might be "unlucky"; for example, if you're training a binary classifier and have an unbalanced dataset, you could end up with all positives in the train set and all negatives in the test set. The model will then not learn any negatives and the model will be a mess. Thus, care should be taken on how the data is split.
To improve robustness, we can instead run the test multiple times on randomized test sets. The randomization occurs times and the test is ran that many times, returning effectiveness values. The mean of these values is then taken. This is a more robust method, because it guarantees that the "unlucky data" factor is largely negligible, because the chance of getting unlucky datasets is minuscule. What you lose with this procedure is performance: you now have to run the test times, which might be difficult or unrealistic if the model is expensive to train.
A common technique is called cross-fold validation (CV). It is like repeated randomized tests, but it guarantees that each test set is disjoint from every other, meaning each iteration of the test uses entirely different data. Each test subset is called a fold. Each fold contains of the total data. This method improves the significance of each individual iteration, since it guarantees that each test is completely different from the previous ones.
An specific form of CV is leave-one-out CV (LOOCV). It is simply a CV where the number of folds is equal to the number of data points . Each fold then is just a single data point. Essentially, you run a test on a single piece of information for every single piece of information the model trained on, then average all the results. This is obviously extremely expensive computationally speaking, so it's only efficient for models that are very cheap and fast to train and/or have little data available.
Now, repeated random, CV and LOOCV all provide a sample of effectiveness results. We spoke of the mean before, but we can also compute other statistical properties, namely standard deviation. Where mean tells you how effective the model is on average, the standard deviation tells you how consistent the learning technique is on different datasets3. Once you start to see these values as statistical data, you can start to use all the tools of statistics to analyze how the model performs: for instance, you can draw a boxplot, run a hypothesis test, or more.
Hypothesis tests#
Hypothesis tests (or statistical significance tests) have an entire discipline of statistics revolving around. This section is a brief primer on them specifically for use in machine learning assessment.
A statistical significance test is a procedure that, given two samples and of two random variables and and a set of hypotheses (called the null hypothesis), it returns a number , called the -value. This value represents the probability that, by collecting other samples from the same random variables and assuming that still holds, the two new samples are more unlikely than the original two.
Let's make an example. Our samples are for and for . Our hypotheses are
- is normally-distributed.
- is normally-distributed.
- The means are identical, .
If we run the test and get , that means
- If you resample and , you are very likely to find samples that are less likely than the ones we started with, as long as holds.
- Thus, our samples are very likely (since others are almost certainly less so).
- Thus, I can assume that is probably true.
If we instead get , that means
- As before, but you are very unlikely to find less likely samples.
- Thus, our samples are very unlikely (since others are almost certainly more so).
- Thus, I can assume that is probably false.
- It's still possible that you got very unlucky with your samples and they returned a false negative. But it's unlikely.
In practice, there are many concrete significance test one can use. Two common ones are the Wilcoxon test and the Friedman test (and all their variations). What you do with them is pick one based on the you have (these often revolve around stating that or ), apply them to calculate , then hope it's as low as possible. You then compare it to an arbitrary threshold and hope that . If that's true, then the test is statistically significant.
For more, see Hypothesis test and Estimator > Confidence intervals.
Footnotes#
-
By "effective" we mean how good its predictions are. A perfectly effective model performs exactly like the real world. ↩
-
If the training set contains test data, that's commonly called contamination and it generally makes that test's results fake and exaggerated. ↩
-
In fact, we can do these for all performance indexes of the models trained during the tests. For instance, the mean and standard deviation of the AUC. ↩