BooleanIQ / Learn

AI from the ground up / Level 300 / LESSON 303

Prediction with a line: how a machine guesses a price

Regression, error, and making the error smaller

Know

About 9 min read · Hindi and English

The video is not out yet. You can read this lesson now.

How does a machine guess a price?

How does a machine price a phone? Four hundred old phones, and one straight line. I drew a line by eye. Its miss score, about thirty four hundred. The machine's, about twenty six hundred. Lower is better. Nobody gave it the rule. It started from a flat line, and nudged it into place.

हिन्दी में पढ़ें

मशीन किसी फ़ोन का दाम कैसे लगाती है? चार सौ पुराने फ़ोन, और एक सीधी लकीर। मैंने आँख से एक लकीर खींची। उसकी चूक का स्कोर, लगभग चौंतीस सौ। मशीन की लकीर का, लगभग छब्बीस सौ। जितना कम, उतना अच्छा। उसे किसी ने नियम नहीं बताया था। उसने एक सपाट लकीर से शुरू किया, और धीरे-धीरे खिसकाकर सही जगह ढूँढ ली।

What this video answers

I am BSK. Every number here is either calculated, or its source is on screen. After this, you can say how a machine prices a phone, and where it goes wrong. If you know this already, stay anyway. We hid a rule inside this table. Watch whether the machine catches it.

हिन्दी में पढ़ें

मैं बी एस के। यहाँ हर नंबर या हिसाब से निकला है, या उसका स्रोत स्क्रीन पे है। इसके बाद आप ख़ुद बता पाएँगे: मशीन फ़ोन का दाम कैसे लगाती है, और कहाँ चूकती है। अगर ये आप पहले से जानते हैं, तो भी रुकिए। इस टेबल में हमने एक नियम छिपाया है। देखिए मशीन उसे पकड़ पाती है या नहीं।

Three parts. The line, its miss, and the machine moving it. And there is one phone this line gets badly wrong. It comes at the end.

हिन्दी में पढ़ें

तीन हिस्से हैं। लकीर, उसकी चूक, और मशीन का उसे खिसकाना। और एक फ़ोन ऐसा भी है, जिसपे ये लकीर बुरी तरह फ़ेल होती है। वो आख़िर में आएगा।

What you need first

This channel has a full AI course, but this video stands alone. First: a machine learns a rule from past records. The records are data; the rule is the model. Second: here each phone comes with its right answer, its asking price. The course has a video on each of these. But how do those answers become a pricing rule? That is today.

हिन्दी में पढ़ें

इस चैनल पे ए आई का पूरा कोर्स है, पर ये वीडियो अकेले भी चलेगा। पहली बात: मशीन पुराने रिकॉर्ड देखकर एक नियम सीखती है। रिकॉर्ड को डेटा कहते हैं, नियम को मॉडल। दूसरी बात: यहाँ हर फ़ोन के साथ उसका सही जवाब लिखा है, यानी उसका माँगा गया दाम। इन दोनों पे कोर्स में अलग वीडियो हैं। पर उन जवाबों से दाम का नियम बनता कैसे है? आज वही।

What is a prediction in machine learning?

Many people believe this: prediction means knowing the future. If a machine said it, it must have known what comes next. A fortune teller with a laptop? Let us test that on a true story, over two centuries old. First of January, eighteen oh one. An Italian astronomer spotted a new small planet. It was named Ceres.

हिन्दी में पढ़ें

बहुत लोग मानते हैं: प्रेडिक्शन मतलब भविष्य जान लेना। मशीन ने कुछ बता दिया, तो जैसे उसे पता था कि आगे क्या होगा। यानी लैपटॉप वाला ज्योतिषी? चलिए, इसे दो सौ साल पुरानी एक सच्ची कहानी पे परखते हैं। एक जनवरी अठारह सौ एक। इटली के एक एस्ट्रोनॉमर को आसमान में एक नया छोटा ग्रह दिखा। नाम रखा गया सेरीज़।

