Skip to main content

SINGLE LAYER PERCEPTRON :

The perceptron is a single processing unit of any neural network. Frank Rosenblatt first proposed in 1958 is a simple neuron which is used to classify its input into one or two categories. Perceptron is a linear classifier, and is used in supervised learning. It helps to organize the given input data.

A perceptron is a neural network unit that does a precise computation to detect features in the input data. Perceptron is mainly used to classify the data into two parts. Therefore, it is also known as Linear Binary Classifier.

The perceptron consists of 4 parts.

  • Input value or One input layer: The input layer of the perceptron is made of artificial input neurons and takes the initial data into the system for further processing.
  • Weights and Bias: Weight: It represents the dimension or strength of the connection between units. If the weight to node 1 to node 2 has a higher quantity, then neuron 1 has a more considerable influence on the neuron.
  • Bias: It is the same as the intercept added in a linear equation. It is an additional parameter which task is to modify the output along with the weighted sum of the input to the other neuron. Net sum: It calculates the total sum.
  • Activation Function: A neuron can be activated or not, is determined by an activation function. The activation function calculates a weighted sum and further adding bias with it to give the result.

how to use this Package :

Import these libraries :

from oneNeuron.perceptron import Perceptron
from oneNeuron.allutils import prepare_data
from oneNeuron.allutils import save_model

how to call Perceptron class :

model = Perceptron(eta, epochs)
model.fit(X, y)

A glance of the code :

class Perceptron:
  def __init__(self, eta, epochs):
    self.weights = np.random.randn(3) * 1e-4 # SMALL WEIGHT INIT
    logging.info(f"initial weights before training: \n{self.weights}")
    self.eta = eta # LEARNING RATE
    self.epochs = epochs 


  def activationFunction(self, inputs, weights):
    z = np.dot(inputs, weights) # z = W * X
    return np.where(z > 0, 1, 0) # CONDITION, IF TRUE, ELSE

  def fit(self, X, y):
    self.X = X
    self.y = y

    X_with_bias = np.c_[self.X, -np.ones((len(self.X), 1))] # CONCATINATION
    logging.info(f"X with bias: \n{X_with_bias}")

    for epoch in tqdm(range(self.epochs), total=self.epochs, desc="Training the Model"):
      logging.info("--"*10)
      logging.info(f"for epoch: {epoch}")
      logging.info("--"*10)

      y_hat = self.activationFunction(X_with_bias, self.weights) # foward propagation
      logging.info(f"predicted value after forward pass: \n{y_hat}")
      self.error = self.y - y_hat
      logging.info(f"error: \n{self.error}")
      self.weights = self.weights + self.eta * np.dot(X_with_bias.T, self.error) # backward propagation
      logging.info(f"updated weights after epoch:\n{epoch}/{self.epochs} : \n{self.weights}")
      logging.info("#####"*10)


  def predict(self, X):
    X_with_bias = np.c_[X, -np.ones((len(X), 1))]
    return self.activationFunction(X_with_bias, self.weights)

  def total_loss(self):
    total_loss = np.sum(self.error)
    logging.info(f"total loss: {total_loss}")
    return total_loss

Release files for oneNeuron-pypi-kkkumar2 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oneNeuron-pypi-kkkumar2 0.0.5
File Size Uploaded
oneNeuron_pypi-kkkumar2-0.0.5.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oneNeuron-pypi-kkkumar2 0.0.5
File Interpreter ABI Platform
oneNeuron_pypi_kkkumar2-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / oneNeuron_pypi-kkkumar2-0.0.5.tar.gz

Download URL oneNeuron_pypi-kkkumar2-0.0.5.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9738382506fc03e8b7fa1661054255472bda38bb9f1476add7ca142de638c552
BLAKE2b-256 checksum
How to use checksums
6895ae26eb6cb374d4c3385af2ac251c75777ab85815205aec2df4abb7ec9a41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / oneNeuron_pypi_kkkumar2-0.0.5-py3-none-any.whl

Download URL oneNeuron_pypi_kkkumar2-0.0.5-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
adff6c55b4ef132d82827c6bc01062b029b72d476429554c80cf3775d633ad42
BLAKE2b-256 checksum
How to use checksums
83baa8989d82e83f124a6bbd8774c10b6805f2f93fd3d3035c60898062a3990c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page