Public, Licensed and Synthetic Data
Not all data comes from your own systems. Three other sources are common: public datasets published by researchers and organisations, licensed data bought or obtained under contract, and synthetic data that you generate yourself. Each one saves time and each one comes with conditions, legal and statistical, that decide whether a model built on it is usable.
Public research datasets
Thousands of datasets are published for research and teaching: the UCI Machine Learning Repository, OpenML, Kaggle, the Hugging Face Hub, government open-data portals, and the large benchmarks such as ImageNet, COCO, Common Voice or Wikipedia dumps. The small classics also ship inside scikit-learn, which is why this course can use them offline:
from sklearn.datasets import load_iris, load_wine, load_breast_cancer, load_digits
for loader in [load_iris, load_wine, load_breast_cancer, load_digits]:
ds = loader()
n, d = ds.data.shape
title = next(line.strip() for line in ds.DESCR.splitlines()
if line.strip() and not line.startswith("..") and set(line.strip()) != {"-"})
print(f"{loader.__name__:20} n={n:5} d={d:3} classes={len(ds.target_names):2} {title}")load_iris n= 150 d= 4 classes= 3 Iris plants dataset
load_wine n= 178 d= 13 classes= 3 Wine recognition dataset
load_breast_cancer n= 569 d= 30 classes= 2 Breast cancer Wisconsin (diagnostic) dataset
load_digits n= 1797 d= 64 classes=10 Optical recognition of handwritten digits dataset
Each dataset comes with a description (ds.DESCR) that names its origin, the people who collected it and the papers to cite. Read it: the breast cancer data, for example, describes features computed from images of cell nuclei from one hospital in Wisconsin, so a model trained on it says little about other hospitals or imaging methods.
Before you use any public dataset, answer five questions:
| Question | Why |
|---|---|
| What is the licence? | it decides what you may do (see below) |
| Who collected it, how, and when? | tells you about bias and age: a 1990s dataset describes the 1990s |
| How were the labels made? | crowd labels on benchmarks have known error rates of a few percent |
| Did the people in it consent? | scraped faces and voices raise legal and ethical problems even when they are "public" |
| Is it in my evaluation data already? | a pretrained model may have seen a public test set during training (contamination), which inflates scores |
Licences in practice
"Publicly available" does not mean "free to use for anything". Common licences for data:
| Licence | You may | Conditions |
|---|---|---|
| CC0 / public domain | anything | none |
| CC BY 4.0 | use, share, adapt, also commercially | give credit (attribution) |
| CC BY-SA 4.0 | the same | credit, and share adaptations under the same licence |
| CC BY-NC | use and adapt | non-commercial only |
| ODbL (databases, e.g. OpenStreetMap) | use and adapt | credit; share-alike for derived databases |
| "research only" / custom terms | what the terms say | often no commercial use, no redistribution |
| no licence stated | legally, very little | ask the owner; do not assume it is free |
Whether training a model counts as "using" or "adapting" a dataset, and what a model trained on non-commercial data may be used for, are questions where the law is still developing and differs between countries. In a company, such questions go to the legal team before the data is used, and the answer is recorded with the dataset.
Licensed data
Companies also buy or license data: market data, credit bureau data, satellite imagery, medical records from partner hospitals, data from a vendor's devices. A contract typically fixes:
- the purpose the data may be used for (and often that it may not train models sold to others);
- who may access it, and where it may be stored (country, cloud);
- how long you may keep it, and what happens at the end (deletion, including from derived datasets);
- attribution, exclusivity and audit rights.
These conditions travel with the data: record them in the dataset's metadata and catalog entry so that a colleague who finds the files in two years knows them too.
Synthetic data
Synthetic data is generated rather than collected: by simulation (a physics engine rendering images of products, a traffic simulator), by rules, or by a model fitted to real data (from simple per-class distributions up to generative networks). It is useful when real data is scarce, expensive to label, or too sensitive to share, and for rare cases (fraud, accidents) that you can generate on purpose.
scikit-learn's make_* functions create synthetic datasets with known structure, ideal for teaching and testing code:
from collections import Counter
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=1000, n_features=6, n_informative=3, n_redundant=1,
weights=[0.9, 0.1], flip_y=0.02, random_state=0)
print("shape:", X.shape, "| classes:", dict(Counter(y.tolist())))shape: (1000, 6) | classes: {0: 893, 1: 107}
Here you control everything, including the imbalance (weights) and the share of randomly flipped labels (flip_y): exactly the problems the quality lessons of this course detect.
A synthetic copy of a real dataset is only as good as the generator. The standard test is train on synthetic, test on real (TSTR): fit a model on synthetic data and score it on held-out real data. Here the generator is deliberately simple: for each wine class it draws samples from a normal distribution with the class's real feature means and standard deviations, but treats the features as independent:
import numpy as np
from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X, y = load_wine(return_X_y=True)
X_real, X_test, y_real, y_test = train_test_split(X, y, test_size=0.4, random_state=0, stratify=y)
rng = np.random.default_rng(0)
X_syn, y_syn = [], []
for c in np.unique(y_real):
Xc = X_real[y_real == c]
X_syn.append(rng.normal(Xc.mean(axis=0), Xc.std(axis=0), size=(len(Xc), X.shape[1])))
y_syn += [c] * len(Xc)
X_syn = np.vstack(X_syn)
def score(X_train, y_train):
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
return model.fit(X_train, y_train).score(X_test, y_test)
print("real test samples:", len(y_test))
print("train on real, test on real: ", round(score(X_real, y_real), 3))
print("train on synthetic, test on real:", round(score(X_syn, y_syn), 3))
corr_real = np.corrcoef(X_real[y_real == 0].T)[0, 12]
corr_syn = np.corrcoef(X_syn[np.array(y_syn) == 0].T)[0, 12]
print(f"class 0, corr(alcohol, proline): real {corr_real:.2f}, synthetic {corr_syn:.2f}")real test samples: 72
train on real, test on real: 0.986
train on synthetic, test on real: 0.944
class 0, corr(alcohol, proline): real 0.29, synthetic -0.16
Trained on the 106 real training wines, the model scores 0.986 on the 72 real test wines; trained on 106 synthetic wines, 0.944. That is close, because the three cultivars differ mainly in their feature averages, which the generator copies. On data where the classes differ in how features move together, rather than in their averages, the gap can be much larger. The last line shows what the simple generator lost: real features are correlated, and independent sampling erases those correlations. Better generators (Gaussian copulas, Bayesian networks, generative models) keep more structure, but the rule stays: synthetic data cannot contain information that the generator did not capture.
Synthetic data is not automatically private either. A generative model can memorise and reproduce real records, especially rare ones. If privacy is the reason for generating data, test for near-copies of real records and consider formal methods such as differential privacy.
Pitfalls
- Licence by assumption: "it was on the internet" is not a licence. Record the licence of every source.
- Old or narrow public data: check when, where and from whom it was collected before trusting it for your population.
- Benchmark contamination: public test sets may be in a pretrained model's training data.
- Sim-to-real gap: models trained on synthetic data can fail on real data. Always evaluate on real data.
- Synthetic = anonymous: not necessarily; check for memorised records.
Practice
- A dataset of street photos is licensed CC BY-NC 4.0. Your start-up wants to train a model on it and sell the model's predictions. What do you do?
Answer
Treat it as not allowed until your legal advisers say otherwise: the NC (non-commercial) condition forbids commercial use, and a paid service is commercial. Look for a commercially licensed alternative, license the data from the owner, or collect your own.
- Why does a synthetic dataset made with
make_classification(flip_y=0.02)have about 1% wrong labels rather than 2%?
Answer
flip_y assigns a random class to that share of the samples, and with two classes about half of those random draws hit the correct class anyway. So roughly 2% / 2 = 1% end up wrong.
Test yourself
A dataset has no licence file. What may you assume?
- It is public domain
- It is CC BY
- Nothing: without a licence you have very few rights to it, so ask the owner
- It is free for research and commercial use
What does CC BY-SA require when you publish an adapted version of a dataset?
- Nothing
- Credit only
- Credit and the same licence for your adaptation
- Payment to the author
What does 'train on synthetic, test on real' measure?
- How fast the generator is
- Whether a model trained only on synthetic data works on real held-out data
- Whether the synthetic data is private
- The size of the synthetic dataset
Why is benchmark contamination a problem?
- It makes datasets bigger
- A model that saw the test set during pretraining gets an inflated, misleading score
- It changes the licence
- It removes labels