But he saw only a small piece of its path. Then Ceres went behind the Sun, and was lost. So where would it reappear? Several people made predictions. The mathematician Carl Friedrich Gauss made one quite unlike the rest. That December, Ceres was found again. Almost exactly where Gauss said.

हिन्दी में पढ़ें

पर वो उसे उसके रास्ते का बस एक छोटा सा हिस्सा देख पाए। फिर सेरीज़ सूरज के पीछे चला गया, और खो गया। अब सवाल: वो दोबारा कहाँ दिखेगा? कई लोगों ने अंदाज़े दिए। गणितज्ञ कार्ल फ़्रीड्रिख़ गाउस का अंदाज़ा बाक़ी सबसे बिल्कुल अलग था। उसी साल दिसंबर में सेरीज़ फिर मिला। लगभग ठीक वहीं, जहाँ गाउस ने कहा था।

So did Gauss know the future? No. From the places it had been seen, he worked out its path, and carried it forward. His method has a name. It comes back with our phones. Now look at our table. Four hundred second hand phones, which we made up for teaching. No real listings.

हिन्दी में पढ़ें

तो क्या गाउस भविष्य जानते थे? नहीं। जहाँ-जहाँ वो दिखा था, उन जगहों से उन्होंने उसका रास्ता निकाला, और उसे आगे बढ़ा दिया। उनके तरीक़े का एक नाम है। वो हमारे फ़ोनों के साथ लौटेगा। अब हमारी टेबल देखिए। चार सौ पुराने फ़ोन, जो हमने सिखाने के लिए ख़ुद बनाए हैं। कोई असली लिस्टिंग नहीं।

Each phone has a row, and four columns. Age, storage, battery health, and the seller's asking price. Put it on a graph. Each dot is a phone. Left to right, its age in months. Upward, its price. You can see it without any maths: the older the phone, the lower the price. The dots slope downward.

हिन्दी में पढ़ें

हर फ़ोन की एक लाइन है, और चार कॉलम। उम्र, स्टोरेज, बैटरी की सेहत, और बेचने वाले का माँगा दाम। इसे ग्राफ़ पे रखते हैं। हर बिंदु एक फ़ोन है। बाएँ से दाएँ उसकी उम्र, महीनों में। नीचे से ऊपर उसका दाम। बिना किसी हिसाब के भी दिख जाता है: फ़ोन जितना पुराना, दाम उतना कम। बिंदु नीचे की तरफ़ ढलते हैं।

Now a new phone is for sale. Twenty months old. What should it cost? To price it, what does the machine need? News from tomorrow, or data on old phones? Think. Only old phones. The table has about forty that age. They ask from about eleven thousand to nearly twenty three thousand.

हिन्दी में पढ़ें

अब एक नया फ़ोन बिकने आया। बीस महीने पुराना। इसका दाम क्या हो? इसका दाम बताने के लिए मशीन को क्या चाहिए? आने वाले कल की कोई ख़बर, या पुराने फ़ोनों का डेटा? सोचिए। सिर्फ़ पुराने फ़ोन। टेबल में उतने ही पुराने लगभग चालीस फ़ोन हैं। उनके दाम लगभग सवा ग्यारह हज़ार से लेकर पौने तेईस हज़ार तक हैं।

There is no magic in it. And notice: this phone is listed today, not tomorrow. The future never came into it. Take the pattern in past data, and apply it to a new case. That is what a prediction really is. A prediction is a model's output for an input; the ones that matter are for inputs unseen in training, future or not.

हिन्दी में पढ़ें

इसमें कोई जादू नहीं है। और ध्यान दीजिए, ये फ़ोन आज बिकने आया है, कल नहीं। भविष्य की तो बात ही नहीं थी। पुराने डेटा में जो पैटर्न दिखा, उसे किसी नए मामले पे लगा देना। प्रेडिक्शन असल में यही है। प्रेडिक्शन यानी किसी इनपुट पे मॉडल का जवाब। काम के वो हैं, जो सीखते वक़्त न देखे गए इनपुट पे हों, चाहे भविष्य के हों या नहीं।

