Total Pageviews

Thursday, September 10, 2026

🖼️ Image Entropy Calculator

🖼️ Image Entropy Calculator

Upload any image and calculate its grayscale histogram, probability distribution and Shannon entropy automatically.

1️⃣ Upload an Image

No image selected.

2️⃣ Image Processing

🖼️ Original Image

Original image

⚫ Grayscale Image

3️⃣ Image Statistics

Total Pixels
0
Used Gray Levels
0
Entropy
0
Maximum Entropy
8 bits
Upload an image and click Analyze Image.

4️⃣ Mathematical Calculation

pᵢ = nᵢ / N

where:

  • nᵢ = number of pixels having intensity i
  • N = total number of pixels
I(i) = −log₂(pᵢ)

Information associated with intensity i.

H = − Σ pᵢ log₂(pᵢ)

This is the Shannon entropy of the grayscale image.

0 ≤ H ≤ 8 bits/pixel

for an 8-bit grayscale image.

5️⃣ Grayscale Histogram

The histogram shows how frequently each gray level occurs in the uploaded image.

6️⃣ Probability Distribution

Only gray levels actually present in the image are displayed below.

Gray Level Pixel Count Probability pᵢ Information −log₂(pᵢ) Contribution pᵢI(i)
Upload and analyze an image.

7️⃣ Entropy Calculation Animation

🖼️ Image
Pixels
⚫ Grayscale
Image
📊 Histogram
nᵢ
📐 Probability
pᵢ=nᵢ/N
🧮 Information
−log₂(pᵢ)
📈 Entropy
H

Click Start Animation

8️⃣ Interpretation

Entropy Interpretation
Near 0 Very uniform image / little intensity variation
Low Few dominant intensity values
Medium Moderate intensity variation
High Large variety of intensity values
Near 8 Intensity distribution approaches uniformity

🎯 Important Concept

Image → Grayscale → Histogram → Probability → Information → Entropy

Image entropy is the average amount of information carried by the intensity distribution of the image.

For an 8-bit grayscale image, the theoretical maximum is:

Hmax = log₂(256) = 8 bits/pixel

📡 Entropy of an Information Source

📡 Entropy of an Information Source

Information Theory • Mathematical Explanation • Numerical Examples

📖 1. What is Entropy?

In Information Theory, entropy measures the average amount of uncertainty or information produced by an information source.

If the outcome of a source is highly uncertain, its entropy is high. If the outcome is almost certain, its entropy is low.

Simple idea:

🎲 More uncertainty → More information → Higher entropy

🎯 Less uncertainty → Less information → Lower entropy

📐 2. Information Content of an Event

Suppose an event x occurs with probability P(x). The information contained in that event is:

I(x) = −log₂ P(x)

The unit is called a bit when the logarithm is base 2.

Example

Suppose an event has probability:

P(x) = 1/2

Then:

I(x) = −log₂(1/2)
= −(−1)
= 1 bit

Therefore, an event having probability 1/2 carries 1 bit of information.

🧮 3. Mathematical Formula of Entropy

Suppose an information source can produce n different symbols:

X = {x₁, x₂, x₃, ..., xₙ}

with probabilities:

P = {p₁, p₂, p₃, ..., pₙ}

where:

p₁ + p₂ + ... + pₙ = 1

The entropy of the source is:

H(X) = − Σ pᵢ log₂(pᵢ)

or explicitly:

H(X) = −[p₁log₂p₁ + p₂log₂p₂ + ... + pₙlog₂pₙ]

📊 4. Why Do We Take an Average?

The information associated with an individual symbol is:

I(xᵢ) = −log₂(pᵢ)

The average information is obtained by multiplying each information value by its probability:

H(X) = Σ pᵢ I(xᵢ)

Substituting:

H(X) = Σ pᵢ[−log₂(pᵢ)]

Therefore:

H(X) = −Σ pᵢlog₂(pᵢ)

🎯 Example 1 — Fair Coin

