xxxxxxxxxx
62
let priceTitle, priceInput, distanceTitle, distanceInput, competitionTitle, competitionInput, submitButton, resP;
let neuralNetwork;
function setup() {
noCanvas();
let nnOptions = {
dataUrl: 'shoe.csv',
inputs: ['price','distance', 'competition'],
outputs: ['outcome'],
task: 'regression',
debug: true,
};
neuralNetwork = ml5.neuralNetwork(nnOptions, modelReady);
priceTitle = createP('Price (type into a value between 50 and 150)');
priceInput = createInput('100', 'text');
distanceTitle = createP('Distance(over 400m type in long, lower 400m type in short)');
distanceInput = createInput('long', 'text');
competitionTitle = createP('Competition(yes or no)');
competitionInput = createInput('yes', 'text');
submitButton = createButton('Submit');
submitButton.mousePressed(predict);
resP = createP('results:')
}
function modelReady() {
neuralNetwork.normalizeData();
neuralNetwork.train({ epochs: 5 }, whileTraining, finishedTraining);
}
function whileTraining(epochs, log) {
console.log('epochs', epochs)
console.log('log', log.loss)
}
function finishedTraining() {
predict();
}
function predict() {
console.log('regression');
const input = [priceInput.value(), distanceInput.value(), competitionInput.value()];
neuralNetwork.classify(input, gotResults);
}
function gotResults(err, res) {
if (res) {
resP.html('results: ' + res[0].label + ', ' + res[0].confidence)
}
}