رگرسیون لجستیک: از دست دادن و منظم شدن
با مجموعهها، منظم بمانید ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
مدلهای رگرسیون لجستیک با استفاده از فرآیند مشابه مدلهای رگرسیون خطی با دو تمایز کلیدی آموزش داده میشوند:
بخش های بعدی این دو ملاحظات را عمیق تر مورد بحث قرار می دهد.
از دست دادن گزارش
در ماژول رگرسیون خطی ، از تلفات مربعی (که از دست دادن L 2 نیز نامیده می شود) به عنوان تابع ضرر استفاده کردید. تلفات مربعی برای یک مدل خطی که در آن نرخ تغییر مقادیر خروجی ثابت است به خوبی کار می کند. به عنوان مثال، با توجه به مدل خطی $y' = b + 3x_1$، هر بار که مقدار ورودی $x_1$ را 1 افزایش می دهید، مقدار خروجی $y'$ 3 افزایش می یابد.
با این حال، نرخ تغییر یک مدل رگرسیون لجستیک ثابت نیست . همانطور که در محاسبه یک احتمال دیدید، منحنی سیگموئید به جای خطی، s شکل است. وقتی مقدار log-odds ($z$) به 0 نزدیکتر است، افزایشهای کوچک در $z$ منجر به تغییرات بسیار بزرگتری به $y$ میشود تا زمانی که $z$ یک عدد مثبت یا منفی بزرگ است. جدول زیر خروجی تابع سیگموئید را برای مقادیر ورودی از 5 تا 10 و همچنین دقت متناظر مورد نیاز برای ثبت تفاوت در نتایج را نشان می دهد.
ورودی | خروجی لجستیک | ارقام مورد نیاز دقت |
---|
5 | 0.993 | 3 |
6 | 0.997 | 3 |
7 | 0.999 | 3 |
8 | 0.9997 | 4 |
9 | 0.9999 | 4 |
10 | 0.99998 | 5 |
اگر از مجذور تلفات برای محاسبه خطاها برای تابع سیگموئید استفاده میکردید، چون خروجی به 0
و 1
نزدیکتر و نزدیکتر میشد، برای حفظ دقت لازم برای ردیابی این مقادیر به حافظه بیشتری نیاز دارید.
در عوض، تابع ضرر برای رگرسیون لجستیک Log Loss است. معادله Log Loss لگاریتم بزرگی تغییر را به جای فاصله بین داده تا پیشبینی برمیگرداند. Log Los به صورت زیر محاسبه می شود:
\(\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\).
منظم سازی در رگرسیون لجستیک
منظمسازی ، مکانیزمی برای جریمه کردن پیچیدگی مدل در طول آموزش، در مدلسازی رگرسیون لجستیک بسیار مهم است. بدون منظمسازی، ماهیت مجانبی رگرسیون لجستیک در مواردی که مدل دارای تعداد زیادی ویژگی است، ضرر را به سمت صفر نگه میدارد. در نتیجه، اکثر مدلهای رگرسیون لجستیک از یکی از دو استراتژی زیر برای کاهش پیچیدگی مدل استفاده میکنند:
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2024-10-31 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-10-31 بهوقت ساعت هماهنگ جهانی."],[[["\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)"]]