Consider a fair coin with two possible outcomes:

Symbol Probability
Head (H) 0.5
Tail (T) 0.5

Using:

H(X) = −Σpᵢlog₂(pᵢ)

Therefore:

H(X) = −[0.5log₂(0.5) + 0.5log₂(0.5)]

Since:

log₂(0.5) = −1

Therefore:

H(X) = −[0.5(−1) + 0.5(−1)]
= −[−0.5 − 0.5]
= 1 bit
Answer: Entropy of a fair coin = 1 bit.

🎲 Example 2 — Biased Coin

Suppose:

Outcome Probability
Head 0.8
Tail 0.2

Entropy:

H(X) = −[0.8log₂(0.8) + 0.2log₂(0.2)]

Using approximate values:

log₂(0.8) ≈ −0.3219
log₂(0.2) ≈ −2.3219

Therefore:

H(X) = −[0.8(−0.3219) + 0.2(−2.3219)]

≈ 0.722 bits
Answer: Entropy ≈ 0.722 bits.

Notice that this is less than 1 bit because the coin is biased, so there is less uncertainty.

📦 Example 3 — Three Symbol Source

Consider a source:

X = {A, B, C}

with probabilities:

Symbol Probability
A 0.5
B 0.3
C 0.2

Check:

0.5 + 0.3 + 0.2 = 1

Entropy:

H(X) = −[0.5log₂0.5 + 0.3log₂0.3 + 0.2log₂0.2]

Using approximate logarithms:

H(X) ≈ 1.485 bits

🏆 5. Maximum Entropy

For a source having n equally probable symbols:

p₁ = p₂ = ... = pₙ = 1/n

The entropy becomes:

H(X) = −n(1/n)log₂(1/n)

Therefore:

Hmax = log₂(n)

Example

For 4 equally probable symbols:

Hmax = log₂(4) = 2 bits

For 8 equally probable symbols:

Hmax = log₂(8) = 3 bits

⬇️ 6. Minimum Entropy

If one symbol has probability 1 and all other symbols have probability 0:

P(X) = {1,0,0,...,0}

Then:

H(X) = 0 bits

There is no uncertainty because the outcome is completely predictable.

⭐ 7. Important Properties of Entropy

1️⃣ Non-Negative

H(X) ≥ 0

Entropy cannot be negative.

2️⃣ Certain Event

P(X)=1 ⇒ H(X)=0

A completely predictable source has zero entropy.

3️⃣ Maximum

Hmax=log₂n

Maximum entropy occurs when all symbols are equally probable.

4️⃣ Unit

When log₂ is used, entropy is measured in bits/symbol.

🎬 Animated Entropy Calculation

The following animation demonstrates how the entropy of a source is calculated from probability → information → weighted information → total entropy.

📡 Probability → Information → Entropy

P(x) Probability
I(x) Information
pI(x) Weighted
H(X) Entropy
Press ▶ Start Animation
H(X)

🧮 General Numerical Example

Suppose an information source produces four symbols:

Symbol Probability Information
A 0.4 −log₂(0.4)
B 0.3 −log₂(0.3)
C 0.2 −log₂(0.2)
D 0.1 −log₂(0.1)

Therefore:

H(X) = −[0.4log₂(0.4) +0.3log₂(0.3) +0.2log₂(0.2) +0.1log₂(0.1)]

Approximate calculation gives:

H(X) ≈ 1.846 bits/symbol

🌍 8. Real-Life Applications

📡 Communication

Entropy helps measure the information generated by a communication source.

🗜️ Data Compression

Entropy provides a theoretical limit for lossless data compression.

💻 Computer Networks

It can be used to analyze information transmitted through communication channels.

🤖 Machine Learning

Entropy is used in decision trees to measure impurity and choose useful splits.

📌 Important Formulas for Examination

Information:
I(x) = −log₂P(x)
Entropy:
H(X) = −Σpᵢlog₂pᵢ
Maximum Entropy:
Hmax = log₂n
Minimum Entropy:
Hmin = 0

🎯 Quick Revision

  • 📡 Entropy measures the average uncertainty of an information source.
  • 🧮 Information of an event = −log₂P(x).
  • 📊 Entropy = −Σpᵢlog₂pᵢ.
  • 🎲 A fair binary source has entropy 1 bit.
  • 📉 A biased source has lower entropy than an equally probable source with the same number of symbols.
  • 🏆 Maximum entropy for n symbols is log₂n.
  • ⬇️ Minimum entropy is 0.
  • 💾 Entropy is fundamental in information theory and data compression.

FIRST AND FOLLOW LL(1) STEP BY STEP

🔤 FIRST & FOLLOW Calculator

15 Grammar Examples • Step-by-Step • Animated Learning

📖 FIRST and FOLLOW — First Understand

🔵 FIRST

FIRST(X) is the set of terminals that can appear at the beginning of strings derived from X.

FIRST(X) = Possible starting terminals

🟣 FOLLOW

FOLLOW(A) is the set of terminals that can appear immediately after the non-terminal A.

FOLLOW(A) = Symbols occurring after A

⚪ Epsilon

The symbol ε means the empty string. If a symbol can generate ε, we may need to examine the next symbol.

💲 End Marker

The symbol $ represents the end of the input. For the start symbol:

$ ∈ FOLLOW(Start Symbol)

📚 Important Rules

FIRST Rule 1

If X is a terminal:

FIRST(X) = {X}
FIRST Rule 2

For A → aα:

a ∈ FIRST(A)
FOLLOW Rule 1

For the start symbol:

$ ∈ FOLLOW(S)
FOLLOW Rule 2

For A → αBβ:

FIRST(β) − {ε} ⊆ FOLLOW(B)

🎓 15 Practice Examples

Example 1 of 15
Example 1

Grammar

S → aA | bB A → c B → d

🔎 Step-by-Step Calculation

✅ Final FIRST & FOLLOW

🎬 Animated FIRST → FOLLOW Visualization

📜
Grammar
🔵
FIRST

Check ε
Press "Animate" to start
FIRST / FOLLOW

📋 15 Examples — Quick Reference

No. Grammar Type Main Concept
1 Simple Grammar Basic FIRST
2 A → a | ε Epsilon
3 S → ABC Multiple Symbols
4 S → aS | b Recursion
5 S → (S)S | ε Balanced Structure
6 Expression Grammar FIRST/FOLLOW
7 Epsilon Grammar Propagation
8 Arithmetic Grammar LL(1)
9 Assignment Terminal After NT
10 Nested Expression Nested FOLLOW
11 Multiple Epsilon Epsilon Propagation
12 Boolean Grammar Logical Operators
13 List Grammar Repeated Elements
14 Statement Grammar Parser Design
15 Complex LL(1) Complete Revision

⭐ Why FIRST and FOLLOW Are Important?

1️⃣ LL(1) Parser

FIRST and FOLLOW are fundamental for constructing LL(1) predictive parsing tables.

2️⃣ Production Selection

They help the parser select the correct production for a given input symbol.

3️⃣ ε Productions

FOLLOW helps determine when an ε-production should be selected.

4️⃣ Syntax Analysis

They are important concepts in the syntax-analysis phase of compiler design.

🧠 KERAS WITH PYTHON Four-Layer Neural Network – Real-Life Student Performance Prediction

🧠 KERAS WITH PYTHON
Four-Layer Neural Network – Real-Life Student Performance Prediction

📘 What is Keras?

Keras is a high-level deep-learning API that provides a simple way to build, train, evaluate and use neural networks with Python.

Keras provides ready-to-use components such as Dense layers, activation functions, optimizers, loss functions and training methods.

In this example, we will use Keras to create a neural network that predicts a student's expected examination marks using information such as study time, attendance, previous marks and assignment performance.

🎓 Real-Life Example: Student Marks Prediction

