Share Brilliantly
tensor flow
await $src('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js');
let linearModel = tf.sequential();
linearModel.add(tf.layers.dense({units:1, inputShape:[2]}));
linearModel.compile({loss:'meanSquaredError',optimizer:'sgd'});
let xs = tf.tensor([[3.2,1],[4.4,1],[5.5,2],[6.71,0.8],[7.168,1.2],[9.779,5],[6.182,5],[7.59,4.5],[2.16,7]]);
let ys = tf.tensor([[1.6],[2.7],[2.9],[3.19],[1.684],[2.53],[3.366],[2.596],[2.53]]);
await linearModel.fit(xs,ys,{
epochs:80
});
let output = linearModel.predict(tf.tensor([4,6]));
prediction = Array.from(output.dataSync())[0];
Try it!
await $src('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js');
var linearModel = tf.sequential();
linearModel.add(tf.layers.dense({units:1, inputShape:[2], useBias: false}));