"Machine learning is how computers learn patterns from examples instead of following rules a person wrote by hand. Show a program enough labeled emails and it learns to spot spam; show it enough house sales and it learns to estimate prices. The ideas on this page are the foundation for everything from recommendation systems to large language models."- Claude 2026
In 1959 Arthur Samuel described machine learning as giving computers the ability to learn without being explicitly programmed. In traditional programming a person writes the rules. In machine learning a person supplies examples, and a learning algorithm works out the rules on its own. The result is a model: a function that takes new inputs and makes a prediction.
- Dataset: a table of examples, one row each
- Features: the input columns, such as size or age
- Label: the answer we want to predict
- Model: the learned function from features to label
- Training: adjusting the model to fit the examples
- Inference: using the trained model on new data
Supervised
Every example comes with the right answer. Classification predicts a category, such as spam or not spam. Regression predicts a number, such as a price or temperature. Most beginner projects start here. See scikit-learn.
Unsupervised
No answers are given. Clustering groups similar examples, such as customer segments. Dimensionality reduction compresses many features into a few so the data can be plotted or processed faster. See scikit-learn clustering examples.
Reinforcement
An agent learns by trying actions and collecting rewards, like learning a game by playing it. It powers game-playing AI and robotics. See Reinforcement Learning Fundamentals.
1Collect data
More, cleaner, and more representative data usually beats a fancier algorithm. Browse our list of datasets for machine learning.
2Prepare data
Fix missing values, turn text categories into numbers, and scale features to similar ranges. Choosing and building good inputs is called feature engineering.
3Split the data
Hold back a test set, often 20%, that the model never sees during training. It is the only honest way to measure how the model will do on new data.
4Train a model
Pick an algorithm and fit it to the training set. In scikit-learn every model shares the same two steps: fit to learn and predict to answer.
5Evaluate
Score the model on the test set. If it falls short, go back: try new features, a different algorithm, or different settings (hyperparameters).
6Predict
Use the finished model on real, new data, and keep monitoring it, because the world changes and models can drift.
You don't need to know the math to start. Learn what each algorithm is good at, then try several and compare. The scikit-learn algorithm cheat sheet is a flowchart for choosing one.
| Algorithm | Type | The idea | Learn more |
|---|---|---|---|
| Linear regression | Regression | Fit the straight line that best follows the data | Visual guide |
| Logistic regression | Classification | Turn a weighted sum of features into a probability | Visual guide |
| k-nearest neighbors | Classification | Copy the answer of the most similar examples | User guide |
| Decision tree | Both | Ask a series of yes/no questions about the features | Visual guide |
| Random forest | Both | Let many decision trees vote | Visual guide |
| Naive Bayes | Classification | Combine word or feature probabilities, a classic for text | Spam detection project |
| k-means | Clustering | Group points around k center points | User guide |
| PCA | Dimensionality | Find the few directions that capture most of the variation | User guide |
| Neural networks | Both | Layers of simple units that learn complex patterns | 3Blue1Brown |
A model that is too simple underfits: it misses the real pattern and does poorly everywhere. A model that is too flexible overfits: it memorizes the training data, noise included, and then fails on new data. This tradeoff is called the bias-variance tradeoff. The warning sign of overfitting is a model that scores far better on training data than on test data.
- Keep a separate test set
- Use cross-validation to score on several splits
- Collect more training data
- Simplify the model or add regularization
How you score a model depends on the task. Scikit-learn's model evaluation guide covers them all.
Classification
Accuracy is the share of correct answers, but it misleads when one class is rare. If 99% of emails are not spam, a model that never flags spam is 99% accurate and useless. Precision and recall and the confusion matrix show which mistakes the model makes.
Regression
Mean absolute error is the average size of a miss, in the label's own units. Mean squared error punishes big misses more. R2 says how much of the variation the model explains, where 1.0 is perfect.
scikit-learn is the standard Python library for classic machine learning. It is free, well documented, and every model follows the same fit / predict pattern, so once you learn one you can try them all. You'll want some Python and pandas first.
Ready for a project? Try these step-by-step builds on tonia.ai:
These resources explain the concepts on this page in much more depth, from visual intuition to the underlying math.
Visual Explanations
A Visual Introduction to Machine Learning builds a decision tree as you scroll. MLU-Explain from Amazon covers core concepts with interactive articles, and the TensorFlow Playground lets you train a small neural network in the browser.
Videos
StatQuest with Josh Starmer explains nearly every algorithm and statistic clearly and step by step. 3Blue1Brown animates how neural networks learn.
Courses
Google's Machine Learning Crash Course is free and practical. Andrew Ng's Machine Learning Specialization on Coursera is the most popular introduction to the theory.
Books
An Introduction to Statistical Learning with Applications in Python is free to download and is a favorite in university courses. Aurélien Géron's best-selling Hands-On Machine Learning has free companion notebooks.