Introduction To Neural Networks (original) (raw)

Last Updated : 9 May, 2026

Neural networks are machine learning models that mimic the complex functions of the human brain. These models consist of interconnected nodes or neurons that process data, learn patterns and enable tasks such as pattern recognition and decision making.

Neural networks are capable of learning and identifying patterns directly from data without pre-defined rules. These networks are built from several key components:

Learning in neural networks follows a structured, three-stage process:

  1. **Input Computation: Data is fed into the network.
  2. **Output Generation: Based on the current parameters, the network generates an output.
  3. **Iterative Refinement: The network refines its output by adjusting weights and biases, gradually improving its performance on diverse tasks.

In an adaptive learning environment:

420047197

The image illustrates the analogy between a biological neuron and an artificial neuron, showing how inputs are received and processed to produce outputs in both systems.

**Importance of Neural Networks

Layers in Neural Network Architecture

_neural_network

Layers in Neural Network Architecture

  1. **Input Layer: This is where the network receives its input data. Each input neuron in the layer corresponds to a feature in the input data.
  2. **Hidden Layers: These layers perform most of the computational heavy lifting. A neural network can have one or multiple hidden layers. Each layer consists of units (neurons) that transform the inputs into something that the output layer can use.
  3. **Output Layer: The final layer produces the output of the model. The format of these outputs varies depending on the specific task like classification, regression.

Working of Neural Networks

1. Forward Propagation

When data is input into the network, it passes through the network in the forward direction, from the input layer through the hidden layers to the output layer. This process is known as forward propagation. Here’s what happens during this phase:

**1. Linear Transformation: Each neuron in a layer receives inputs which are multiplied by the weights associated with the connections. These products are summed together and a bias is added to the sum. This can be represented mathematically as:

z = w_1x_1 + w_2x_2 + \ldots + w_nx_n + b

where

**2. Activation: The result of the linear transformation (denoted as z) is then passed through an activation function. The activation function is crucial because it introduces non-linearity into the system, enabling the network to learn more complex patterns. Popular activation functions include ReLU, sigmoid and tanh.

2. Backpropagation

After forward propagation, the network evaluates its performance using a loss function which measures the difference between the actual output and the predicted output. The goal of training is to minimize this loss. This is where backpropagation comes into play:

3. Iteration

This process of forward propagation, loss calculation, backpropagation and weight update is repeated for many iterations over the dataset. Over time, this iterative process reduces the loss and the network's predictions become more accurate.

Through these steps, neural networks can adapt their parameters to better approximate the relationships in the data, thereby improving their performance on tasks such as classification, regression or any other predictive modeling.

Example of Email Classification

Let's consider a record of an email dataset:

Email ID Email Content Sender Subject Line Label
1 "Get free gift cards now!" spam@example.com "Exclusive Offer" 1

To classify this email, we will create a feature vector based on the analysis of keywords such as "free" "win" and "offer"

The feature vector of the record can be presented as:

How Neurons Process Data in a Neural Network

In a neural network, input data is passed through multiple layers, including one or more hidden layers. Each neuron in these hidden layers performs several operations, transforming the input into a usable output.

**1. Input Layer: The input layer contains 3 nodes that indicates the presence of each keyword.

**2. Hidden Layer: The input vector is passed through the hidden layer. Each neuron in the hidden layer performs two primary operations: a weighted sum followed by an activation function.

**Weights:

**Input Vector: [1,0,1]

**Weighted Sum Calculation

**Activation Function

Here we will use ReLu activation function:

**3. Output Layer: The activated values from the hidden neurons are sent to the output neuron where they are again processed using a weighted sum and an activation function.

**4. Final Classification:

backpropagation_in_neural_network_8

Neural Network

Learning of a Neural Network

**1. Learning with Supervised Learning

In supervised learning, a neural network learns from labeled input-output pairs provided by a teacher. The network generates outputs based on inputs and by comparing these outputs to the known desired outputs, an error signal is created. The network iteratively adjusts its parameters to minimize errors until it reaches an acceptable performance level.

**2. Learning with Unsupervised Learning

Unsupervised learning involves data without labeled output variables. The primary goal is to understand the underlying structure of the input data (X). Unlike supervised learning, there is no instructor to guide the process. Instead, the focus is on modeling data patterns and relationships, with techniques like clustering and association commonly used.

**3. Learning with Reinforcement Learning

Reinforcement learning enables a neural network to learn through interaction with its environment. The network receives feedback in the form of rewards or penalties, guiding it to find an optimal policy or strategy that maximizes cumulative rewards over time. This approach is widely used in applications like gaming and decision-making.

Types of Neural Networks

There are several types of neural networks, including:

Implementation of Neural Network using TensorFlow

Here, we implement simple feedforward neural network that trains on a sample dataset and makes predictions using following steps:

Step 1: Import Necessary Libraries

Import necessary libraries, primarily TensorFlow and Keras, along with other required packages such as NumPy and Pandas for data handling.

Python `

import numpy as np import pandas as pd from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense

`

Step 2: Create and Load Dataset

data = { 'feature1': [0.1, 0.2, 0.3, 0.4, 0.5], 'feature2': [0.5, 0.4, 0.3, 0.2, 0.1], 'label': [0, 0, 1, 1, 1] }

df = pd.DataFrame(data) X = df[['feature1', 'feature2']].values y = df['label'].values

`

Step 3: Create a Neural Network

Instantiate a Sequential model and add layers. The input layer and hidden layers are typically created using Dense layers, specifying the number of neurons and activation functions.

Python `

model = Sequential() model.add(Dense(8, input_dim=2, activation='relu')) model.add(Dense(1, activation='sigmoid'))

`

**Step 4: Compiling the Model

Compile the model by specifying the loss function, optimizer and metrics to evaluate during training. Here we will use binary crossentropy and adam optimizer.

Python `

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

`

**Step 5: Train the Model

Fit the model on the training data, specifying the number of epochs and batch size. This step trains the neural network to learn from the input data.

Python `

model.fit(X, y, epochs=100, batch_size=1, verbose=1)

`

**Step 6: Make Predictions

Use the trained model to make predictions on new data. Process the output to interpret the predictions like converting probabilities to binary outcomes.

Python `

test_data = np.array([[0.2, 0.4]]) prediction = model.predict(test_data) predicted_label = (prediction > 0.5).astype(int)

`

**Output:

Predicted label: 1

Advantages

Limitations

Applications

  1. **Image and Video Recognition: CNNs are extensively used in applications such as facial recognition, autonomous driving and medical image analysis.
  2. **Natural Language Processing (NLP): RNNs and transformers power language translation, chatbots and sentiment analysis.
  3. **Finance: Predicting stock prices, fraud detection and risk management.
  4. **Healthcare: Neural networks assist in diagnosing diseases, analyzing medical images and personalizing treatment plans.
  5. **Gaming and Autonomous Systems: Neural networks enable real-time decision-making, enhancing user experience in video games and enabling autonomous systems like self-driving cars.