{"id":"l-ml-1-1","courseId":"ml-crash-course","lang":"en","kind":"intro","summary":"Explain what machine learning does differently from hand-written rules, tell supervised from unsupervised problems, and describe the churn question this course answers.","html":"<p>Cartwheel, the online store you will work with in this course, has a problem every subscription-free shop has. Customers drift away without saying goodbye. Nobody cancels anything; they stop ordering. The marketing team wants to send a win-back offer to customers who are about to go quiet, before they are gone. Which customers?</p>\n<p>You could write a rule: “if a customer hasn’t ordered in 90 days, send the offer”. That rule is a fine start, and you will measure it properly in a later lesson. But churn depends on more than one number. A customer with fifteen orders who went quiet for a month is different from a one-time buyer who went quiet for a month. Writing rules for every combination of tenure, order count, spend, coupons and support tickets gets out of hand fast.</p>\n<h2 id=\"sec-1\" tabindex=\"-1\">Rules from examples</h2>\n<p>Machine learning flips the job around. Instead of writing the rules, you collect examples where you already know the answer, and an algorithm finds a rule that fits them. For Cartwheel, that means past customers, what they looked like on a given date, and whether they ordered again in the following 90 days.</p>\n<figure class=\"diagram\"><svg class=\"diagram-svg\" focusable=\"false\" viewBox=\"0 0 680 230\" role=\"img\" aria-labelledby=\"l-ml-1-1-t1\"><defs><marker id=\"arrow-l-ml-1-1-1\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0 L10 5 L0 10 z\" class=\"d-arrowhead\"/></marker></defs>\n  <title id=\"l-ml-1-1-t1\">In classic programming, rules and data go in and answers come out. In machine learning, data and known answers go in and a learned rule, the model, comes out.</title>\n  <text class=\"d-label-strong\" x=\"20\" y=\"30\">Classic programming</text>\n  <rect class=\"d-box\" x=\"20\" y=\"45\" width=\"130\" height=\"44\" rx=\"10\"/>\n  <text class=\"d-label\" x=\"85\" y=\"72\" text-anchor=\"middle\">Rules</text>\n  <rect class=\"d-box\" x=\"170\" y=\"45\" width=\"130\" height=\"44\" rx=\"10\"/>\n  <text class=\"d-label\" x=\"235\" y=\"72\" text-anchor=\"middle\">Data</text>\n  <path class=\"d-arrow\" d=\"M310 67 L400 67\" marker-end=\"url(#arrow-l-ml-1-1-1)\"/>\n  <rect class=\"d-box-accent\" x=\"410\" y=\"45\" width=\"150\" height=\"44\" rx=\"10\"/>\n  <text class=\"d-label\" x=\"485\" y=\"72\" text-anchor=\"middle\">Answers</text>\n  <text class=\"d-label-strong\" x=\"20\" y=\"140\">Machine learning</text>\n  <rect class=\"d-box\" x=\"20\" y=\"155\" width=\"130\" height=\"44\" rx=\"10\"/>\n  <text class=\"d-label\" x=\"85\" y=\"182\" text-anchor=\"middle\">Data</text>\n  <rect class=\"d-box\" x=\"170\" y=\"155\" width=\"130\" height=\"44\" rx=\"10\"/>\n  <text class=\"d-label\" x=\"235\" y=\"182\" text-anchor=\"middle\">Answers</text>\n  <path class=\"d-arrow\" d=\"M310 177 L400 177\" marker-end=\"url(#arrow-l-ml-1-1-1)\"/>\n  <rect class=\"d-box-primary\" x=\"410\" y=\"155\" width=\"150\" height=\"44\" rx=\"10\"/>\n  <text class=\"d-label\" x=\"485\" y=\"182\" text-anchor=\"middle\">Rules (a model)</text>\n</svg><figcaption>Classic programming versus machine learning</figcaption></figure>\n<p>The learned rule is called a <strong>model</strong>. Once you have it, you feed it new customers and it predicts their answer. That is the whole idea; the rest of this course is about doing it well and knowing when the predictions deserve trust.</p>\n<p>Here is the table you will spend most of the course with. Each row is a customer, each column is something known about them on 30 September 2025, and <code dir=\"ltr\">churned</code> records what happened next.</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"python\" data-run=\"python\" data-index=\"0\"><div class=\"code-head\"><span class=\"code-title\">Python</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn code-run\" data-action=\"run\" data-lang=\"python\" data-index=\"0\" aria-label=\"Run this example\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z\"/></svg><span>Run</span></button><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#CF222E;--shiki-dark:#FF7B72\">import</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\"> pandas </span><span style=\"color:#CF222E;--shiki-dark:#FF7B72\">as</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\"> pd</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">churn </span><span style=\"color:#CF222E;--shiki-dark:#FF7B72\">=</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\"> pd.read_csv(</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"churn.csv\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">)</span></span>\n<span class=\"line\"><span style=\"color:#0550AE;--shiki-dark:#79C0FF\">print</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">(churn.shape)</span></span>\n<span class=\"line\"><span style=\"color:#0550AE;--shiki-dark:#79C0FF\">print</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">(churn[[</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"orders\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">, </span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"days_since_last_order\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">, </span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"support_tickets\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">, </span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"churned\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">]].head())</span></span>\n<span class=\"line\"><span style=\"color:#0550AE;--shiki-dark:#79C0FF\">print</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">(</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"Churn rate:\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">, </span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\">round</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">(churn[</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\">\"churned\"</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">].mean(), </span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\">3</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">))</span></span></code></pre><div class=\"run-output\" data-run-output=\"0\" hidden></div></div>\n<p>398 customers, 55% of whom did not order again within 90 days. The columns you predict from are the <strong>features</strong>; the column you predict is the <strong>target</strong> (or label).</p>\n<h2 id=\"sec-2\" tabindex=\"-1\">Kinds of learning</h2>\n<p><strong>Supervised learning</strong> has a target column. The examples come with answers, and the model learns to map features to the answer. Two flavours, depending on the target:</p>\n<ul>\n<li><strong>Classification</strong>: the target is a category. Will this customer churn, yes or no? Is this tumour benign or malignant? Which digit is in this image?</li>\n<li><strong>Regression</strong>: the target is a number. How much will this customer spend next year? How far will a disease progress?</li>\n</ul>\n<p><strong>Unsupervised learning</strong> has no target. You ask the data a looser question: which customers resemble each other? Can thirty columns be summarised by two? You will meet clustering and PCA, the two workhorses, in section 5.</p>\n<aside class=\"callout callout-mistake\" role=\"note\"><p class=\"callout-title\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"/><path d=\"M12 9v4\"/><path d=\"M12 17h.01\"/></svg><span><span class=\"callout-kind\">Common mistake</span><span class=\"callout-sep\" aria-hidden=\"true\"> · </span>Reaching for a model when a rule will do</span></p>\n<p>If you can write the rule down and it is right, write it down. “Orders over $10,000 need review” is a rule, not a learning problem. Models cost data, training, monitoring and explanations. They pay off when the pattern is real but too tangled to state by hand.</p>\n</aside>\n<h2 id=\"sec-3\" tabindex=\"-1\">How this course works</h2>\n<p>You will build everything in scikit-learn, the standard Python library for classic machine learning, and run it in the browser. Each section adds one layer:</p>\n<ol>\n<li>The workflow, the train/test split, the scikit-learn API and baselines.</li>\n<li>Regression on a medical dataset, with the loss function and gradient descent pictured.</li>\n<li>Classification on churn: logistic regression, trees, ensembles, and the metrics that matter.</li>\n<li>The habits that keep you honest: cross-validation, pipelines, tuning, leakage.</li>\n<li>Clustering, neural networks, where LLMs fit, fairness, and shipping.</li>\n</ol>\n<p>One habit runs through all of it. Before you believe a score, you ask “compared to what?”. A model that is 73% accurate sounds good until you learn that guessing “churned” for everyone gets 55%, and a one-line rule gets 72%. Next lesson starts with the most important step in that habit: setting data aside so you can measure honestly.</p>\n","toc":[{"id":"sec-1","text":"Rules from examples","level":2},{"id":"sec-2","text":"Kinds of learning","level":2},{"id":"sec-3","text":"How this course works","level":2}],"takeaways":["Machine learning takes examples of inputs with known answers and produces a function that predicts answers for new inputs.","Supervised learning needs a labelled target column; unsupervised learning looks for structure in data with no target.","Predicting a number is regression; predicting a category is classification.","If a short rule or a SQL query answers the question well enough, you do not need a model."],"further":[{"title":"scikit-learn: An introduction to machine learning","url":"https://scikit-learn.org/stable/tutorial/basic/tutorial.html"},{"title":"scikit-learn User Guide","url":"https://scikit-learn.org/stable/user_guide.html"}],"quiz":[{"q":"<p>Cartwheel wants to group its customers into a few shopping styles, but nobody has labelled any customer with a style. What kind of problem is this?</p>","options":[{"text":"Supervised classification, because the output is a category.","why":"Classification needs examples where the right category is already known. Here there are no labels to learn from."},{"text":"Unsupervised learning, because there is no target column to learn from.","why":"Correct. Finding groups in unlabelled data is clustering, a classic unsupervised task."},{"text":"Regression, because customer data is mostly numbers.","why":"Regression is about the output being a number, not the inputs. Numeric inputs are normal for every kind of model."}],"answer":1},{"q":"<p>Which question is a regression problem?</p>","options":[{"text":"Will this customer place another order in the next 90 days?","why":"The answer is yes or no, a category. That makes it classification."},{"text":"Which of five support teams should handle this ticket?","why":"Five possible teams is still a set of categories, so this is multi-class classification."},{"text":"How much will this customer spend over the next year?","why":"Correct. The target is a continuous amount of money, which makes it regression."}],"answer":2},{"q":"<p>A teammate proposes a model to flag orders over $10,000 for manual review. What is the best response?</p>","options":[{"text":"Train a classifier on past flagged orders so it can learn the pattern.","why":"The rule is already known and exact. A model can only approximate it, and adds training, monitoring and error."},{"text":"Write the rule <code dir=\"ltr\">total &gt; 10000</code>; no learning is needed when you can state the rule.","why":"Correct. Machine learning earns its cost when the rule is unknown or too complex to write by hand."},{"text":"Use clustering to find which orders look large.","why":"Clustering finds groups by similarity. It cannot know your business threshold, which you already have."}],"answer":1}],"exercise":{"kind":"choice","multiple":true,"options":["churn-flag","spend-next-year","find-segments","big-order-rule","ticket-team"],"correct":["churn-flag","spend-next-year","ticket-team"],"title":"Which of these are supervised learning problems?","prompt":"<p>Cartwheel’s teams have pitched five ideas. Select every idea that is a <strong>supervised learning</strong> problem: one where you have past examples with a known answer and want a model to predict that answer for new cases.</p>\n","hints":["Ask of each idea: is there a column of known answers in the historical data?","Supervised covers both categories (classification) and numbers (regression).","One idea has no labels at all, and one is a rule someone can already write down."],"explanation":"<p>Churn flags, next-year spend and ticket routing all have historical answers to learn from: two classification problems and one regression problem. Finding shopping styles has no labels, so it is unsupervised clustering. The $10,000 review threshold is a known rule, so it needs an <code dir=\"ltr\">if</code>, not a model.</p>\n","checkLabels":{},"optionText":{"churn-flag":{"text":"Predict whether a customer will order again in the next 90 days, using past customers whose outcome is known.","why":"Supervised classification: the historical <code dir=\"ltr\">churned</code> column is the label."},"spend-next-year":{"text":"Predict how much a customer will spend next year, using customers from previous years.","why":"Supervised regression: past customers’ actual spend is a numeric label."},"find-segments":{"text":"Discover a handful of shopping styles among customers, without any predefined styles.","why":"No labels exist, so this is unsupervised learning (clustering)."},"big-order-rule":{"text":"Flag every order above $10,000 for manual review.","why":"The rule is known and exact. Write the condition; no learning is involved."},"ticket-team":{"text":"Route each new support ticket to one of five teams, using past tickets that were routed correctly.","why":"Supervised multi-class classification: past routing decisions are the labels."}}},"words":618,"readMinutes":3}