What is linear regression?

Prices spread that wide. So how do you get one number from these dots? You saw the easiest way at school. For now, assume price depends on age alone. We add storage and battery later. Dots on graph paper. You pick up a ruler, and lay it so it passes through the middle of them all.

हिन्दी में पढ़ें

दाम इतने फैले हुए हैं। तो इन बिंदुओं से एक नंबर कैसे निकले? सबसे आसान तरीक़ा आपने स्कूल में देखा है। अभी के लिए मान लीजिए कि दाम सिर्फ़ उम्र से तय होता है। स्टोरेज और बैटरी हम बाद में जोड़ेंगे। ग्राफ़ पेपर पे बिंदु हैं। आप एक स्केल उठाते हैं, और उसे ऐसे रखते हैं कि वो सब बिंदुओं के बीच से गुज़रे।

Where the ruler starts tells you roughly what a brand new phone would fetch. And how steeply it tilts tells you how much price is lost each month. Here the picture stops. A ruler is always straight. Prices need not be.

हिन्दी में पढ़ें

स्केल कहाँ से शुरू होता है, ये बताता है कि बिल्कुल नए फ़ोन का दाम अंदाज़न क्या होगा। और स्केल कितना झुका है, ये बताता है कि हर महीने दाम कितना गिरता है। बस, यहाँ तस्वीर रुकती है। स्केल हमेशा सीधा रहता है। दाम भी सीधे ही चलें, ये ज़रूरी नहीं।

So the real model is a line, set by just two numbers. The twenty month phone's price? Find twenty months on the line, and read it off. My line by eye starts at eighteen thousand, and falls two fifty a month. At twenty months, thirteen thousand. Guessing a number from a straight line is called linear regression. A heavy name for a ruler's job.

हिन्दी में पढ़ें

तो असल मॉडल एक लकीर है, जिसे बस दो नंबर तय करते हैं। बीस महीने वाले फ़ोन का दाम? लकीर पे बीस महीने देखिए, और वहाँ से पढ़ लीजिए। मेरी आँख वाली लकीर अठारह हज़ार से शुरू होती है, और हर महीने ढाई सौ गिरती है। बीस महीने पे, तेरह हज़ार। सीधी लकीर से किसी नंबर का अंदाज़ा लगाना, इसे लीनियर रिग्रेशन कहते हैं। नाम भारी है, काम स्केल वाला ही है।

What is a loss function?

But who decides whether my line is any good? By eye, every line looks fine. For each phone, see what the line said, and what was really asked. The gap between them is a miss. Some dots sit above the line, some below. Above or below, every miss counts.

हिन्दी में पढ़ें

पर मेरी लकीर अच्छी है या नहीं, ये कौन तय करेगा? आँख से तो हर लकीर ठीक ही लगती है। हर फ़ोन के लिए देखिए, लकीर ने कितना बताया, और असल में कितना माँगा गया। दोनों का फ़ासला एक चूक है। कुछ बिंदु लकीर के ऊपर हैं, कुछ नीचे। ऊपर हो या नीचे, हर चूक गिनी जाएगी।

Each miss is multiplied by itself. So double the miss means four times the penalty. Then we take the average over all phones. So it is not a total; it is a miss per phone. This one number says how wrong the line is overall. It is called the loss.

हिन्दी में पढ़ें

हर चूक को उसी से गुणा करते हैं, चूक गुणा चूक। इससे चूक दुगुनी हो, तो सज़ा चौगुनी। फिर सब फ़ोनों का औसत लेते हैं। यानी ये कुल जोड़ नहीं, एक फ़ोन पे चूक का नंबर है। ये एक नंबर बताता है कि लकीर कुल मिलाकर कितनी ग़लत है। इसे लॉस कहते हैं।

Here the loss is the mean of the squared misses; on screen, its root, so it reads in rupees. First, a foolish line: every phone at one price, the average. Its loss, about fifty four hundred. My eye line: about thirty four hundred. Better than flat.

हिन्दी में पढ़ें

यहाँ लॉस है चूकों के स्क्वेयर का औसत, और स्क्रीन पे उसका रूट दिखाया है, ताकि नंबर रुपयों में रहे। पहले एक बेवक़ूफ़ लकीर: हर फ़ोन का एक ही दाम, औसत दाम। उसका लॉस, लगभग चौवन सौ। मेरी आँख वाली लकीर: लगभग चौंतीस सौ। सपाट से बेहतर।

Lower loss, better line. That is the whole scoreboard.

हिन्दी में पढ़ें

लॉस जितना कम, लकीर उतनी अच्छी। बस, यही पूरा स्कोरबोर्ड है।

What is training? Gradient descent

How low can a line go? Now watch the machine. We keep a hundred phones aside. The machine learns from the other three hundred. It starts from that same flat, foolish line.

हिन्दी में पढ़ें

कोई लकीर कितना नीचे जा सकती है? अब मशीन को देखिए। सौ फ़ोन हमने अलग रख दिए हैं। मशीन बाक़ी तीन सौ से सीखती है। वो उसी सपाट, बेवक़ूफ़ लकीर से शुरू करती है।

Then the machine checks which way the loss slopes down, and nudges the line a little that way, turning it a little. With every nudge the loss falls. By the fifth, about three thousand. My eye line is already behind. Honestly, that stung. By the tenth, about twenty six fifty. Now each nudge saves less than the last.

हिन्दी में पढ़ें

फिर मशीन देखती है कि किस तरफ़ खिसकाने से लॉस घटेगा, और लकीर को थोड़ा सा उसी तरफ़ खिसकाती है, थोड़ा सा घुमाती है। हर धक्के के साथ लॉस गिरता है। पाँचवें धक्के तक लगभग तीन हज़ार। मेरी आँख वाली लकीर पीछे छूट गई। सच कहूँ, थोड़ा बुरा लगा। दसवें तक लगभग छब्बीस सौ पचास। अब हर धक्का पहले से कम बचाता है।

The eighteenth nudge did not save a rupee. So the machine stops. Loss, about twenty six hundred. Moving the line until the loss stops falling. That is called training. Each step goes against the loss's gradient, sized by learning rate times gradient: gradient descent.

हिन्दी में पढ़ें

अठारहवें धक्के ने एक रुपया भी नहीं बचाया। तो मशीन रुक जाती है। लॉस, लगभग छब्बीस सौ। लकीर को तब तक खिसकाना, जब तक लॉस गिरना बंद न हो जाए। इसी को ट्रेनिंग कहते हैं। हर क़दम लॉस की ढलान की उल्टी तरफ़, और क़दम का आकार लर्निंग रेट गुणा ढलान; इसे ग्रेडिएंट डिसेंट कहते हैं।

Is there a shortcut? For lines, a formula gives the best line in one go. The nudges stopped a rupee and a half short. It is called least squares: the smallest total of squared misses. That was Gauss's method. Legendre printed it first; Gauss said he had used it for years. This line starts at about twenty two thousand, and falls about three hundred fifty a month.

हिन्दी में पढ़ें

कोई शॉर्टकट है? लकीर के लिए एक सीधा फ़ॉर्मूला भी है, जो एक बार में सबसे अच्छी लकीर दे देता है। धक्के उससे बस डेढ़ रुपये पीछे रुके। इसका नाम है लीस्ट स्क्वेयर्स, यानी चूक गुणा चूक का सबसे कम जोड़। यही गाउस का तरीक़ा था। लेजांड्र ने इसे पहले छापा, और गाउस ने कहा, मैं तो बरसों से कर रहा हूँ। ये लकीर लगभग बाईस हज़ार से शुरू होती है, और हर महीने लगभग साढ़े तीन सौ गिरती है।

For our twenty month phone it says about fifteen thousand three hundred. My eye said thirteen thousand. And on the hundred phones kept aside, the loss stayed near twenty six hundred. Mine, about thirty seven hundred. Then why nudge? Because models that are not lines have no such formula. Big AI models learn this same way, nudge by nudge.

हिन्दी में पढ़ें

हमारे बीस महीने वाले फ़ोन के लिए ये कहती है, लगभग सवा पंद्रह हज़ार। मेरी आँख ने कहा था, तेरह हज़ार। और जो सौ फ़ोन अलग रखे थे, उनपे भी लॉस लगभग छब्बीस सौ ही रहा। मेरी लकीर का, लगभग सैंतीस सौ। तो फिर धक्के क्यों? क्योंकि जो मॉडल लकीर नहीं हैं, उनके लिए ऐसा कोई फ़ॉर्मूला नहीं होता। बड़े ए आई मॉडल भी इसी तरह, धक्के खा-खाकर सीखते हैं।

This is your first look at the maths behind AI. A model, a loss, and nudges. Next time a screen shows an estimated price, ask: which dots drew that line? A question; answer it in your head. How does the machine know it is time to stop?

हिन्दी में पढ़ें

ए आई के पीछे के गणित की ये पहली झलक है। एक मॉडल, एक लॉस, और धक्के। अगली बार कोई स्क्रीन अंदाज़े वाला दाम दिखाए, तो पूछिए: ये लकीर किन बिंदुओं पे खींची गई? एक सवाल, जवाब मन में दीजिए। मशीन को कैसे पता चलता है कि अब रुकना है?

When the next nudge barely lowers the loss. That is where training ends.

हिन्दी में पढ़ें

जब अगला धक्का लॉस को लगभग घटाता ही नहीं। वहीं ट्रेनिंग पूरी होती है।

Multiple linear regression: more columns

But a phone's price is not set by age alone. How much storage? How healthy is the battery? So each column gets its own tilt. How much price falls with age, rises with storage, and with battery. Same loss, same nudging, same formula. Just one more number to learn per column.

हिन्दी में पढ़ें

पर फ़ोन का दाम सिर्फ़ उम्र से तय नहीं होता। स्टोरेज कितनी है? बैटरी की सेहत कितनी बची है? तो हर कॉलम का अपना एक झुकाव होता है। उम्र के साथ दाम कितना गिरे, स्टोरेज के साथ कितना बढ़े, बैटरी के साथ कितना। लॉस वही, खिसकाना वही, फ़ॉर्मूला भी वही। बस हर कॉलम का एक नंबर और सीखना है।

This is a line tilted in many directions at once. It is called multiple linear regression. With all three columns, the loss on those hundred phones kept aside fell from twenty six hundred to about fifteen hundred. And now the rule we hid inside this table. Did the machine catch it?

हिन्दी में पढ़ें

ये एक लकीर है, जो कई दिशाओं में एक साथ झुकी है। इसे मल्टिपल लीनियर रिग्रेशन कहते हैं। तीनों कॉलम साथ लिए, तो उन्हीं सौ अलग रखे फ़ोनों पे लॉस छब्बीस सौ से गिरकर लगभग पंद्रह सौ रह गया। और अब वो नियम, जो हमने इस टेबल में छिपाया था। मशीन उसे पकड़ पाई या नहीं?

When we built the table, we set this: three hundred twenty less a month. Twenty eight more a gigabyte. Ninety more a battery point. The machine found: about three hundred two less, twenty nine and a half more, a hundred six more. Nobody told it. Close, but not exact. Why the gap? Two reasons.

हिन्दी में पढ़ें

