Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(async () => {
/*
Load our csv file and get it into a properly shaped array of pairs likes...
[
[distanceA, forceB],
[distanceB, forceB],
...
]
*/
var pairs = getPairsFromCSV();
console.log(pairs);
/*
Train the model using the data.
*/
var model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
const xs = tf.tensor1d(pairs.map((p) => p[0] / 100));
const ys = tf.tensor1d(pairs.map((p) => p[1]));
console.log(`Training ${pairs.length}...`);
await model.fit(xs, ys, {epochs: 100});
await model.save("file://../Assets/shots_model");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment