- Published on
๐STUDY ์น ๋ธ๋ผ์ฐ์ ์ ๋จธ์ ๋ฌ๋ Tensorflow.js | ๋คํญํ๊ท
๋คํญํ๊ท
: ์ฃผ์ด์ง ๋ฐ์ดํฐ์ ์ ๋ชฉํฏ๊ฐ์ ์์ธกํ๋๋ฐ ์ฌ์ฉํ๋ ๋จธ์ ๋ฌ๋ ์๊ณ ๋ฆฌ์ฆ.
- ์ง๋ํ์ต: ๋ช ์์ ์ธ ๋ชฉํฏ๊ฐ(label)๊ณผ ํจ๊ป ํ๋ จ โก ์ต๋ํ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ํ๋ ํจ์(objective function)๋ฅผ ๋ง๋ฆ
- ์ ํ ๋ชจ๋ธ(linear model):
- ์์ค ํจ์(loss function): ์์ธก๊ณผ ์ํ๊ฐ์ ์ค์ฐจ ex. mean squared error
- Optimizer: ์ต์ ๊ฐ์ ์ฐพ์๋๊ฐ, ์ต์ ํํจ์ ๋ฐ๋ผ ๋จ์กฐ ๊ฐ์ ๊ณผ์ ์ ๊ฑฐ์นจ. ์ด ๊ณผ์ ์์ ์์ค ํจ์๋ ๋ฏธ๋ถ์ด ๊ฐ๋ฅํด์ผํ๋ฉฐ, ์ต์๊ฐ์ ์ฐพ์์ผํจ.
- gradient descent:
- Underfitting: ๊ณผํ๊ฒ ๋จ์ํ โก ์์ค๊ฐ์ด ์๋๋ผ๋ ๋ฐ์
- Overfitting: ๊ณผํ๊ฒ ๋ณต์กํ โก ์์ค๊ฐ์ด ์๋๋ผ๋ ๋ฐ์
import * as tf from "@tensorflow/tfjs";
const doublePi = tf.scalar(2.0, Math.PI);
const xs = tf.mul(doublePi, tf.range(-0.5, 0.5, 0.01));
const noise = tf.randomNormal([xs.size]).mul(0.05);
const ys = tf.sin(xs).add(noise);
const w0 = tf.scalar(Math.random() - 0.5).variable();
const w1 = tf.scalar(Math.random() - 0.5).variable();
const w2 = tf.scalar(Math.random() - 0.5).variable();
const f_x = (x) => {
return w2.mul(x).mul(x).add(w1.mul(x)).add(w0);
};
const loss = (pred, label) => pred.sub(label).square().mean();
const learningRate = 0.3;
const optimizer = tf.train.adam(learningRate);
for (let i = 0; i < 100; i++) {
const l = optimizer.minimize(() => loss(f_x(xs), ys), true);
losses.push(l.dataSync());
}
- Authors
- Name
- Amelia Young
- GitHub
- @ameliacode