Machine learning 101 : Ep-03 : What is a Neural Network and how it works ?

Nagarjun Gopalaswamy
3 min readMar 18, 2024

--

Lets take a simple example to understand Neural Network! The odds of a customer buying the product based on their age and income. Imagine you have a dataset containing information about customers, including their age, income, and whether they bought a product (1 for bought, 0 for didn’t buy). Here’s how we can use a neural network to predict whether a new customer will buy the product:

  1. Input Data: Each customer in our dataset is represented by two features: age and income. For example, one customer might be 35 years old with an income of $50,000.
  2. Neural Network Structure: We’ll use a simple neural network with two input neurons (one for each feature), one hidden layer with a variable number of neurons, and one output neuron (representing whether the customer will buy the product or not). Each neuron in the hidden layer and the output layer is connected to every neuron in the previous layer.
  3. Training Process: We start by randomly initializing the weights and biases of the neural network. Then, we feed the training data (age and income of customers along with their purchase status) into the network and compute the output. We compare the predicted output with the actual purchase status and use a loss function (e.g., mean squared error) to measure the difference between the predicted and actual outputs.
  4. Backpropagation: Using an optimization algorithm like gradient descent, we update the weights and biases of the neural network to minimize the loss function. This process is called backpropagation. We adjust the weights and biases in such a way that the next prediction is closer to the actual purchase status.
  5. Learning Patterns: As the neural network goes through multiple iterations of training (epochs), it learns to identify patterns and relationships between the input features (age and income) and the output (purchase status). The network adjusts its internal parameters to better predict whether a customer will buy the product based on their age and income.
  6. Making Predictions: Once the neural network is trained, we can use it to predict whether a new customer will buy the product. We feed the new customer’s age and income into the trained network, and it outputs a prediction (0 or 1) indicating whether the customer is likely to buy the product.
  7. Evaluation: Finally, we evaluate the performance of the neural network on a separate validation dataset to ensure that it generalizes well to new, unseen data. We may adjust the network’s architecture, hyperparameters, or preprocessing techniques to improve its performance if needed.

This example demonstrates how a neural network can learn from data to make predictions or decisions in a variety of real-world scenarios.

What is a Neuron within a Neural network and what are these hidden layers ?

In a neural network, a neuron (or node) is a fundamental building block that receives input, performs a mathematical operation on that input, and produces an output. Neurons are organized into layers, with each layer performing specific functions in the network. Here’s a brief explanation of neurons and hidden layers:

Neuron:

  • A neuron receives input from one or more neurons in the previous layer or from external data.
  • Each input is multiplied by a weight, which represents the strength of the connection between the neurons.
  • The weighted inputs are summed together, and a bias term is added to the sum.
  • The resulting sum is then passed through an activation function, which introduces non-linearity into the network and determines the output of the neuron.
  • The output of the neuron is then passed to the neurons in the next layer.

Hidden Layer:

  • A hidden layer is a layer of neurons in a neural network that is neither the input nor the output layer.
  • The term “hidden” refers to the fact that the outputs of the neurons in the hidden layer are not observed directly in the input or output data.
  • Hidden layers are responsible for learning complex patterns and representations in the data.
  • The number of hidden layers and the number of neurons in each hidden layer are hyperparameters that can be adjusted to improve the performance of the neural network.
  • Adding more hidden layers or neurons can increase the capacity of the network to learn intricate relationships in the data, but it also increases the risk of overfitting (memorizing the training data rather than learning generalizable patterns).

In summary, neurons perform computations on input data using weights, biases, and activation functions to produce output, and hidden layers in a neural network are responsible for learning complex patterns and representations in the data.

--

--