टेबल बनाते वक़्त हमने ये रखा था: हर महीने तीन सौ बीस रुपये कम। हर जी बी पे अट्ठाईस रुपये ज़्यादा। बैटरी के हर पॉइंट पे नब्बे रुपये ज़्यादा। मशीन ने ढूँढा: लगभग तीन सौ दो कम, साढ़े उनतीस ज़्यादा, एक सौ छह ज़्यादा। उसे किसी ने कुछ नहीं बताया था। क़रीब, पर बिल्कुल वही नहीं। फ़र्क़ क्यों? दो वजहें हैं।

One: every seller asks a bit above or below the usual price. That difference, about fifteen hundred, is in no column. That is why our hidden rule itself misses those phones as much as the machine does. The machine could not do better. Two: older phones also have weaker batteries. When two columns move together, that difference is easily blamed on the wrong one.

हिन्दी में पढ़ें

पहली, हर बेचने वाला अपने मन से सामान्य दाम से थोड़ा ज़्यादा या कम माँगता है। ये लगभग पंद्रह सौ का फ़र्क़ किसी कॉलम में दर्ज नहीं। इसीलिए हमारा छिपा नियम ख़ुद भी उन फ़ोनों पे उतना ही चूकता है, जितना मशीन। मशीन उससे बेहतर हो ही नहीं सकती थी। दूसरी, पुराने फ़ोन की बैटरी भी कमज़ोर होती है। जो दो कॉलम साथ-साथ चलते हैं, उनके बीच वो फ़र्क़ आसानी से ग़लत कॉलम के नाम चढ़ जाता है।

And an honest note: our table had a rule to find, because we put it there. Real prices hide no rule this neat. The line is just the best straight guess.

हिन्दी में पढ़ें

और एक सच्ची बात: हमारी टेबल में ढूँढने लायक़ एक नियम था, क्योंकि हमने रखा था। असली दामों में इतना साफ़ नियम छिपा नहीं होता। लकीर बस सबसे अच्छा सीधा अंदाज़ा है।

Where linear regression fails: outliers

But a line assumes something of its own. And here comes the phone I promised at the start. Imagine an old phone that has become a collector's item. This one is made up too. Forty months old, and people pay thirty five thousand. The line says about eight and a half thousand. Off by over twenty six thousand.

हिन्दी में पढ़ें

पर लकीर भी एक बात मानकर चलती है। और यहीं वो फ़ोन आता है, जिसका वादा शुरू में किया था। मान लीजिए एक पुराना फ़ोन, जो अब कलेक्टर वाला फ़ोन बन चुका है। ये भी हमारी कल्पना है। चालीस महीने का, और लोग उसके पैंतीस हज़ार दे रहे हैं। लकीर कहती है: लगभग साढ़े आठ हज़ार। छब्बीस हज़ार से ज़्यादा की चूक।

Said plainly: a line assumes the world is straight. Every month, every phone, the same slope. A collector's phone breaks that. The older it gets, the dearer. And that it is rare is written nowhere in the table. Put five such phones into the training rows, and the whole line tilts. Every ordinary forty month phone is now priced about nine hundred higher, and new phones a little lower.

हिन्दी में पढ़ें

सीधी बात ये है: लकीर मानकर चलती है कि दुनिया सीधी है। हर महीना, हर फ़ोन, एक ही ढलान। कलेक्टर वाला फ़ोन ये बात ग़लत कर देता है। वो जितना पुराना, उतना महँगा। और वो रेयर है, ये टेबल में कहीं लिखा ही नहीं। ऐसे पाँच फ़ोन सीखने वाली टेबल में डाल दें, तो पूरी लकीर झुक जाती है। अब हर आम चालीस महीने वाला फ़ोन लगभग नौ सौ रुपये महँगा बताया जाता है, और नए फ़ोन थोड़े सस्ते।