Suppose a teacher wants to estimate the expected marks of a student. The following four features are available:

  • 📚 Study Hours per day
  • 🏫 Attendance percentage
  • 📝 Previous Marks percentage
  • 📖 Assignment Score percentage

The neural network learns a relationship between these four inputs and the student's expected examination marks.

Study Hours + Attendance + Previous Marks + Assignment Score

Neural Network

Predicted Examination Marks

🔷 Four-Layer Neural Network Architecture

The model contains four trainable Dense layers. The input consists of four features.

📥
INPUT
4 Features
➡️
⚙️
LAYER 1
16 Neurons
ReLU
➡️
⚙️
LAYER 2
12 Neurons
ReLU
➡️
⚙️
LAYER 3
8 Neurons
ReLU
➡️
📤
LAYER 4
1 Neuron
Linear
4 Inputs → 16 → 12 → 8 → 1 Output

📊 Sample Training Dataset

The following is a small educational dataset. The target value is the student's examination mark.

Study Hours Attendance % Previous Marks % Assignment % Exam Marks
2 60 45 50 48
3 65 50 55 55
4 70 60 65 65
5 75 68 70 72
6 85 78 80 82
7 90 85 88 90

Note: This small dataset is intended to demonstrate the Keras workflow. A real prediction system would require a much larger, representative dataset and appropriate validation.

⚙️ Step 1: Install Required Libraries

Install TensorFlow and NumPy using:

pip install tensorflow numpy

💻 Step 2: Complete Python Code

import numpy as np
from tensorflow import keras
from tensorflow.keras import layers

# ---------------------------------------
# 1. Training Data
# ---------------------------------------

# Columns:
# 1 = Study Hours
# 2 = Attendance
# 3 = Previous Marks
# 4 = Assignment Score

X = np.array([
    [2, 60, 45, 50],
    [3, 65, 50, 55],
    [4, 70, 60, 65],
    [5, 75, 68, 70],
    [6, 85, 78, 80],
    [7, 90, 85, 88],
    [3, 68, 52, 58],
    [5, 80, 72, 75],
    [6, 88, 82, 85],
    [4, 72, 62, 68]
], dtype=float)


# Target: Examination Marks

y = np.array([
    48,
    55,
    65,
    72,
    82,
    90,
    57,
    76,
    86,
    67
], dtype=float)


# ---------------------------------------
# 2. Create Four-Layer Neural Network
# ---------------------------------------

model = keras.Sequential([

    # Layer 1
    layers.Dense(
        16,
        activation="relu",
        input_shape=(4,)
    ),

    # Layer 2
    layers.Dense(
        12,
        activation="relu"
    ),

    # Layer 3
    layers.Dense(
        8,
        activation="relu"
    ),

    # Layer 4 - Output
    layers.Dense(
        1,
        activation="linear"
    )
])


# ---------------------------------------
# 3. Compile the Model
# ---------------------------------------

model.compile(
    optimizer="adam",
    loss="mean_squared_error",
    metrics=["mae"]
)


# ---------------------------------------
# 4. Display Model Architecture
# ---------------------------------------

model.summary()


# ---------------------------------------
# 5. Train the Model
# ---------------------------------------

model.fit(
    X,
    y,
    epochs=500,
    verbose=0
)


# ---------------------------------------
# 6. Evaluate the Model
# ---------------------------------------

loss, mae = model.evaluate(
    X,
    y,
    verbose=0
)

print("Mean Absolute Error:", mae)


# ---------------------------------------
# 7. Test a New Student
# ---------------------------------------

new_student = np.array([
    [5.5, 82, 76, 80]
], dtype=float)


# ---------------------------------------
# 8. Predict Examination Marks
# ---------------------------------------

prediction = model.predict(
    new_student,
    verbose=0
)

print(
    "Predicted Examination Marks:",
    prediction[0][0]
)

🔍 Description of Each Layer

1️⃣ Layer 1 – 16 Neurons

layers.Dense(16, activation="relu", input_shape=(4,))

