Anomaly detection
Anomaly detection automatically flags data points, events, or patterns that do not fit normal behaviour. It can catch odd invoices, machine ...
Read definitionCross-validation estimates how well a model generalises by splitting the data into k folds, training on all but one and scoring on the fold left out, then rotating and averaging. It gives a steadier read than a single train-test split, with variants for imbalanced, grouped and time-ordered data.
Cross-validation estimates how well a machine learning model will perform on data it has not seen, by splitting the same dataset several ways and scoring each one. Instead of trusting a single held-out slice, you rotate which rows do the testing and average the results, so the number you report does not hinge on one lucky split.
It is a routine step in supervised learning. You fit a model on labelled examples and want an honest read on how it behaves on new records. A single train-test split gives one score from one arrangement of the data, and on a small dataset that score can swing a lot depending on which rows land in the test fold. Cross-validation uses the data more efficiently and shows that variance, though you still hold out a separate test set for the final number and to watch for model drift.
The most common form is k-fold. You split the rows into k equal folds and train k times. Each round holds one fold back for testing and trains on the other k-1, so every row is tested once and trained on k-1 times.
Say you have 500 rows and pick k of 5. That gives five folds of 100. Round one trains on folds 2 to 5 (400 rows) and scores on fold 1, round two trains on the rest and scores on fold 2, and so on. You end up with five scores: their average is your estimate, and their spread shows how stable it is.
Most teams use k of 5 or 10, and scikit-learn uses 5 folds by default. Higher k trains more models and costs more compute, which bites when each model is a slow neural network.
Plain random folds assume every row is independent. When that breaks, k-fold gives a misleading score and you need a different splitter.
Stratified k-fold. Each fold keeps roughly the same class proportions as the full dataset. If 5 percent of your rows are fraud cases, every fold keeps about that 5 percent instead of one fold drawing almost none. That is what you want under class imbalance, and scikit-learn uses it automatically for classifiers.
Grouped k-fold. When several rows belong to the same entity (one customer, one patient, one machine), they must stay in one fold. Otherwise the model sees patient A in both training and testing and looks better than it is. GroupKFold keeps each group on one side of the split.
Time-series split. When rows are ordered in time, a random split lets the model train on the future and test on the past, which never happens in production. TimeSeriesSplit trains on earlier rows and tests on later ones.
Cross-validation only gives an honest number if every step that learns from the data is refit inside the loop. Scale or impute on the whole dataset first, and information from the test folds has already leaked into training. The scores come out too optimistic, and you find out only once the model is live.
The fix is to wrap the preprocessing and the model in a single pipeline and pass that to the cross-validation call. scikit-learn then refits the scaler on each training fold and applies it to the held-out fold, exactly as at prediction time. Preprocessing by hand across the full dataset is the most common source of data leakage in model evaluation.
Anomaly detection automatically flags data points, events, or patterns that do not fit normal behaviour. It can catch odd invoices, machine ...
Read definitionArtificial intelligence is technology that teaches computers to learn, reason, and make decisions from data instead of following hand-writte...
Read definitionBias in AI is a skew that creeps into models through data, algorithms, or human choices. It is not always harmful, but it has to be managed ...
Read definitionClass imbalance is when one class in a classification dataset vastly outnumbers the other, like fraud among normal transactions. The rare cl...
Read definitionComputer vision is software that interprets images and video. It can classify images, detect objects, segment defects, read text with OCR, o...
Read definition
What's the difference between Power Bi and Microsoft Fabric? Power Bi is best for data vizualisation and reporting. Fabric offers end-to-end...
A centralized data repository is the foundation to become a true data-driven organization. by bringing data from various sources together an...