Machine Learning Cheat Sheet for Beginners (Algorithm Selection Map)
β‘ Quick Answer
A machine learning cheat sheet for beginners β the algorithm selection map, metrics that matter, why accuracy lies on imbalanced data, and the workflow order.
Get more content like this on Telegram!
Daily AI tips, notes & resources β free
Advertisement
Machine Learning Cheat Sheet for Beginners
Most machine learning failures are not modelling failures. They are the wrong metric, the wrong split, or a model that memorised its training data.
Picking the algorithm is the easy part β there is a small map from data shape to algorithm family, and this sheet contains it. The parts that decide whether your model works are further down.
Updated for 2026. Examples use scikit-learn conventions.
The Three Learning Types
| Type | You have | You want | Example |
|---|---|---|---|
| Supervised | Inputs + correct labels | Predict labels for new inputs | Spam detection, price prediction |
| Unsupervised | Inputs only | Find structure | Customer segments, anomaly detection |
| Reinforcement | An environment + rewards | A policy of actions | Game agents, robotics, ad bidding |
Supervised learning splits again by what the label is:
- Classification β the label is a category. Spam or not. Which of five products.
- Regression β the label is a number. Price, temperature, days until churn.
What people get wrong: framing a regression problem as classification by bucketing the target. Predicting "high, medium, low" price throws away information the model could have used and forces you to defend arbitrary boundaries.
The Algorithm Selection Map
This is the table to actually use. Find your row, start with the first suggestion, and only move right if it is not enough.
| Your data | Labels? | Start with | Then try |
|---|---|---|---|
| Tabular, < 1k rows | Yes, category | Logistic regression | Random forest, SVM |
| Tabular, 1kβ1M rows | Yes, category | Gradient boosting (XGBoost, LightGBM) | Random forest, neural net |
| Tabular, any size | Yes, number | Linear regression as baseline | Gradient boosting regressor |
| Tabular, many features, few rows | Yes | Ridge / Lasso (regularised) | Linear SVM |
| Images | Yes | Pretrained CNN, fine-tuned | Vision transformer |
| Text | Yes | Pretrained transformer | TF-IDF + logistic regression baseline |
| Time series | Yes, number | Gradient boosting with lag features | Classical statistical models |
| Any | No, want groups | K-means (if k is known) | DBSCAN (if k is unknown) |
| Any | No, too many features | PCA | UMAP, t-SNE (visualisation only) |
| Any | No, find outliers | Isolation Forest | One-class SVM |
| Sequential decisions | Reward signal | Reinforcement learning | β |
The single most useful line in this table: for tabular data of any realistic size, gradient boosting wins most of the time. Neural networks dominate images, audio, and text; on spreadsheets, boosted trees remain the default answer, and beginners routinely reach past them for a deep model that performs worse.
Algorithms β When To Use, When Not To
| Algorithm | Use it when | Avoid it when |
|---|---|---|
| Linear regression | Relationship is roughly linear, you need interpretability | Relationships are non-linear or features interact |
| Logistic regression | Binary classification baseline, need probabilities | Complex boundaries, heavy feature interaction |
| Decision tree | You must explain every prediction | Accuracy matters β a single tree overfits badly |
| Random forest | Strong default, little tuning, handles mixed data | You need the fastest possible inference |
| Gradient boosting | Best tabular accuracy, competitions, production | Data is tiny or you cannot tune anything |
| SVM | Small dataset, clear margin, high dimensions | More than ~100k rows β it scales poorly |
| K-nearest neighbours | Tiny dataset, simple baseline, no training step | Large data or many features (curse of dimensionality) |
| Naive Bayes | Text classification, very fast, small data | Features are strongly correlated |
| K-means | Round, similar-sized clusters, k is known | Irregular shapes, unknown k, outliers present |
| DBSCAN | Arbitrary cluster shapes, unknown k, noisy data | Clusters have very different densities |
| PCA | Too many correlated features, need speed | You need the original features to stay interpretable |
| Neural network | Images, audio, text, very large datasets | Small tabular data β boosted trees will beat it |
The interpretability tradeoff is real and it is a business decision. A logistic regression that a loan officer can explain in a sentence may be worth two accuracy points against a boosted model nobody can defend to a regulator.
Metrics β The Section That Decides Whether Your Model Works
The confusion matrix
Everything below is derived from four counts.
Predicted + Predicted β
Actual + True Positive False Negative β missed it
Actual β False Positive True Negative
β false alarmThe metrics themselves
| Metric | Formula | Answers |
|---|---|---|
| Accuracy | (TP + TN) / all | How often am I right overall? |
| Precision | TP / (TP + FP) | When I say yes, how often am I right? |
| Recall | TP / (TP + FN) | Of all real positives, how many did I find? |
| F1 score | 2PR / (P + R) | Harmonic mean when both matter |
| ROC-AUC | area under TPR/FPR curve | How well does the model rank positives above negatives? |
Why accuracy is wrong on imbalanced data
This is the most consequential idea on this page.
Suppose 1% of credit card transactions are fraudulent. A model that predicts "not fraud" for every single transaction achieves 99% accuracy and catches zero fraud.
Predict all negative on 1% positives:
accuracy = 99% β looks excellent
precision = 0 β undefined / no positives predicted
recall = 0 β caught nothingAccuracy counts every correct prediction equally, which hides the fact that all the errors landed on the only class you cared about. On any dataset where the classes are unbalanced β fraud, disease, churn, defects, click-through β accuracy is not just imperfect, it is actively misleading.
Use instead: precision and recall, the F1 score, or the confusion matrix directly.
Precision or recall β which one
They pull against each other. Flagging more items raises recall and lowers precision. The choice depends entirely on which error costs more.
| Problem | Favour | Because |
|---|---|---|
| Spam filter | Precision | A lost real email is worse than spam in the inbox |
| Cancer screening | Recall | A missed case is far worse than an extra test |
| Fraud detection | Recall, then precision | Missing fraud costs money; false alarms cost support time |
| Recommendation | Precision | Bad recommendations erode trust immediately |
ROC-AUC is threshold-independent and useful for comparing models, but on heavily imbalanced data prefer the precision-recall curve, which does not flatter a model that is good at the easy majority class.
Train, Validation, Test
| Split | Purpose | Rule |
|---|---|---|
| Training (~60β70%) | Fit the model | Model sees this |
| Validation (~15β20%) | Tune hyperparameters, compare models | Model is chosen using this |
| Test (~15β20%) | Final honest estimate | Touch once, at the very end |
The test set is not a validation set. Every time you look at test performance and change something, you leak information into the model, and the test score stops being an honest estimate of new data. If you have tuned against it, it is now a validation set and you no longer have a test set.
Cross-validation
from sklearn.model_selection import cross_val_score, StratifiedKFold
scores = cross_val_score(model, X, y, cv=StratifiedKFold(5), scoring='f1')
print(scores.mean(), scores.std())Cross-validation trains on all folds but one, evaluates on the held-out fold, and rotates until each fold has been held out once. The reported score is the average, and the standard deviation tells you how stable the result is.
Two variants that are not optional:
- Stratified folds for classification, so each fold keeps the original class balance.
- Time-based splits for time series, so the model never trains on data from after the period it is predicting.
What people get wrong: shuffling time series data before splitting. The model learns from the future, scores brilliantly, and fails completely in production.
Overfitting vs Underfitting
| Training score | Validation score | Signal | |
|---|---|---|---|
| Underfitting | Low | Low | Model too simple |
| Good fit | High | High, close to training | The gap is small |
| Overfitting | Very high | Noticeably lower | Large gap |
The gap between training and validation score is the diagnostic. Check it after every training run, before you look at anything else.
| Problem | Fixes |
|---|---|
| Overfitting | More data, fewer features, regularisation (L1/L2), dropout, early stopping, simpler model, tree depth limits |
| Underfitting | More expressive model, better features, less regularisation, train longer |
L1 (Lasso) shrinks some coefficients to exactly zero, so it performs feature selection. L2 (Ridge) shrinks all coefficients toward zero without eliminating any. Use L1 when you suspect many features are useless; L2 when they are all mildly informative.
Feature Scaling
| Needs scaling | Does not need scaling |
|---|---|
| K-nearest neighbours | Decision tree |
| SVM | Random forest |
| K-means | Gradient boosting |
| PCA | Naive Bayes |
| Linear / logistic regression (gradient descent) | |
| Neural networks |
The rule underneath: anything that measures distance or uses gradient descent needs scaling; anything that splits on thresholds within one feature does not.
from sklearn.preprocessing import StandardScaler, MinMaxScaler
StandardScaler() # mean 0, std 1 β the default
MinMaxScaler() # squeeze into [0, 1] β for bounded inputsWithout scaling, a feature measured in thousands overwhelms a feature measured in decimals purely because of its units, and the model quietly ignores the smaller one.
Fit the scaler on training data only, then apply it to validation and test. Fitting on the full dataset leaks the test set's distribution into training β one of the most common and most invisible mistakes in beginner pipelines.
The Workflow Order
- Define the problem and the metric first. Before any code, decide what a good model means numerically and what an error costs.
- Split the data. Before exploration, before scaling, before anything. Hold out the test set immediately.
- Explore and clean. Missing values, obvious errors, class balance, leakage candidates.
- Build a dumb baseline. Predict the majority class, or the mean. Every later model is measured against this.
- Engineer features. Usually worth more than the model choice on tabular data.
- Train a simple model. Logistic or linear regression. Compare to the baseline.
- Train a strong model. Gradient boosting for tabular; a pretrained network otherwise.
- Tune hyperparameters using cross-validation. Never using the test set.
- Evaluate on the test set once. Report that number, not the best one you saw.
- Monitor after deployment. Data drifts; a model that was good in March may not be in September.
Step 4 is skipped most often and matters most. Without a baseline you cannot tell whether your gradient boosting model is adding value or just adding complexity.
The Five Mistakes
1. Using accuracy on imbalanced data. A 99% accurate fraud detector that catches no fraud is the canonical example. Check the class balance before you choose a metric, always.
2. Data leakage. Scaling before splitting, using a feature that would not exist at prediction time, or including the target in disguise. The signal is a validation score that looks too good β investigate rather than celebrate.
3. Tuning against the test set. Once you have made decisions using test performance, it is no longer an honest estimate. Keep a genuinely untouched holdout.
4. Reaching for deep learning on tabular data. Gradient boosting beats neural networks on most spreadsheet-shaped problems with far less tuning and far less compute. Deep learning earns its place on images, audio, and text.
5. Shuffling time series before splitting. The model trains on the future, scores brilliantly, and fails in production. Time series need time-ordered splits, no exceptions.
Print This Section
PICK tabular + labels ......... gradient boosting (XGBoost/LightGBM)
tabular, tiny / explain .. logistic or linear regression
images ................... pretrained CNN, fine-tuned
text ..................... pretrained transformer
no labels, k known ....... k-means
no labels, k unknown ..... DBSCAN
too many features ........ PCA
find outliers ............ isolation forest
METRICS balanced classes ......... accuracy is fine
imbalanced classes ....... precision / recall / F1 (NEVER accuracy)
false alarms costly ...... optimise precision
misses costly ............ optimise recall
regression ............... RMSE (penalises big errors), MAE
FIT train high + val low ..... overfitting β more data, regularise, simplify
both low ................. underfitting β richer model, better features
SCALE needed: kNN, SVM, k-means, PCA, linear w/ GD, neural nets
not needed: trees, random forest, gradient boosting
fit the scaler on TRAIN only
ORDER metric β split β clean β baseline β features β simple β strong
β CV tune β test ONCE β monitorMachine learning rewards discipline more than cleverness. Choose the metric before the model, split before you touch the data, and beat a dumb baseline before you reach for anything complicated.
π Next in this collection: Pandas and NumPy Cheat Sheet, or return to The Complete Developer Cheat Sheet Collection.
Advertisement
π¬ DiscussionPowered by GitHub Discussions
Frequently Asked Questions

AI & Software Engineering Editorial Team
The AiTechWorlds editorial team writes and reviews in-depth guides on artificial intelligence, machine learning, prompt engineering, programming, and developer tools. Every article is fact-checked against primary sources and kept up to date for working developers and CS students.
Not sure yet? Ask AI about this article
Get an instant, unbiased AI summary of βMachine Learning Cheat Sheet for Beginners (Algorithm Selection Map)β.
Advertisement
Related Articles
Bash Scripting Cheat Sheet (The First Line Every Script Needs)
A practical Bash scripting cheat sheet β variables, conditionals, loops, functions, and the set -euo pipefail line that turns silent failure into loud failure.
15 Coding Interview Patterns That Solve Most Problems
The 15 coding interview patterns that cover most problems β the signal that identifies each one, a minimal code skeleton, and a two-minute recognition table.
CSS and Tailwind Cheat Sheet: Flexbox, Grid and Centering Solved
A practical CSS and Tailwind cheat sheet β Flexbox vs Grid decision rules, every centering method, responsive breakpoints, and the specificity traps.
Data Structures and Big-O Cheat Sheet for Coding Interviews
A practical big O cheat sheet β the complexity ladder with real examples, data structure operation tables, and how to state your complexity in an interview.