This is the first Dense layer. It receives four input features:

  • Study Hours
  • Attendance
  • Previous Marks
  • Assignment Score

It contains 16 neurons and uses the ReLU activation function.

2️⃣ Layer 2 – 12 Neurons

layers.Dense(12, activation="relu")

The second layer receives the features learned by the first layer. It contains 12 neurons.

This layer allows the network to learn more complex relationships between the student's characteristics.

3️⃣ Layer 3 – 8 Neurons

layers.Dense(8, activation="relu")

The third layer further processes the information received from Layer 2 and learns higher-level patterns.

4️⃣ Layer 4 – Output Layer

layers.Dense(1, activation="linear")

The final layer contains one neuron because the model needs to produce one numerical prediction: expected examination marks.

A linear output is appropriate for this simple regression example.

🔗 Understanding Sequential Model

model = keras.Sequential([
    layers.Dense(16, activation="relu", input_shape=(4,)),
    layers.Dense(12, activation="relu"),
    layers.Dense(8, activation="relu"),
    layers.Dense(1, activation="linear")
])

Sequential means that the layers are connected in a simple sequence. The output of one layer becomes the input to the next layer.

Input → Layer 1 → Layer 2 → Layer 3 → Output Layer

⚙️ Understanding model.compile()

model.compile(
    optimizer="adam",
    loss="mean_squared_error",
    metrics=["mae"]
)

🔹 Optimizer – Adam

Adam controls how the model's weights are updated during training.

🔹 Loss – Mean Squared Error

MSE = 1/n Σ(y − ŷ)²

Here y is the actual mark and ŷ is the predicted mark.

🔹 Metric – MAE

MAE = 1/n Σ|y − ŷ|

MAE represents the average absolute difference between actual and predicted values.

🔄 How the Four-Layer Model Learns

Student Data
➡️
Layer 1
➡️
Layer 2
➡️
Layer 3
➡️
Layer 4
➡️
Prediction

After producing a prediction, the model calculates the loss by comparing the predicted mark with the actual mark. The optimizer then updates the weights. This process is repeated over many epochs.

🔮 Predicting a New Student's Marks

new_student = np.array([
    [5.5, 82, 76, 80]
])

prediction = model.predict(new_student)

print(
    "Predicted Examination Marks:",
    prediction[0][0]
)

The new student's information is:

  • 📚 Study Hours = 5.5 hours/day
  • 🏫 Attendance = 82%
  • 📝 Previous Marks = 76%
  • 📖 Assignment Score = 80%

The four values are passed through the four-layer neural network, and the final neuron produces the predicted examination mark.

🖥️ Example Output

Model: "sequential"

Layer (type)              Output Shape
-----------------------------------------
Dense                     (None, 16)
Dense                     (None, 12)
Dense                     (None, 8)
Dense                     (None, 1)

Mean Absolute Error: 1.5

Predicted Examination Marks: 78.6

The exact output can differ because neural networks generally start with randomly initialized weights and this example uses a very small dataset.

⚡ Why ReLU and Linear Activation?

ReLU

ReLU(x) = max(0,x)

ReLU is used in the hidden layers because it introduces non-linearity and helps the network learn complex patterns.

Linear

f(x) = x

A linear output is useful for regression tasks where the predicted value is a continuous number such as marks, temperature or price.

📚 Important Keras Terms

Term Meaning
Sequential Creates a model where layers are arranged sequentially.
Dense A fully connected neural-network layer.
ReLU Activation function used in the hidden layers.
Linear Activation used here for continuous numerical prediction.
Epoch One complete pass through the training dataset.
Loss A measure of how different the prediction is from the actual value.
Optimizer Updates model parameters to reduce the loss.

🎯 Complete Learning Flow

Student Information

4 Input Features

16-Neuron Layer

12-Neuron Layer

8-Neuron Layer

1-Neuron Output Layer

Predicted Examination Marks

