Skip to content

Instantly share code, notes, and snippets.

@etoxin
Last active September 4, 2019 13:47
Show Gist options
  • Save etoxin/b9dc235aaab27eec89d3d53c427edcd5 to your computer and use it in GitHub Desktop.
Save etoxin/b9dc235aaab27eec89d3d53c427edcd5 to your computer and use it in GitHub Desktop.
const tf = require("@tensorflow/tfjs-node");
(async () => {
const model = tf.sequential({
layers: [tf.layers.dense({ inputShape: [1], units: 1 })]
});
model.compile({ optimizer: "sgd", loss: "meanSquaredError" });
// y = 2X - 1
const xs = tf.tensor([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0]);
const ys = tf.tensor([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0]);
await model.fit(xs, ys, { epochs: 1000 });
model.predict(tf.tensor([10.0])).print();
})();
{
"main": "index.js",
"dependencies": {
"@tensorflow/tfjs-node": "^1.2.8"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment