Skip to content

Instantly share code, notes, and snippets.

@kirill-fedyanin
Created August 14, 2019 15:30
Show Gist options
  • Save kirill-fedyanin/a6be50051fa9a5abbeb865ac6c524435 to your computer and use it in GitHub Desktop.
Save kirill-fedyanin/a6be50051fa9a5abbeb865ac6c524435 to your computer and use it in GitHub Desktop.
const model = tf.sequential();
model.add(tf.layers.dense({ units: 5, activation: 'sigmoid', inputShape: [1]}));
model.add(tf.layers.dense({ units: 1, activation: 'sigmoid'}));
model.compile({loss: 'meanSquaredError', optimizer: 'adadelta'});
const xs = tf.tensor1d([1, 2, 3, 4, 5, 6, 7, 8, 9]);
const ys = tf.tensor1d([0, 0, 0, 0, 0, 1, 1, 1, 1]);
model.fit(xs, ys, {epochs: 1000}).then(h => {
console.log("Loss after Epoch " + " : " + h.history.loss[0]);
model.predict(xs).print();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment