Skip to content

Commit

Permalink
Create neural_network.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 8, 2024
1 parent 1462026 commit 3b9bcdb
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// neural_network.js

const tf = require('@tensorflow/tfjs');
const { Sequential } = require('@tensorflow/tfjs-layers');

class NeuralNetwork {
constructor() {
this.model = this.createModel();
}

createModel() {
const model = tf.sequential();
model.add(tf.layers.dense({ units: 128, inputShape: [100] }));
model.add(tf.layers.dropout({ rate: 0.2 }));
model.add(tf.layers.dense({ units: 64 }));
model.add(tf.layers.dropout({ rate: 0.2 }));
model.add(tf.layers.dense({ units: 1 }));
model.compile({ optimizer: tf.optimizers.adam(), loss: 'meanSquaredError' });
return model;
}

train(data, labels) {
this.model.fit(data, labels, { epochs: 10, batchSize: 32 });
}

predict(data) {
return this.model.predict(data);
}
}

module.exports = NeuralNetwork;

0 comments on commit 3b9bcdb

Please sign in to comment.