TipsMake
Newest

Pattern Recognition in Machine Learning

  1. Neural networks are used in applications such as facial recognition.
  2. These applications utilize pattern recognition.
  3. This type of classification can be performed using Perceptron .
  4. Perceptrons can be used to classify data into two parts.
  5. 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?

 

Pattern Recognition in Machine Learning Picture 1

A perceptron can be trained to identify points lying on a straight line, without needing to know the formula for that line.

Pattern Recognition in Machine Learning Picture 2

 

How to program neural networks

To program a neural network, we can use a simple JavaScript program to:

  1. Create a simple graphing object.
  2. Generate 500 random x, y points.
  3. Display the x and y points.
  4. Create a function to draw a line: f(x)
  5. Display straight lines
  6. Calculate the desired results.
  7. 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.

  1. Create as many xy points as you like.
  2. Let the value of x be random (from 0 to the maximum value).
  3. Let the value of y be random (from 0 to the maximum value).
  4. 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.

Discover more Machine Learning
Kareem Winters
Share by Kareem Winters
Update 02 March 2026