Key Points

  1. Keras makes neural-network development easier.
  2. A Dense layer contains interconnected neurons.
  3. The first three layers use ReLU activation.
  4. The final layer uses linear activation for regression.
  5. Adam is used as the optimizer.
  6. Mean Squared Error is used as the loss function.
  7. MAE is used to measure prediction error.
  8. fit() trains the model.
  9. evaluate() measures model performance.
  10. predict() generates predictions for new data.
🧠 Keras & Python Neural Network Learning Module
Created by Bijan Krishna Paul

🧠 Keras with Python Simple Two-Layer Neural Network – Real-Life House Price Prediction

🧠 Keras with Python
Simple Two-Layer Neural Network – Real-Life House Price Prediction

📘 What is Keras?

Keras is a high-level deep learning API that makes it easier to create, train, evaluate and use neural networks with Python.

Instead of manually implementing every mathematical operation of a neural network, Keras provides ready-made components such as Dense layers, activation functions, optimizers and loss functions.

Keras is commonly used for applications such as image classification, text processing, prediction, pattern recognition and many other machine-learning tasks.

🏠 Real-Life Example: House Price Prediction

Imagine a real-estate company wants to estimate the price of a house. Two important pieces of information are available:

  • 📐 House Area in square feet
  • 🛏️ Number of Bedrooms

A neural network can learn the relationship between these input features and the house price.

House Area + Bedrooms

Neural Network

Predicted House Price

🔷 Two-Layer Neural Network Architecture

In this example, the neural network contains two trainable Dense layers.

📥
Input
2 Features
Area + Bedrooms
➡️
⚙️
Layer 1
10 Neurons
ReLU
➡️
📤
Layer 2
1 Neuron
Linear Output
2 Inputs → 10 Hidden Neurons → 1 Output

📊 Sample Training Dataset

For simplicity, house prices are represented in ₹ Lakhs. The dataset below is only an educational example.

Area (sq.ft.) Bedrooms Price (₹ Lakhs)
800 2 40
1000 2 50
1200 3 65
1500 3 80
1800 4 100
2200 4 120

⚙️ Step 1: Install Required Libraries

Install TensorFlow and NumPy using:

pip install tensorflow numpy

TensorFlow provides Keras, while NumPy is used for numerical arrays.

💻 Step 2: Complete Python Code

import numpy as np
from tensorflow import keras
from tensorflow.keras import layers

# --------------------------------
# 1. Training Data
# --------------------------------

# Input:
# Column 1 = House Area
# Column 2 = Number of Bedrooms

X = np.array([
    [800, 2],
    [1000, 2],
    [1200, 3],
    [1500, 3],
    [1800, 4],
    [2200, 4]
], dtype=float)

# Target values: House Price in ₹ Lakhs

y = np.array([
    40,
    50,
    65,
    80,
    100,
    120
], dtype=float)


# --------------------------------
# 2. Create Two-Layer Model
# --------------------------------

model = keras.Sequential([

    # Layer 1: Hidden Layer
    layers.Dense(
        10,
        activation="relu",
        input_shape=(2,)
    ),

    # Layer 2: Output Layer
    layers.Dense(
        1,
        activation="linear"
    )
])


# --------------------------------
# 3. Compile the Model
# --------------------------------

model.compile(
    optimizer="adam",
    loss="mean_squared_error",
    metrics=["mae"]
)


# --------------------------------
# 4. Train the Model
# --------------------------------

model.fit(
    X,
    y,
    epochs=500,
    verbose=0
)


# --------------------------------
# 5. Evaluate the Model
# --------------------------------

loss, mae = model.evaluate(
    X,
    y,
    verbose=0
)

print("Mean Absolute Error:", mae)


# --------------------------------
# 6. Predict Price of a New House
# --------------------------------

new_house = np.array([
    [1600, 3]
], dtype=float)

prediction = model.predict(
    new_house,
    verbose=0
)

print(
    "Predicted House Price:",
    prediction[0][0],
    "Lakhs"
)

🔍 Step-by-Step Code Description

