Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Test a Perceptron on Unseen Points

Evaluate a trained perceptron on separate points, count classification errors, inspect class balance and avoid tuning on the test set.

Table of Contents

After training a perceptron, test it on points it has never seen and compare each prediction with the known label. In this lesson the label comes from the line y = f(x): a point above the line is class 1, and a point on or below it is class 0. This checks the model on fresh synthetic data; it does not establish performance on real customer or production data.

Set up a separate test set

The example assumes you already created ptron, f(x), xMax and yMax in the preceding perceptron training tutorial. Finish training before running this loop. Do not call ptron.train on the test points.

const testCount = 500;
let errors = 0;
let class0 = 0;
let class1 = 0;

for (let i = 0; i < testCount; i++) {
  const x = Math.random() * xMax;
  const y = Math.random() * yMax;
  const expected = y > f(x) ? 1 : 0;
  const guess = ptron.activate([x, y, ptron.bias]);

  if (expected === 1) class1++; else class0++;
  if (guess !== expected) errors++;

  // Optional, if the earlier lesson's plotter is available:
  // plotter.plotPoint(x, y, guess === 0 ? 'blue' : 'black');
}

console.log({ errors, accuracy: (testCount - errors) / testCount, class0, class1 });

The bias input mirrors the earlier library's activate([x, y, ptron.bias]) call. Its train method appends the bias itself, so keep training and prediction input conventions distinct. The original error condition had two comparisons and did not define what happens on the line; deriving expected once makes the boundary rule explicit.

Interpret the result

The error count is the number of disagreements with the line-based labels. Accuracy is correct predictions divided by the number of test points. If the line lies mostly outside the sampled rectangle, one class may dominate; a high overall accuracy could then hide poor performance on the rare class. Inspect class0 and class1 and count errors separately by expected class if the distribution is uneven.

The random test changes on each run. For comparisons between training settings, generate one held-out set in advance and reuse it for each version, or use a seeded generator. Keep it separate from all training examples and avoid tuning repeatedly to the same test set; use a validation set for choosing learning rate and training duration.

Adjust and retest carefully

  • Confirm that training labels and test labels use the same rule, including the boundary.
  • Plot misclassified points to see whether errors cluster near the line or across a whole region.
  • Try a different learning rate or more training examples, then evaluate on the same held-out test set after choosing settings on validation data.
  • Check the model's limits: a single perceptron learns a linear boundary and cannot solve arbitrary non-linear patterns with these raw inputs.

If you need background on the model's weighted inputs and threshold, start with TipsMake's neural network fundamentals. This small experiment is useful for checking code and reasoning about generalization; report the sampling range, training procedure and evaluation set when sharing results.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.