การถดถอยแบบโลจิสติก: การสูญเสียและการทำให้เป็นมาตรฐาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การถดถอยแบบโลจิสติกส์
โมเดลจะได้รับการฝึกด้วยกระบวนการเดียวกับ
การถดถอยเชิงเส้น
ซึ่งมีความแตกต่างสำคัญ 2 ประการ ได้แก่
ส่วนต่อไปนี้จะกล่าวถึงข้อควรพิจารณาทั้ง 2 ข้อในเชิงลึกยิ่งขึ้น
การสูญหายของบันทึก
ในโมดูลการถดถอยเชิงเส้น
คุณใช้การขาดทุนกำลังสอง (หรือที่เรียกว่า
L2 ) เป็น
ฟังก์ชันหายไป
การสูญเสียในสี่เหลี่ยมทำงานได้ดีกับเส้นตรง
รูปแบบที่อัตราการเปลี่ยนแปลงของค่าเอาต์พุตคงที่ ตัวอย่างเช่น
สำหรับโมเดลเชิงเส้น $y' = b + 3x_1$ ทุกครั้งที่คุณเพิ่มอินพุต
ค่า $x_1$ คูณ 1 ค่าเอาต์พุต $y'$ จะเพิ่มขึ้น 3
แต่อัตราการเปลี่ยนแปลงของโมเดลการถดถอยแบบโลจิสติกส์ไม่คงที่
ดังที่แสดงในการคำนวณความน่าจะเป็น ค่า
เส้นโค้ง sigmoid เป็นรูปตัว S
แทนที่จะเป็นแบบเชิงเส้น เมื่อค่าอัตราต่อรอง ($z$) เข้าใกล้ 0 จะน้อย
การเพิ่มขึ้นใน $z$ จะส่งผลให้เกิดการเปลี่ยนแปลงเป็น $y$ มากกว่าในขณะที่ $z$ มีขนาดใหญ่มาก
จำนวนบวกหรือลบ ตารางต่อไปนี้แสดงฟังก์ชัน sigmoid
สำหรับค่าอินพุตตั้งแต่ 5 ถึง 10 รวมทั้งความแม่นยำที่เกี่ยวข้อง
เพื่อให้เห็นความแตกต่างในผลลัพธ์
อินพุต |
เอาต์พุตแบบโลจิสติกส์ |
จำนวนหลักของความแม่นยำที่กำหนด |
5 |
0.993 |
3 |
6 |
0.997 |
3 |
7 |
0.999 |
3 |
8 |
0.9997 |
4 |
9 |
0.9,999 |
4 |
10 |
0.99998 |
5 |
ถ้าคุณใช้การขาดทุนยกกำลังสองเพื่อคำนวณข้อผิดพลาดสำหรับฟังก์ชัน sigmoid เช่น
เอาต์พุตของคุณเข้าใกล้ 0
และ 1
มากขึ้นแล้ว คุณจะต้องมีหน่วยความจำมากขึ้นเพื่อ
คงความแม่นยำที่ต้องใช้ในการติดตามค่าเหล่านี้ไว้
ฟังก์ชันการสูญเสียการถดถอยแบบโลจิสติกส์คือ
การสูญหายของบันทึก
สมการการสูญหายของบันทึกจะแสดงลอการิทึมของขนาดของการเปลี่ยนแปลง
มากกว่าระยะทางระหว่างข้อมูลสู่การคาดการณ์ การสูญหายของบันทึกมีวิธีคำนวณดังนี้
ดังต่อไปนี้:
\(\text{Log Loss} = \sum_{(x,y)\in D} -y\log(y') - (1 - y)\log(1 - y')\)
โดยมี
-
\((x,y)\in D\) คือชุดข้อมูลซึ่งมีตัวอย่างที่มีป้ายกำกับหลายรายการ
\((x,y)\) คู่
-
\(y\) คือป้ายกำกับในตัวอย่างที่ติดป้ายกำกับ เนื่องจากนี่เป็นการถดถอยแบบโลจิสติกส์
ทุกค่าของ \(y\) ต้องเป็น 0 หรือ 1
-
\(y'\) คือการคาดการณ์ของโมเดลของคุณ (อยู่ระหว่าง 0 ถึง 1) เมื่อพิจารณาจากชุด
ใน \(x\)
การกำหนดกฎเกณฑ์ในการถดถอยแบบโลจิสติก
การทำให้เป็นมาตรฐาน ซึ่งเป็นกลไกสำหรับ
การลดความซับซ้อนของโมเดลในระหว่างการฝึกเป็นสิ่งที่สำคัญอย่างยิ่งในด้านโลจิสติกส์
การสร้างแบบจำลองการถดถอย หากไม่ได้กำหนดมาตรฐานไว้ โลจิสติกส์ที่มีลักษณะไม่ก่อให้เกิดอาการ
การถดถอยจะทำให้สูญเสียค่าเป็น 0 ในกรณีที่โมเดลมีค่า
ฟีเจอร์จำนวนมาก ดังนั้น โมเดลการถดถอยแบบโลจิสติกส์ส่วนใหญ่จะใช้
ในการลดความซับซ้อนของโมเดล 2 ข้อดังต่อไปนี้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-08-13 UTC
[null,null,["อัปเดตล่าสุด 2024-08-13 UTC"],[[["\u003cp\u003eLogistic regression models are trained similarly to linear regression models but use Log Loss instead of squared loss and require regularization.\u003c/p\u003e\n"],["\u003cp\u003eLog Loss is used in logistic regression because the rate of change isn't constant, requiring varying precision levels unlike squared loss used in linear regression.\u003c/p\u003e\n"],["\u003cp\u003eRegularization, such as L2 regularization or early stopping, is crucial in logistic regression to prevent overfitting due to the model's asymptotic nature.\u003c/p\u003e\n"]]],[],null,["# Logistic regression: Loss and regularization\n\n[**Logistic regression**](/machine-learning/glossary#logistic_regression)\nmodels are trained using the same process as\n[**linear regression**](/machine-learning/crash-course/linear-regression)\nmodels, with two key distinctions:\n\n- Logistic regression models use [**Log Loss**](/machine-learning/glossary#Log_Loss) as the loss function instead of [**squared loss**](/machine-learning/glossary#l2-loss).\n- Applying [regularization](/machine-learning/crash-course/overfitting/regularization) is critical to prevent [**overfitting**](/machine-learning/glossary#overfitting).\n\nThe following sections discuss these two considerations in more depth.\n\nLog Loss\n--------\n\nIn the [Linear regression module](/machine-learning/crash-course/linear-regression),\nyou used [**squared loss**](/machine-learning/glossary#l2-loss) (also called\nL~2~ loss) as the\n[**loss function**](/machine-learning/glossary#loss-function).\nSquared loss works well for a linear\nmodel where the rate of change of the output values is constant. For example,\ngiven the linear model $y' = b + 3x_1$, each time you increment the input\nvalue $x_1$ by 1, the output value $y'$ increases by 3.\n\nHowever, the rate of change of a logistic regression model is *not* constant.\nAs you saw in [Calculating a probability](/machine-learning/crash-course/logistic-regression/sigmoid-function), the\n[**sigmoid**](/machine-learning/glossary#sigmoid-function) curve is s-shaped\nrather than linear. When the log-odds ($z$) value is closer to 0, small\nincreases in $z$ result in much larger changes to $y$ than when $z$ is a large\npositive or negative number. The following table shows the sigmoid function's\noutput for input values from 5 to 10, as well as the corresponding precision\nrequired to capture the differences in the results.\n\n| input | logistic output | required digits of precision |\n|-------|-----------------|------------------------------|\n| 5 | 0.993 | 3 |\n| 6 | 0.997 | 3 |\n| 7 | 0.999 | 3 |\n| 8 | 0.9997 | 4 |\n| 9 | 0.9999 | 4 |\n| 10 | 0.99998 | 5 |\n\nIf you used squared loss to calculate errors for the sigmoid function, as the\noutput got closer and closer to `0` and `1`, you would need more memory to\npreserve the precision needed to track these values.\n\nInstead, the loss function for logistic regression is\n[**Log Loss**](/machine-learning/glossary#Log_Loss). The\nLog Loss equation returns the logarithm of the magnitude of the change, rather\nthan just the distance from data to prediction. Log Loss is calculated as\nfollows:\n\n\\\\(\\\\text{Log Loss} = \\\\sum_{(x,y)\\\\in D} -y\\\\log(y') - (1 - y)\\\\log(1 - y')\\\\)\n\n\u003cbr /\u003e\n\nwhere:\n\n- \\\\((x,y)\\\\in D\\\\) is the dataset containing many labeled examples, which are \\\\((x,y)\\\\) pairs.\n- \\\\(y\\\\) is the label in a labeled example. Since this is logistic regression, every value of \\\\(y\\\\) must either be 0 or 1.\n- \\\\(y'\\\\) is your model's prediction (somewhere between 0 and 1), given the set of features in \\\\(x\\\\).\n\nRegularization in logistic regression\n-------------------------------------\n\n[**Regularization**](/machine-learning/glossary#regularization), a mechanism for\npenalizing model complexity during training, is extremely important in logistic\nregression modeling. Without regularization, the asymptotic nature of logistic\nregression would keep driving loss towards 0 in cases where the model has a\nlarge number of features. Consequently, most logistic regression models use one\nof the following two strategies to decrease model complexity:\n\n- [L~2~ regularization](/machine-learning/crash-course/overfitting/regularization)\n- [Early stopping](/machine-learning/crash-course/overfitting/regularization#early_stopping_an_alternative_to_complexity-based_regularization): Limiting the number of training steps to halt training while loss is still decreasing.\n\n| **Note:** You'll learn more about regularization in the [Datasets, Generalization, and Overfitting](/machine-learning/crash-course/overfitting) module of the course.\n| **Key terms:**\n|\n| - [Gradient descent](/machine-learning/glossary#gradient-descent)\n| - [Linear regression](/machine-learning/glossary#linear_regression)\n| - [Log Loss](/machine-learning/glossary#Log_Loss)\n| - [Logistic regression](/machine-learning/glossary#logistic_regression)\n| - [Loss function](/machine-learning/glossary#loss-function)\n| - [Overfitting](/machine-learning/glossary#overfitting)\n| - [Regularization](/machine-learning/glossary#regularization)\n- [Squared loss](/machine-learning/glossary#l2-loss) \n[Help Center](https://support.google.com/machinelearningeducation)"]]