ロジスティック回帰: 損失と正則化
コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。
ロジスティック回帰 モデルは同じプロセスでトレーニングされ、 線形回帰 主な違いは 2 つあります。
以降のセクションでは、この 2 つの考慮事項について詳しく説明します。
ログ損失
線形回帰モジュールでは、 二乗損失(別名: L2 損失)を 損失関数。 二乗損失は線形回帰の場合に このモデルでは、出力値の変化率が一定です。たとえば 線形モデル $y' で= b + 3x_1$ となり、入力をインクリメントするたびに 出力値 $y'$ が 3 ずつ増加します。
しかし、ロジスティック回帰モデルの変化率は一定ではありません。 確率の計算で説明したように、 シグモイド曲線は S 字型 線形ではなく対数オッズ($z$)の値が 0 に近いほど、 $z$ の増加は、$z$ が大きいときよりも $y$ の変動が大きくなります。 正または負の数。次の表は、シグモイド関数の 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
に次第に近づくと、次の処理を行うためにより多くのメモリが必要になります。 値を追跡するために必要な精度を維持します。
代わりに、ロジスティック回帰の損失関数は、 ログ損失。「 対数損失の方程式は、変化の大きさの対数を返します。 単なる距離ではありませんログ損失は次のように計算されます。 次のようになります。
\(\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 つの戦略のうちのどれに該当するかを示します。
- L2 正則化
- 早期停止: 損失が発生してもトレーニングを停止するトレーニング ステップの数を制限すると、 減少し続けています
で確認できます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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**](/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\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[**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)"]]