Machine Learning is for Humans — how to do it, and teach it too

<script src=”https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
let brain;
isTrained = false;
let options = {
inputs: [“mouseX”, “mouseY”],
outputs: [‘red’,’blue’],
task: ‘classification’,
debug: true
}
brain = ml5.neuralNetwork(options);
if (mouseX > 50 && mouseX < 100 && mouseY > 50 && mouseY<100) {
// code to change formatting of button
}
20, 60  no
60, 60 yes
70, 110 no
140,110 no
80, 55 yes
20, 155 no
dropdown = createSelect();
dropdown.option(‘red’);
dropdown.option(‘blue’);
if (!isTrained) {
let inputs = {
mouseX, mouseY
}
let label = dropdown.value();
brain.addData(inputs,{label});
}
let data = brain.neuralNetworkData.data.raw;
for (let row of data) {
fill(row.ys.label);
circle(row.xs.mouseX,row.xs.mouseY,20);
}
let trainbutton = createButton(‘train’);
trainbutton.mousePressed(function() {
brain.normalizeData();
brain.train({epochs:epochs},()=>{isTrained=true;});
});
if (isTrained) {
let inputs = {mouseX,mouseY};
let outputs = brain.classifySync(inputs);
background(outputs[0].label);
}

--

--

--

exploring the intersection of coding, education and disciplinary knowledge

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Asynchronous Stochastic Gradient Descent with Diminishing stepwise

Dog Breed Classification using Transfer Learning

Slalom’s Experience with Amazon Personalize

Why Not SOTA?

Super Car-io Odyssey: My Favorite Papers from CVPR 2019

Co-reference Resolution

What is Machine Learning and Artificial Intelligence??

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Greg Benedis-Grab

Greg Benedis-Grab

exploring the intersection of coding, education and disciplinary knowledge

More from Medium

Entropy (Shannon Claude)

A backpropagation Neural Network Model to Predict the Plasmapause Location

Why Do We Keep Creating Racist Robots?

From cats and dogs to polyps in the colon