Hello, my name is Christian Rudder, and I was one of the founders of OkCupid. It's now one of the biggest dating sites in the United States. Like most everyone at the site, I was a math major, As you may expect, we're known for the analytic approach we take to love. We call it our matching algorithm. Basically, OkCupid's matching algorithm helps us decide whether two people should go on a date. We built our entire business around it. Now, algorithm is a fancy word, and people like to drop it like it's this big thing. But really, an algorithm is just a systematic, step-by-step way to solve a problem. It doesn't have to be fancy at all. Here in this lesson, I'm going to explain how we arrived at our particular algorithm, so you can see how it's done. Now, why are algorithms even important? Why does this lesson even exist? Well, notice one very significant phrase I used above: they are a step-by-step way to solve a problem, and as you probably know, computers excel at step-by-step processes. A computer without an algorithm is basically an expensive paperweight. And since computers are such a pervasive part of everyday life, algorithms are everywhere. The math behind OkCupid's matching algorithm is surprisingly simple. It's just some addition, multiplication, a little bit of square roots. The tricky part in designing it was figuring out how to take something mysterious, human attraction, and break it into components that a computer can work with. The first thing we needed to match people up was data, something for the algorithm to work with. The best way to get data quickly from people is to just ask for it. So we decided that OkCupid should ask users questions, stuff like, "Do you want to have kids one day?" "How often do you brush your teeth?" "Do you like scary movies?" And big stuff like, "Do you believe in God?" Now, a lot of the questions are good for matching like with like, that is, when both people answer the same way. For example, two people who are both into scary movies are probably a better match than one person who is and one who isn't. But what about a question like, "Do you like to be the center of attention?" If both people in a relationship are saying yes to this, they're going to have massive problems. We realized this early on, and so we decided we needed a bit more data from each question. We had to ask people to specify not only their own answer, but the answer they wanted from someone else. That worked really well. But we needed one more dimension. Some questions tell you more about a person than others. For example, a question about politics, something like, "Which is worse: book burning or flag burning?" might reveal more about someone than their taste in movies. And it doesn't make sense to weigh all things equally, so we added one final data point. For everything that OkCupid asks you, you have a chance to tell us the role it plays in your life. And this ranges from irrelevant to mandatory. So now, for every question, we have three things for our algorithm: first, your answer; second, how you want someone else -- your potential match -- to answer; and third, how important the question is to you at all. With all this information, OkCupid can figure out how well two people will get along. The algorithm crunches the numbers and gives us a result. As a practical example, let's look at how we'd match you with another person. Let's call him "B." Your match percentage with B is based on questions you've both answered. Let's call that set of common questions "s." As a very simple example, we use a small set "s" with just two questions in common, and compute a match from that. Here are our two example questions. The first one, let's say, is, "How messy are you?" And the answer possibilities are: very messy, average and very organized. And let's say you answered "very organized," and you'd like someone else to answer "very organized," and the question is very important to you. Basically, you're a neat freak. You're neat, you want someone else to be neat, and that's it. And let's say B is a little bit different. He answered "very organized" for himself, but "average" is OK with him as an answer from someone else, and the question is only a little important to him. Let's look at the second question, from our previous example: "Do you like to be the center of attention?" The answers are "yes" and "no." You've answered "no," you want someone else to answer "no," and the question is only a little important to you. Now B, he's answered "yes." He wants someone else to answer "no," because he wants the spotlight on him, and the question is somewhat important to him. So, let's try to compute all of this. Our first step is, since we use computers to do this, we need to assign numerical values to ideas like "somewhat important" and "very important," because computers need everything in numbers. We at OkCupid decided on the following scale: "Irrelevant" is worth 0. "A little important" is worth 1. "Somewhat important" is worth 10. "Very important" is 50. And "absolutely mandatory" is 250. Next, the algorithm makes two simple calculations. The first is: How much did B's answers satisfy you? That is, how many possible points did B score on your scale? Well, you indicated that B's answer to the first question, about messiness, was very important to you. It's worth 50 points and B got that right. The second question is worth only 1, because you said it was only a little important. B got that wrong, so B's answers were 50 out of 51 possible points. That's 98% satisfactory. Pretty good. The second question the algorithm looks at is: How much did you satisfy B? Well, B placed 1 point on your answer to the messiness question and 10 on your answer to the second. Of those 11, that's 1 plus 10, you earned 10 -- you guys satisfied each other on the second question. So your answers were 10 out of 11 equals 91 percent satisfactory to B. That's not bad. The final step is to take these two match percentages and get one number for the both of you. To do this, the algorithm multiplies your scores, then takes the nth root, where "n" is the number of questions. Because s, which is the number of questions in this sample, is only 2, we have: match percentage equals the square root of 98 percent times 91 percent. That equals 94 percent. That 94 percent is your match percentage with B. It's a mathematical expression of how happy you'd be with each other, based on what we know. Now, why does the algorithm multiply, as opposed to, say, average the two match scores together, and do the square-root business? In general, this formula is called the geometric mean. It's a great way to combine values that have wide ranges and represent very different properties. In other words, it's perfect for romantic matching. You've got wide ranges and you've got tons of different data points, like I said, about movies, politics, religion -- everything. Intuitively, too, this makes sense. Two people satisfying each other 50 percent should be a better match than two others who satisfy 0 and 100, because affection needs to be mutual. After adding a little correction for margin of error, in the case where we have a small number of questions, like we do in this example, we're good to go. Any time OkCupid matches two people, it goes through the steps we just outlined. First it collects data about your answers, then it compares your choices and preferences to other people's in simple, mathematical ways. This, the ability to take real-world phenomena and make them something a microchip can understand, is, I think, the most important skill anyone can have these days. Like you use sentences to tell a story to a person, you use algorithms to tell a story to a computer. If you learn the language, you can go out and tell your stories. I hope this will help you do that.
สวัสดีครับ ผมชื่อ คริสเตียน รัดเดอร์ (Christian Rudder) และผมก็เป็นหนึ่งในผู้ก่อตั้ง โอเคคิวปิด (OKCupid) ตอนนี้มันเป็นหนึ่งในเว็บหาคู่ ที่ใหญ่ที่สุดในอเมริกา ก็เหมือน ๆ กับพนักงานส่วนใหญ่ที่นั่น ผมจบเอกคณิตศาสตร์ และอย่างที่คุณคาด พวกเราขึ้นชื่อในเรื่องการวิเคราะห์ข้อมูล พวกเราได้นำมันมาใช้ในการหาคู่ พวกเราเรียกมันว่า อัลกอริทึมการจับคู่ (matching algorithm) อัลกอริทึมที่ว่าของ โอเค คิวปิด ช่วยเราในการตัดสินว่า คนสองคนนี้ควรไปเดทกันหรือไม่ มันเป็นหัวใจของบริษัทเราเลยล่ะ อัลกอริทึม ฟังดูเป็นคำหรูหรา ผู้คนชอบพูดถึงมันเหมือนว่ามันเป็นอะไรใหญ่โต แต่จริง ๆ แล้ว อัลกอริทึม ก็เป็นแค่วิธีในการแก้ปัญหา อย่างเป็นระบบและเป็นขั้นตอน มันไม่จำเป็นต้องมีอะไรหรูหราเลยสักนิด ในบทเรียนนี้ ผมจะอธิบายว่า เราคิดอัลกอริทึมของเราขึ้นมาได้อย่างไร คุณจะได้เห็นที่มาของมัน แล้วทำไมอัลกอริทึมทั้งหลายจึงสำคัญ ทำไมต้องมีบทเรียนอันนี้ สังเกตเห็นคำคำหนึ่งที่ผมได้พูดไปไหม พวกมันเป็นวิธีแก้ปัญหาอย่างเป็นขั้นเป็นตอน บางทีคุณอาจจะรู้อยู่แล้วว่า คอมพิวเตอร์เก่งในเรื่องการทำงานเป็นขั้นตอน คอมพิวเตอร์ที่ปราศจากอัลกอริทึม ก็เป็นแค่ที่ทับกระดาษแพง ๆ และเนื่องจากคอมพิวเตอร์นั้น พบได้ทั่วไปในชีวิตประจำวัน อัลกอริทึมจึงมีอยู่ทุกหนทุกแห่ง คณิตศาสตร์เบื้องหลังอัลกอริทึมการจับคู่ ของโอเค คิวปิด นั้น เรียบง่ายจนน่าตกใจ มันใช้แค่ การบวก การคูณ และการถอดราก นิดหน่อย แต่จุดที่ยากในการออกแบบมัน ก็คือว่า จะทำอย่างไรกับข้อมูลที่ดูลึกลับ อย่างแรงดึงดูดระหว่างคนสองคน และย่อยมันเป็นองค์ประกอบ ที่คอมพิวเตอร์สามารถนำไปวิเคราะห์ได้ เอาล่ะ สิ่งแรกที่จำเป็น สำหรับการจับคู่ก็คือ ข้อมูล อะไรบางอย่างที่อัลกอริทึมเอาไปใช้ วิธีที่ดีที่สุดที่จะได้ข้อมูลจากผู้คน ก็คือ การถามจากพวกเขานั่นเอง เราจึงตัดสินใจว่า โอเค คิวปิด ควรถามคำถามกับผู้ใช้งาน อย่างเช่น "ในอนาคต คุณต้องการมีลูกหรือไม่" และ "คุณแปรงฟันบ่อยแค่ไหน" "คุณชอบหนังสยองขวัญหรือไม่" หรือคำถามหนัก ๆ อย่าง "คุณเชื่อในพระเจ้าหรือไม่" ทีนี้ หลาย ๆ คำถามนั้นเป็นประโยชน์ สำหรับการจับคู่คนที่ชอบอะไรเหมือน ๆ กัน นั่นเกิดขึ้นเมื่อคู่ตอบคำถาม ไปในทางเดียวกัน เช่น คนสองคนที่เป็นแฟนหนังสยองขวัญ ก็น่าจะเข้ากันได้ดี มากกว่า กรณีที่คนนึงชอบ แต่อีกคนไม่ชอบ แล้วถ้าเกิดเป็นคำถามอย่างเช่น "คุณชอบที่จะตกเป็นจุดสนใจหรือไม่" ล่ะ ถ้าเกิดคู่รักทั้งสอง ตอบใช่ทั้งคู่ นั่นคงจะทำให้เกิดปัญหาใหญ่ตามมา พวกเราตะหนักดีถึงเรื่องเหล่านี้ เราจึงคิดว่าเราต้องการ ข้อมูลที่ลึกลงไปอีกสำหรับแต่ละคำถาม เราต้องการให้พวกเขา ไม่เพียงแค่ระบุคำตอบของพวกเขาเอง แต่ยังต้องระบุคำตอบที่อยากได้จากอีกคนด้วย ซึ่งมันให้ผลลัพธ์ที่ดีมาก แต่เรายังต้องการอะไรเพิ่มอีกสักอย่าง บางคำถามนั้นบอกคุณเกี่ยวคนคนหนึ่ง ได้ดีกว่าคำถามอื่น เช่น คำถามเกี่ยวกับการเมือง อย่างเช่น "อย่างไหนแย่กว่าระหว่าง เผาหนังสือ กับ เผาธง" อาจเผยให้เห็นตัวตนของคนคนหนึ่ง ได้ดีกว่าคำถามเกี่ยวกับหนัง มันดูไม่มีเหตุผล ที่จะให้ทุกคำถามมีน้ำหนักเท่ากันหมด ดังนั้นเราจึงเพิ่มตัวแปรสุดท้ายเข้าไปอีกอันนึง สำหรับทุก ๆ คำถามที่ โอเค คิวปิด ถามคุณ คุณมีโอกาสที่จะบอกเรา ว่าคุณซีเรียสกับมันแค่ไหน ตั้งแต่เป็นเรื่องขี้ปะติ๋ว ไปจนถึงเป็นเรื่องคอขาดบาดตาย ทีนี้ สำหรับทุก ๆ คำถาม เราก็ได้ 3 สิ่งสำหรับอัลกอริทึมของเรา หนึ่ง คำตอบของคุณเอง สอง คำตอบที่คุณอยากให้คนอื่น คนที่เป็นว่าที่คู่ของคุณ ให้คำตอบ และสาม คำถามนี้สำคัญกับคุณแค่ไหน ด้วยข้อมูลทั้งหมดนี้ โอเคคิวปิด สามารถบอกได้ว่าคนสองคนนี้ จะไปกันได้ดีแค่ไหน อัลกอริทึมจะวิเคราะห์ตัวเลขและให้ผลลัพธ์ออกมา ลองมาดูตัวอย่างกัน ดูซิว่า เราทำการจับคู่คุณเข้ากับคนอื่นได้อย่างไร สมมติให้เขาชื่อ นายบี เปอร์เซ็นต์ที่คุณจะคู่กับ นายบี ขึ้นอยู่กับ คำถามที่คุณทั้งคู่ตอบ เราตั้งชื่อมันว่า ชุดคำถามทั่วไป "เอส" ในตัวอย่างนี้ เราใช้คำถามจากชุดคำถาม "เอส" เพียงแค่ 2 คำถาม นำมาคำนวนหาความเข้าคู่กัน และนี่เป็นตัวอย่างคำถาม 2 ข้อนั้น ข้อที่หนึ่ง "คุณเป็นคนซกมกแค่ไหน" คำตอบก็เป็นได้ตั้งแต่ ซกมกสุด ๆ ระดับปกติ และเรียบร้อยสุด ๆ สมมติว่าคำตอบของคุณคือ "เรียบร้อยสุด ๆ" คุณก็คงจะอยากให้คู่ของคุณตอบ "เรียบร้อยสุด ๆ" เช่นกัน และคำถามนี้ถือว่ามีความสำคัญกับคุณมาก สำหรับคุณแล้วทุกอย่างต้องหมดจดเรียบร้อย คุณเป็นคนเรียบร้อย คุณต้องการให้อีกคนเป็นระเบียบเรียบร้อย ก็แค่นั้นเอง ส่วนนาย บี นั้นต่างออกไปเล็กน้อย เขาตอบว่า "เรียบร้อยสุด ๆ" สำหรับตัวเขา แต่ตอบว่า "ระดับปกติ" ก็โอเคสำหรับเขา สำหรับคำตอบของอีกคน และเขาก็ไม่ค่อยซีเรียสกับคำถามนี้สักเท่าไร ทีนี้ลองมาดูคำถามที่สองกัน มันมาจากหนึ่งในตัวอย่างก่อนโน้น "คุณชอบที่จะตกเป็นจุดสนใจใช่หรือไม่" คำตอบเป็นได้แค่ ใช่ กับ ไม่ใช่ ทีนี้คุณตอบว่า "ไม่ใช่" คำตอบที่คุณอยากให้อีกคนตอบ คือ "ไม่ใช่" และคำถามนี้ก็ไม่ค่อยสำคัญกับคุณสักเท่าไร ส่วน นาย บี คำตอบของเขาคือ "ใช่" คำตอบที่เขาอยากให้อีกคนตอบ คือ "ไม่ใช่" เพราะเขาต้องการเป็นจุดเด่น และคำถามนี้ก็ค่อนข้างสำคัญกับเขามาก เราลองมาวิเคราะห์ผลทั้งหมดนี้กัน อันดับแรก คือ เนื่องจากเราต้องอาศัยคอมพิวเตอร์ เราจึงต้องกำหนดค่าต่าง ๆ เป็นตัวเลข สำหรับคำตอบเช่น "ค่อนข้างสำคัญ" หรือ "สำคัญมาก" เพราะคอมพิวเตอร์เข้าใจแต่ตัวเลข พวกเราที่ โอเคคิวปิด กำหนดค่าต่าง ๆ ตามนี้ "ไม่สำคัญเลย" มีค่าเท่ากับ 0 "สำคัญเล็กน้อย" มีค่าเท่ากับ 1 "ค่อนข้างสำคัญ" มีค่าเท่ากับ 10 "สำคัญมาก" มีค่าเท่ากับ 50 "เป็นเรื่องคอขาดบาดตาย" มีค่าเท่ากับ 250 อัลกอริทึมก็จะทำการคำนวนง่าย ๆ 2 อย่าง อย่างแรก คุณพึงพอใจคำตอบของ นายบี แค่ไหน หรือก็คือ ความเป็นไปได้ของคะแนนของนายบี ตามระดับของคุณเป็นเท่าไร คุณบอกว่า คำตอบของนายบี สำหรับคำถามแรกเกี่ยวกับความซกมก สำคัญมากสำหรับคุณ มันจึงมีค่า 50 คะแนน และนายบีก็ตอบได้ถูกใจคุณ ส่วนคำถามที่สองมีค่าแค่ 1 เพราะคุณบอกว่ามันสำคัญแค่เล็กน้อยเท่านั้น และนายบีก็ตอบไม่เข้าเป้า ดังนั้นคะแนนจากคำตอบของนายบี จึงเท่ากับ 50 เต็ม 51 หรือ คะแนนความพึงพอใจเท่ากับ 98% ถือว่าดีทีเดียว และ คำถามที่สองของที่อัลกอริทึมจะคำนวน ก็คือนายบีจะพึงพอใจคุณแค่ไหน สำหรับนายบี คำถามเรื่องระดับความซกมก มีค่าแค่ 1 คะแนน ส่วนคำถามข้อที่สองมีค่า 10 คะแนน ดังนั้นคะแนนเต็ม 11 ซึ่งคือ 1 บวก 10 คุณก็ทำได้ 10 คะแนน คุณทั้งคู่พึงพอใจกับคำถามที่สองของแต่ละฝ่าย คุณได้คะแนน 10 เต็ม 11 เท่ากับสำหรับนายบีแล้ว คุณมีความพึงพอใจ 91% มันก็ไม่เลวนัก ขั้นตอนสุดท้ายก็คือ นำค่าเปอร์เซ็นต์ทั้งสองค่านั้น ทำให้เป็นค่าเดียวกันสำหรับคุณทั้งสอง โดยอัลกอริทึมจะนำค่าทั้งสองมาคูณกัน แล้วถอดรากที่ n โดย n คือจำนวนของคำถามทั้งหมด แต่ s ซึ่งคือจำนวนคำถามในตัวอย่างนี้ มีแค่ 2 ข้อ เปอร์เซ็นต์การจับคู่จึงเท่ากับ รากที่สองของ 98% คูณ 91% ซึ่งเท่ากับ 94% 94% ก็คือโอกาสที่คุณจะเข้ากันได้กับนายบี มันเป็นค่าตัวเลขที่แสดงว่า คุณน่าจะมีความสุขด้วยกันแค่ไหน โดยอาศัยจากข้อมูลที่เรามี แล้วทำไมอัลกอริทึมนี้ถึงต้องเอาค่ามาคูณกัน แทนที่จะแค่หาค่าเฉลี่ยก็พอ แถมยังมีการถอดรากอีกทำไมกัน ทั่วไปแล้ว สูตรคณิตนี้มีชื่อว่า ค่าเฉลี่ยเรขาคณิต (Geometric Mean) ซึ่งเป็นวิธีที่ดีที่ใช้ในการหาค่าเฉลี่ยของข้อมูล ที่มีพิสัยของข้อมูลกว้าง และมีที่มาของข้อมูลหลากหลาย อีกนัยก็คือ มันเหมาะที่จะใช้กับการหาคู่มาก คุณมีข้อมูลที่มีพิสัยกว้าง คุณมีการให้คะแนนที่หลากหลายมาตรฐาน อย่างที่เคยพูดถึงข้อมูลที่เกี่ยวกับภาพยนตร์ เกี่ยวกับการเมือง เกี่ยวกับศาสนา หรือในทุก ๆ เรื่อง ลึก ๆ แล้ว มันดูเข้าท่า คนสองคนที่มีระดับความพึงพอใจต่อกันที่ 50% ควรจะเข้ากันได้ดีกว่า กรณีระดับความพอใจ ที่คนนึงได้ 0 แต่อีกคนได้ 100 เพราะความรักเป็นเรื่องระหว่างคนสองคน หลังจากที่เราปรับแก้เล็กน้อย สำหรับค่าความคลาดเคลื่อน ในกรณีที่ชุดคำถามมีคำถามน้อยมาก ๆ เหมือนที่ทำในตัวอย่าง มันก็พร้อมใช้งานได้จริง เมื่อใดก็ตามที่ โอเคคิวปิด จับคู่ระหว่างคนสองคน มันก็จะทำไปตามขั้นตอนอย่างที่ได้กล่าวไป เริ่มจาก รวบรวมคำตอบของคุณ ต่อมา เปรียบเทียบคำตอบและความชอบของคุณ กับคนอื่น ด้วยคณิตศาสตร์ง่าย ๆ การที่เราสามารถ นำปรากฎการณ์ต่าง ๆ ในชีวิตจริง แล้วทำให้เป็นอะไรที่คอมพิวเตอร์เข้าใจได้ ผมคิดว่าสิ่งนี้ เป็นทักษะที่สำคัญที่สุด ที่ใครก็ควรมีในทุกวันนี้ เหมือนกับที่คุณใช้ประโยค ในการเล่าเรื่องราวแก่คนอื่น คุณก็ใช้อัลกอริทึม ในการเล่าเรื่องราวแก่คอมพิวเตอร์ ถ้าคุณได้เรียนรู้ภาษาของมัน คุณก็จะสามารถออกไปบอกเล่าเรื่องราวของคุณได้ นี่เป็นสิ่งที่ผมอยากให้คุณทำดู