Pattern Recognition in Machine Learning
- Neural networks are used in applications such as facial recognition.
- These applications utilize pattern recognition.
- This type of classification can be performed using Perceptron .
- Perceptrons can be used to classify data into two parts.
- The perceptron is also known as a linear binary classifier.
Sample classification
Imagine a straight line (linear graph) in space with scattered x and y points. How would you classify the points that lie above and below the line?
A perceptron can be trained to identify points lying on a straight line, without needing to know the formula for that line.
How to program neural networks
To program a neural network, we can use a simple JavaScript program to:
- Create a simple graphing object.
- Generate 500 random x, y points.
- Display the x and y points.
- Create a function to draw a line: f(x)
- Display straight lines
- Calculate the desired results.
- Display the desired results
Create a simple graphing object.
Creating a simple graphing object is described in AI Canvas.
For example:
const plotter = new XYPlotter("myCanvas"); plotter.transformXY(); const xMax = plotter.xMax; const yMax = plotter.yMax; const xMin = plotter.xMin; const yMin = plotter.yMin; Generate random X and Y points.
- Create as many xy points as you like.
- Let the value of x be random (from 0 to the maximum value).
- Let the value of y be random (from 0 to the maximum value).
- Display the points on the graph:
For example:
const numPoints = 500; const xPoints = []; const yPoints = []; for (let i = 0; i < numPoints; i++) { xPoints[i] = Math.random() * xMax; yPoints[i] = Math.random() * yMax; } Create a function to draw a straight line.
Displaying a line on the plotter:
For example:
function f(x) { return x * 1.2 + 50; } Calculate the correct answer
Calculate the correct answer based on the linear function:
y = x * 1.2 + 50.
The desired answer is 1 if y lies on the line and 0 if y lies below the line.
Store the desired answers in an array (desired[]).
For example:
let desired = []; for (let i = 0; i < numPoints; i++) { desired[i] = 0; if (yPoints[i] > f(xPoints[i])) {desired[i] = 1;} } Show the correct answers
For each point, if desired[i] = 1, display the point in black; otherwise, display the point in blue.
For example:
for (let i = 0; i < numPoints; i++) { let color = "blue"; if (desired[i]) color = "black"; plotter.plotPoint(xPoints[i], yPoints[i], color); } How to train a Perceptron
In the next chapter, you will learn how to use the correct answers to: Train a perceptron to predict the output value of unknown input values.