gradient_descent
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
gradient_descent [2025/08/21 12:18] – [R output] hkimscil | gradient_descent [2025/08/21 16:24] (current) – [Gradient descend] hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Gradient Descent ====== | ====== Gradient Descent ====== | ||
- | ====== explanation ====== | ||
- | |||
- | ====== Why normalize (scale or make z-score) xi ====== | ||
- | x 변인의 측정단위로 인해서 b 값이 결정되게 되는데 이 때의 b값은 상당하고 다양한 범위를 가질 수 있다. 가령 월 수입이 (인컴) X 라고 한다면 우리가 추정해야 (추적해야) 할 b값은 수백만이 될 수도 있다.이 값을 gradient로 추적하게 된다면 너무도 많은 iteration을 거쳐야 할 수 있다. 변인이 바뀌면 이 b의 추적범위도 드라마틱하게 바뀌게 된다. 이를 표준화한 x 점수를 사용하게 된다면 일정한 learning rate와 iteration만으로도 정확한 a와 b를 추적할 수 있게 된다. | ||
- | |||
- | ====== How to unnormalize (unscale) a and b ====== | ||
- | \begin{eqnarray*} | ||
- | y & = & a + b * x \\ | ||
- | & & \text{we use z instead of x} \\ | ||
- | & & \text{and } \\ | ||
- | & & z = \frac{(x - \mu)}{\sigma} \\ | ||
- | & & \text{suppose that the result after calculation be } \\ | ||
- | y & = & k + m * z \\ | ||
- | & = & k + m * \frac{(x - \mu)}{\sigma} \\ | ||
- | & = & k + \frac{m * x}{\sigma} - \frac{m * \mu}{\sigma} | ||
- | & = & k - \frac{m * \mu}{\sigma} + \frac{m * x}{\sigma} | ||
- | & = & k - \frac{\mu}{\sigma} * m + \frac{m}{\sigma} * x \\ | ||
- | & & \text{therefore, | ||
- | a & = & k - \frac{\mu}{\sigma} * m \\ | ||
- | b & = & \frac{m}{\sigma} \\ | ||
- | \end{eqnarray*} | ||
- | |||
- | |||
====== R code: Idea ====== | ====== R code: Idea ====== | ||
< | < | ||
Line 519: | Line 496: | ||
> | > | ||
</ | </ | ||
- | 렇게 말고 | + | a와 b를 동시에 |
- | gradient descent | + | |
====== Gradient descend ====== | ====== Gradient descend ====== | ||
Line 563: | Line 539: | ||
& = & -2 X_i \sum{(Y_i - (a + bX_i))} \\ | & = & -2 X_i \sum{(Y_i - (a + bX_i))} \\ | ||
& = & -2 * X_i * \sum{\text{residual}} \\ | & = & -2 * X_i * \sum{\text{residual}} \\ | ||
- | \\ | + | & .. & -2 * X_i * \frac{\sum{\text{residual}}}{n} \\ |
+ | & = & -2 * \overline{X_i * \text{residual}} \\ | ||
\end{eqnarray*} | \end{eqnarray*} | ||
- | (미분을 이해한다는 것을 전제로) | + | 위의 설명은 Sum of Square값을 미분하는 것을 전제로 하였지만, |
< | < | ||
Line 1011: | Line 989: | ||
> | > | ||
</ | </ | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | |||
+ | ====== Why normalize (scale or make z-score) xi ====== | ||
+ | x 변인의 측정단위로 인해서 b 값이 결정되게 되는데 이 때의 b값은 상당하고 다양한 범위를 가질 수 있다. 가령 월 수입이 (인컴) X 라고 한다면 우리가 추정해야 (추적해야) 할 b값은 수백만이 될 수도 있다.이 값을 gradient로 추적하게 된다면 너무도 많은 iteration을 거쳐야 할 수 있다. 변인이 바뀌면 이 b의 추적범위도 드라마틱하게 바뀌게 된다. 이를 표준화한 x 점수를 사용하게 된다면 일정한 learning rate와 iteration만으로도 정확한 a와 b를 추적할 수 있게 된다. | ||
+ | |||
+ | ====== How to unnormalize (unscale) a and b ====== | ||
+ | \begin{eqnarray*} | ||
+ | y & = & a + b * x \\ | ||
+ | & & \text{we use z instead of x} \\ | ||
+ | & & \text{and } \\ | ||
+ | & & z = \frac{(x - \mu)}{\sigma} \\ | ||
+ | & & \text{suppose that the result after calculation be } \\ | ||
+ | y & = & k + m * z \\ | ||
+ | & = & k + m * \frac{(x - \mu)}{\sigma} \\ | ||
+ | & = & k + \frac{m * x}{\sigma} - \frac{m * \mu}{\sigma} | ||
+ | & = & k - \frac{m * \mu}{\sigma} + \frac{m * x}{\sigma} | ||
+ | & = & \underbrace{k - \frac{\mu}{\sigma} * m}_\text{ 1 } + \underbrace{\frac{m}{\sigma}}_\text{ 2 } * x \\ | ||
+ | & & \text{therefore, | ||
+ | a & = & k - \frac{\mu}{\sigma} * m \\ | ||
+ | b & = & \frac{m}{\sigma} \\ | ||
+ | \end{eqnarray*} | ||
+ | |||
- | {{: | ||
gradient_descent.1755746320.txt.gz · Last modified: 2025/08/21 12:18 by hkimscil