1️⃣ Import NumPy and Keras

import numpy as np
from tensorflow import keras
from tensorflow.keras import layers

NumPy is used to store and process numerical data. Keras is imported from TensorFlow to create the neural network.

2️⃣ Prepare the Input Data

X = np.array([
    [800, 2],
    [1000, 2],
    [1200, 3],
    [1500, 3]
])

Each row represents one house. The first value represents the area and the second value represents the number of bedrooms.

3️⃣ Prepare the Target Values

y = np.array([
    40,
    50,
    65,
    80
])

These values represent the corresponding house prices in ₹ Lakhs.

4️⃣ Create the First Layer

layers.Dense(
    10,
    activation="relu",
    input_shape=(2,)
)

The first Dense layer contains 10 neurons. It receives two input features:

  • House Area
  • Number of Bedrooms

The ReLU activation function allows the network to learn non-linear relationships.

5️⃣ Create the Second Layer

layers.Dense(
    1,
    activation="linear"
)

The second layer contains one neuron because we want to predict one numerical value: house price.

A linear activation is suitable for a basic regression problem because the output is a continuous numerical value.

6️⃣ Compile the Model

model.compile(
    optimizer="adam",
    loss="mean_squared_error",
    metrics=["mae"]
)
  • Adam: Optimizer that updates the model parameters during training.
  • Mean Squared Error: Measures the squared difference between actual and predicted prices.
  • MAE: Mean Absolute Error, which gives the average absolute prediction error.

7️⃣ Train the Model

model.fit(
    X,
    y,
    epochs=500
)

The fit() function trains the neural network. During training, Keras adjusts the weights and biases to reduce the prediction error.

8️⃣ Predict a New House

new_house = np.array([
    [1600, 3]
])

prediction = model.predict(new_house)

The new house has:

  • 📐 Area = 1600 sq.ft.
  • 🛏️ Bedrooms = 3

The trained network estimates the price of this new house.

🧩 Understanding the Two Layers

Layer Neurons Activation Purpose
Layer 1 10 ReLU Learns patterns from area and bedrooms.
Layer 2 1 Linear Produces the predicted house price.

📐 Mathematics Behind the Model

A neuron first calculates a weighted sum:

z = w₁x₁ + w₂x₂ + b

where:

  • x₁ = house area
  • x₂ = number of bedrooms
  • w₁, w₂ = learned weights
  • b = bias

The first layer applies ReLU:

ReLU(z) = max(0,z)

The output layer then produces the predicted continuous value.

Predicted Price = w₁h₁ + w₂h₂ + ... + b

🔄 How the Model Learns

Training Data
➡️
Neural Network
➡️
Prediction
➡️
Calculate Loss
➡️
Update Weights

This process is repeated for many epochs. The optimizer gradually changes the weights and biases so that the predicted prices become closer to the training values.

🖥️ Example Output

Mean Absolute Error: 1.8

Predicted House Price: 85.4 Lakhs

The exact numerical result may differ slightly between runs because neural networks normally begin with randomly initialized weights.

📚 Important Keras Terms

Term Meaning
Sequential Creates a model where layers are arranged one after another.
Dense A fully connected neural-network layer.
ReLU Activation function commonly used in hidden layers.
Linear Suitable for producing continuous numerical outputs.
Epoch One complete pass through the training dataset.
Optimizer Algorithm used to update the model's weights and biases.

🎯 Summary

  1. Collect house information.
  2. Prepare input and target data.
  3. Create a Keras Sequential model.
  4. Add the first Dense layer with 10 neurons.
  5. Add the second Dense layer with 1 output neuron.
  6. Compile the model.
  7. Train the model using fit().
  8. Evaluate the model.
  9. Give a new house as input.
  10. Use predict() to estimate its price.
🏠 House Data → 🧠 Keras Model → 📚 Training → 🔮 Price Prediction
🧠 Keras & Python Neural Network Learning Module
Created by Bijan Krishna Paul