Section 1: How machine learning works
What machine learning actually is
A traditional program follows rules a person wrote: if the email contains these words, mark it as spam. Machine learning flips this. You give the computer examples with known answers, such as thousands of emails labelled spam or not spam, and an algorithm finds patterns that map inputs to answers. The result is a model: a function that can make predictions for new examples.
Supervised learning
Most practical machine learning is supervised: each training example has a known target.
- Classification predicts a category: will this customer cancel (yes or no), which of five product types is this.
- Regression predicts a number: the price of a house, next week's demand.
There are other kinds, such as unsupervised learning, which finds structure without labels, like grouping similar customers. We focus on supervised learning, because it covers most business problems and teaches the core ideas.
Features and targets
Each example is described by features, the inputs: a customer's tenure, plan type, number of support tickets. The target is what you want to predict: whether they cancelled. In scikit-learn, features are usually a table called X and the target a column called y.
The quality of features usually matters more than the choice of algorithm. A model can only learn from information you give it.
What learning means
Most models have parameters, numbers adjusted during training to make predictions match the training targets as closely as possible. A linear regression learns one weight per feature. A decision tree learns which questions to ask and in what order. Training is an optimisation: find the parameters that minimise errors on the examples.
The real goal: generalisation
A model that memorises the training data is useless. The goal is to predict well on new data the model has never seen. That is why we always hold back data for evaluation, and why a model with perfect training accuracy is often a warning sign rather than a success. This idea, generalisation, runs through the whole course.
When not to use machine learning
If simple rules work, use rules. If you have very little data, or the cost of a wrong prediction is high and you cannot explain the model, think carefully. Machine learning is a tool for problems where patterns are too complex to write by hand and enough examples exist to learn them.