Remember, double the miss, four times the penalty? That is why a handful of odd phones pulls the whole line toward them. So, is prediction knowing the future? No. It is a ruler laid on the past. Where a case is unlike the past, the ruler is wrong.

हिन्दी में पढ़ें

याद है, चूक दुगुनी तो सज़ा चौगुनी? इसलिए गिनती के कुछ अजीब फ़ोन पूरी लकीर को अपनी तरफ़ खींच लेते हैं। तो, क्या प्रेडिक्शन भविष्य जानना है? नहीं। वो बीते हुए कल पे रखा एक स्केल है। जो मामला बीते कल जैसा नहीं, उसपे स्केल ग़लत होगा।

How a machine guesses a price: the answer

So why did my line lose? I picked two numbers by eye. The machine measured every miss, and moved the line until the loss stopped falling. So now you tell me: how does a machine price a phone? By laying a line on past phones, and nudging it until the loss stops falling.

हिन्दी में पढ़ें

तो मेरी लकीर क्यों हारी? मैंने दो नंबर आँख से चुने थे। मशीन ने हर फ़ोन की चूक नापी, और लॉस गिरना बंद होने तक लकीर खिसकाई। तो अब बताइए: मशीन किसी फ़ोन का दाम कैसे लगाती है? पुराने फ़ोनों पे एक लकीर रखकर, और उसे तब तक खिसकाकर, जब तक लॉस गिरना बंद न हो।

Which column would you add to the table? Write it in the comments. Next question: when a loan is rejected in four seconds, who really decides? If this way of learning helped, subscribe, so you do not miss the next question.

हिन्दी में पढ़ें

आप टेबल में और कौन सा कॉलम जोड़ेंगे? कमेंट में लिखिए। अगला सवाल: लोन चार सेकंड में रिजेक्ट हो, तो असल में फ़ैसला कौन करता है? अगर ये तरीक़ा काम का लगा, तो सब्सक्राइब कीजिए, ताकि अगला सवाल आपसे न छूटे।

Ideas to keep

Prediction
A prediction is a model's output for an input; the ones that matter are for inputs unseen in training, future or not.
Linear regression
Guessing a number from a straight line is called linear regression. A heavy name for a ruler's job.
Loss
For each phone, see what the line said, and what was really asked. The gap between them is a miss. Some dots sit above the line, some below. Above or below, every miss counts. Each miss is multiplied by itself. So double the miss means four times the penalty. Then we take the average over all phones. So it is not a total; it is a miss per phone. This one number says how wrong the line is overall. It is called the loss.

THE WORKED CASE

Follow the example

For now, assume price depends on age alone. We add storage and battery later. Dots on graph paper. You pick up a ruler, and lay it so it passes through the middle of them all. Where the ruler starts tells you roughly what a brand new phone would fetch. And how steeply it tilts tells you how much price is lost each month. Here the picture stops. A ruler is always straight. Prices need not be. So the real model is a line, set by just two numbers. The twenty month phone's price? Find twenty months on the line, and read it off. My line by eye starts at eighteen thousand, and falls two fifty a month. At twenty months, thirteen thousand. Guessing a number from a straight line is called linear regression. A heavy name for a ruler's job.

Check your understanding

To price a 20-month-old phone, what does the machine need?
Answer and why

Data on old phones and their prices

A prediction is the pattern in past data applied to a new case. The phone is for sale today, not tomorrow: the machine only needs phones like it from the past, here about forty of the same age in the table. Nobody gives it the rule; it finds a line from the old phones and reads the price off that line. Knowing the future never comes into it.

How does the machine know when to stop nudging the line?
Answer and why

When a nudge no longer lowers the loss

Training is moving the line until the loss, the one number for how wrong it is, stops falling. Each nudge saves less than the one before; on our table the 18th saved under a rupee, so the machine stopped. Eighteen is not a rule: it depends on how big each step is. A line cannot pass through every dot, because the prices are spread out.

Go to the source

Kept in this browser only.