neural_network.perceptron

Perceptron w = w + N * (d(k) - y) * x(k)

Using perceptron network for oil analysis, with Measuring of 3 parameters that represent chemical characteristics we can classify the oil, in p1 or p2 p1 = -1 p2 = 1

Reference: https://en.wikipedia.org/wiki/Perceptron

Attributes

network

samples

target

Classes

Perceptron

Module Contents

class neural_network.perceptron.Perceptron(sample: list[list[float]], target: list[int], learning_rate: float = 0.01, epoch_number: int = 1000, bias: float = -1, seed: int | None = 0)
sign(u: float) int

threshold function for classification :param u: input number :return: 1 if the input is greater than or equal to 0, otherwise -1 >>> data = [[0], [-0.5], [0.5]] >>> targets = [1, -1, 1] >>> perceptron = Perceptron(data, targets) >>> perceptron.sign(0) 1 >>> perceptron.sign(-0.5) -1 >>> perceptron.sign(0.5) 1

sort(sample: list[float]) int

Classifies a single observation as P1 (-1) or P2 (1). The network must be trained first.

Parameters:

sample – example row to classify as P1 or P2

Returns:

-1 if the sample is classified as P1, otherwise 1

>>> data = [[2.0149, 0.6192, 10.9263]]
>>> targets = [-1]
>>> perceptron = Perceptron(data, targets)
>>> perceptron.training()
5
>>> perceptron.sort([2.0149, 0.6192, 10.9263])
-1
training() int

Trains the perceptron until it stops misclassifying the training data or the maximum number of epochs (epoch_number) is reached, whichever comes first. The epoch cap guarantees termination even if the data is not linearly separable.

Returns:

the number of epochs the network was trained for.

>>> data = [[2.0149, 0.6192, 10.9263]]
>>> targets = [-1]
>>> perceptron = Perceptron(data, targets)
>>> perceptron.training()
5
_rng
bias = -1
col_sample
epoch_number = 1000
learning_rate = 0.01
number_sample
sample
target
weight: list = []
neural_network.perceptron.network
neural_network.perceptron.samples
neural_network.perceptron.target