← Learning Hub
Intermediate

Classification: Will the Customer Buy?

Let's predict whether a shopper will buy, from how they browsed. Logistic regression is the simplest classifier: it gives a probability between 0 and 1.

Classification answers yes/no or which-group questions: will this customer buy, is this payment fraud, which category is this product. Logistic regression gives probabilities, trees give readable rules, and random forests are strong all-rounders for table data.

Example
You can edit this code.

Decision trees

A decision tree learns yes/no questions. It's easy to read, so you can explain the model to your team:

Example
You can edit this code.

Random forest

A random forest trains many trees on random parts of the data and lets them vote. It's often more accurate than one tree and is a great default for table data.

Example
You can edit this code.
With only 20 rows these numbers are just for learning. Real models need hundreds or thousands of examples, and you should check the results on fresh data.
Key points
  • predict_proba gives probabilities.
  • Decision trees are easy to explain.
  • Random forests combine many trees for accuracy.

📝 Test yourself

1. What does predict_proba give?
2. Why are decision trees popular with teams?
3. Fill in the model made of many voting trees:
from sklearn.ensemble import Classifier