Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createModel() {
- // Create a sequential model
- const model = tf.sequential();
- // Add two hidden layers
- model.add(tf.layers.dense({ inputShape: [1], units: 5, useBias: true }));
- model.add(tf.layers.dense({ units: 10, useBias: true }));
- // Add an output layer
- model.add(tf.layers.dense({ units: 1, useBias: true }));
- return model;
- }
- async function trainModel(model, inputs, labels) {
- // Prepare the model for training.
- model.compile({
- optimizer: tf.train.adam(),
- loss: tf.losses.meanSquaredError,
- metrics: ["mse"]
- });
- const batchSize = 32;
- const epochs = 50;
- return await model.fit(inputs, labels, {
- batchSize,
- epochs,
- shuffle: true,
- callbacks: tfvis.show.fitCallbacks(
- { name: "Training Progresses" },
- ["loss", "mse"],
- { height: 200, callbacks: ["onEpochEnd"] }
- )
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement