Artificial Intelligence · Foundations
What Is Machine Learning?
A gentle introduction to fitting functions to data.
- machine learning
- basics
Machine learning is the practice of fitting a function to data instead of writing it by hand.
import numpy as np
def predict(x, weights):
return np.dot(x, weights)Note: a model is only as good as the data and the objective it was trained against.
Key terms#
- Features: the inputs to a model.
- Labels: the outputs a supervised model learns to predict.
- Loss function: measures how wrong a prediction is.
How a model learns#
Training repeats a simple loop: make predictions, measure the loss, and nudge the weights in the direction that reduces it.
def train(x, y, weights, lr=0.01, steps=1000):
for _ in range(steps):
error = predict(x, weights) - y
gradient = x.T @ error / len(y)
weights = weights - lr * gradient
return weightsThe learning rate controls the size of each nudge. Too large and the loss oscillates or diverges; too small and training crawls.
Evaluating a model#
A model that scores well on the data it was trained on may still fail on new data. Always hold out data the model never saw during training.
| Split | Purpose |
|---|---|
| Training | Fit the model's weights |
| Validation | Tune hyperparameters and compare candidates |
| Test | Report the final, unbiased estimate once |
Pick a metric that matches the cost of mistakes. Accuracy hides problems on imbalanced data, where precision, recall, or the area under the ROC curve tell you more.
Common pitfalls#
- Data leakage: information from the test set sneaking into training, which inflates scores.
- Overfitting: memorising noise instead of learning the signal.
- Distribution shift: production data that no longer resembles the training data.
Each of these is easier to prevent than to diagnose later, so build the evaluation harness before the model.