Data: features, target and splitting
Every model starts with a table. Each row is an example (a customer, an invoice, a month), and the columns come in two kinds: features are what we know, and the target (or label) is what we want to predict.
| Store | Orders / month | Weeks since last order | Region | Left? (target) |
|---|---|---|---|---|
| Al Waha | 8 | 1 | Riyadh | No |
| Al Salam | 2 | 7 | Jeddah | Yes |
| Al Noor | 5 | 4 | Dammam | No |
Why split the data? Testing a model on the examples it learned from is like a student who memorised the exam with its answers: full marks, no understanding. So we hold back part of the data (usually 20%) as the test set, learn from the rest (the training set), and then see how the model does on examples it has never seen.
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct"] cartons = [410, 395, 430, 450, 470, 520, 610, 590, 480, 505] cut = int(len(cartons) * 0.8) # 80% for training train = cartons[:cut] test = cartons[cut:] print("Train:", len(train), "months") print("Test: ", len(test), "months", test)
Data matters more than the algorithm. A model learns from what you give it: if the sales data has duplicates, mistyped prices or missing months, it learns the mistakes. The classic rule: garbage in, garbage out. That's why most of an ML project's time goes into preparing and cleaning data, and where your SQL skills pay off.