邏輯迴歸:遺失與正規化
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
邏輯迴歸
訓練時使用的程序
線性迴歸
其中有兩項主要差異:
以下章節將深入探討這兩項注意事項。
對數損失
在線性迴歸模組中
您使用了平方損失 (也稱為
L2 損失)
損失函式。
方形損失很適合用於線性
輸出值變化速率是固定的模型。例如:
已知線性模式 $y'= b + 3x_1$,每次輸入時就會增加
$x_1$ 乘以 1,輸出值 $y'$ 會加 3。
不過,邏輯迴歸模型的變更速率「不是」常數。
如「計算機率」一節中所述
S 函數曲線為形狀
而非線性當對數機率 ($z$) 值接近 0 時,小號
$z$ 的增加幅度比 $z$ 大時增加 $y$
必須是正數或負數下表顯示 S 函數的
輸出內容的精確度,介於 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 |
如果您使用平方損失來計算 S 函數的誤差,
輸出內容更接近 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\)中 Kubernetes 的功能
邏輯迴歸中的正規化
正規化,也就是
降低模型在訓練期間的複雜度,在邏輯上是極為重要的
以及迴歸模型沒有正則化時,物流不合乎
如果模型有其他模型
並提供大量功能因此,大部分邏輯迴歸模型
以下兩種減少模型複雜度的策略:
,瞭解如何調查及移除這項存取權。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-08-13 (世界標準時間)。
[null,null,["上次更新時間:2024-08-13 (世界標準時間)。"],[[["\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)"]]