Published
Edited
Jan 9, 2019
1 star
Insert cell
Insert cell
tf = await require('@tensorflow/tfjs@0.14.1')
Insert cell
{
const model = tf.sequential()
model.add(tf.layers.dense({units: 2, inputShape: [1]})) // inputShapeは入口、unitsは出口
model.add(tf.layers.dense({units: 1, inputShape: [2]}))
model.add(tf.layers.dense({units: 1, inputShape: [1]}))
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'})
model.summary()
const xs = tf.tensor2d([-1, 0, 1], [3, 1])
const ys = tf.tensor2d([-3, -1, 1], [3, 1])
const h = await model.fit(xs, ys, {epocs: 250})
return model.predict(tf.tensor2d([30], [1, 1])).dataSync()
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more