Lesson 1 - Deep Learning Fundamentals

Welcome to Deep Learning with TensorFlow

This lesson introduces deep learning and the framework you will use to build it: TensorFlow, together with its high-level interface, Keras. You will learn what makes deep learning different from the classic machine learning you may already know, why a framework is worth learning at all, and how the training loop quietly powers every neural network you will ever build. Along the way you will meet the dataset that runs through this entire module and frame the real prediction problem you are going to solve.

By the end of this lesson, you will be able to:

  • Explain what deep learning is and how a neural network differs from a classic model
  • Describe why frameworks like TensorFlow and Keras exist and what they handle for you
  • Walk through the high-level training loop: data, tensors, model, loss, backpropagation, and the optimizer step
  • Describe the Indian IPO dataset and the binary prediction task you will work on
  • Recognize how a balanced target shapes the way you evaluate a classifier

You should be comfortable with basic Python, pandas, and NumPy, and it helps if you have seen the general machine learning workflow before. No deep learning experience is required. Let’s begin.


What Is Deep Learning?

You have probably built a model before by handing a table of numbers to an algorithm and asking it to learn a pattern. Deep learning does the same thing at heart, but it changes who designs the features the model learns from.

In classic machine learning, you often spend most of your time crafting features by hand. You decide that the ratio of two columns matters, you bin an age into groups, you combine signals you suspect are useful. The algorithm then learns weights over the features you engineered. The quality of your model is capped by the quality of your feature engineering.

Deep learning flips this. Instead of you designing the features, a stack of simple computational layers learns useful representations of the raw data on its own. Each layer transforms its input a little, and the layers compose so that early layers capture simple patterns while later layers combine them into richer, more abstract ones. This idea, learning the representation rather than hand-coding it, is what people mean by representation learning, and it is the engine behind modern breakthroughs in image recognition, speech, and language.

Neurons, Layers, and Networks

The basic unit of a neural network is the neuron (also called a node). A neuron takes several input numbers, multiplies each by a weight, sums the results, adds a small offset called a bias, and passes that sum through a simple nonlinear function. That nonlinear function, the activation, is what lets the network bend and fold the data instead of only drawing straight lines.

Neurons are organized into layers:

  • The input layer is where your features enter the network, one value per feature.
  • One or more hidden layers sit in the middle. This is where the network discovers patterns and interactions between features.
  • The output layer produces the final answer, such as a probability that an IPO lists with a gain.
   input layer        hidden layer(s)        output layer
   +---------+        +-------------+         +---------+
   | feat 1  | -----> |  o   o   o  | ----->  | p(gain) |
   | feat 2  | -----> |  o   o   o  |         +---------+
   |  ...    | -----> |  o   o   o  |
   | feat 6  |        +-------------+
   +---------+

A network with no hidden layers, or just one, is called a shallow network. It can only learn relatively simple relationships. When you stack many hidden layers, you get a deep network, and “deep learning” is simply learning with these deeper stacks. The extra depth lets the model capture nonlinear, interacting patterns that a shallow model would miss, at the cost of needing more data and more computation to train.

Depth is a trade-off, not a free win

More layers can model more complex patterns, but they also need more data, more compute, and more careful tuning. For small tabular datasets like the one in this module, a modest network often beats a giant one. Reach for depth when the problem genuinely demands it, not by reflex.


Why Use a Framework Like TensorFlow?

You could, in principle, write a neural network from scratch in NumPy. People do it once as a learning exercise, and it is genuinely useful for understanding what happens inside. But for real work it quickly becomes painful, and that is exactly the gap a framework fills.

TensorFlow is an open-source deep learning framework. Keras is its high-level interface, the part you will spend almost all your time in, designed to make building and training networks readable and fast. When you use TensorFlow and Keras, several hard problems are handled for you:

  • Tensors and hardware. Networks compute on tensors, multi-dimensional arrays much like NumPy arrays. TensorFlow can run those tensor operations on a CPU or transparently move them to a GPU for a large speedup, without you rewriting your code.
  • Automatic differentiation. Training a network means nudging its weights in the direction that reduces error. Working out that direction requires calculus, the derivative of the loss with respect to every weight. TensorFlow computes these gradients automatically, so you never differentiate by hand.
  • Ready-made building blocks. Layers, activation functions, loss functions, and optimizers come built in and tested. You assemble them like LEGO instead of reimplementing them.
  • A clean training loop. Keras wraps the whole train-evaluate cycle behind a small, consistent set of methods, so the same few lines train almost any model.

TensorFlow, Keras, and the bigger picture

Think of TensorFlow as the engine and Keras as the steering wheel. TensorFlow does the heavy numerical work on tensors and gradients; Keras gives you a friendly, high-level way to drive it. You will write Keras code most of the time and only occasionally drop down to raw TensorFlow when you need fine control.

The payoff is leverage. The same framework that trains a two-layer classifier on a few hundred rows also trains models with billions of parameters on huge datasets. Learning the framework once means the skills transfer all the way up.


The High-Level Training Loop

Every neural network you will ever train, from the smallest classifier to the largest language model, is trained by the same loop. Understanding it now gives you a mental map for everything that follows. The diagram below shows the cycle.

The TensorFlow training loop: data flows into tensors, through the model to produce predictions, the loss compares them to the truth, backpropagation computes gradients, and the optimizer updates the weights
The training loop is a cycle: data becomes tensors, the model predicts, the loss measures error, backpropagation finds the gradients, and the optimizer updates the weights.

Let’s walk through each stage.

Step 1: Data to Tensors

Everything starts with your data. Before a network can touch it, the raw table of features and labels is converted into tensors, the numeric arrays TensorFlow operates on. A batch of feature rows becomes one tensor, and the matching labels become another. This is also where you would scale features and split into training and test sets, just as in any machine learning workflow.

Step 2: The Model Makes a Prediction

The feature tensor flows forward through the network. Each layer multiplies, sums, adds its bias, and applies its activation, passing the result to the next layer until the output layer produces a prediction. This forward pass is called forward propagation. For our IPO problem, the output will be a number between 0 and 1: the model’s estimated probability that an IPO lists with a gain.

Step 3: The Loss Measures the Error

A prediction is only useful if you can tell how wrong it is. The loss function compares the model’s predictions to the true labels and returns a single number: large when the model is far off, small when it is close. For binary classification you will use binary cross-entropy, a loss that strongly penalizes confident wrong answers. Training is, in one sentence, the search for weights that make this loss as small as possible.

Step 4: Backpropagation Computes the Gradients

Now the question is which way to nudge each weight to reduce the loss. The answer comes from backpropagation, an efficient application of the chain rule that computes the gradient of the loss with respect to every weight in the network. The gradient points in the direction of steepest increase, so its negative points toward lower loss. TensorFlow performs this entire computation automatically; you never write the derivatives yourself.

Step 5: The Optimizer Updates the Weights

Finally, the optimizer takes those gradients and adjusts each weight a small step in the direction that lowers the loss. The size of that step is controlled by the learning rate. A popular optimizer called Adam adapts the step size per weight and works well out of the box. After this update, the weights are slightly better than before.

Putting the Loop Together

Steps 2 through 5 repeat, over and over, on batches of data. One full pass through the training data is called an epoch, and you usually train for many epochs. With each pass the loss drifts lower and the predictions get sharper.

The arithmetic of the forward pass is just a weighted sum at each neuron. For a single neuron with inputs xi x_i , weights wi w_i , and bias b b , the pre-activation value is:

z=iwixi+b z = \sum_{i} w_i x_i + b

and the neuron’s output is a=f(z) a = f(z) , where f f is the activation function. Stacking many of these and learning the weights with the loop above is, mechanically, all a neural network does.

# The training loop in plain pseudocode (Keras hides this behind one .fit() call)
for epoch in range(num_epochs):
    for x_batch, y_batch in training_data:
        predictions = model(x_batch)            # 2. forward pass
        loss = loss_fn(y_batch, predictions)    # 3. measure error
        gradients = compute_gradients(loss)     # 4. backpropagation
        optimizer.apply(gradients, model)       # 5. update weights
# Output: (no printed values; this is the conceptual shape of training)

You will not type this loop yourself in most lessons. Keras packs it into a single model.fit(...) call. But knowing the five steps means you always understand what fit is doing under the hood.

The loop never really changes

Predict, measure, find the gradient, update, repeat. This same loop trains a tiny classifier and a state-of-the-art model with billions of parameters. What changes between them is scale and architecture, not the fundamental cycle. Internalize it once and every deep learning system becomes legible.


The Dataset You Will Use: Indian IPOs

Concepts stick when you apply them to something concrete, so this whole module is built around one real dataset: Indian IPOs. An IPO, or initial public offering, is the moment a private company first sells shares to the public on a stock exchange. On listing day the share price can open above the offer price (a listing gain) or below it (a loss). Predicting which outcome happens is a genuine, messy, binary classification problem, and it is exactly the kind of tabular task deep learning is comfortable with.

Your goal across this module is to predict whether an IPO lists with a gain using a handful of numeric features describing the offering.

You can download the dataset and load it with pandas.

import pandas as pd

# download: https://datatweets.com/datasets/indian_ipo.csv
df = pd.read_csv("indian_ipo.csv")

print("Shape:", df.shape)
# Output: Shape: (319, 10)

The dataset has 319 rows and 10 columns. Each row is one IPO. After dropping identifier columns, you will work with 6 numeric features describing the offering and one binary target.

The Target: Listing_Gains

The column you are predicting is Listing_Gains. It is already encoded as 1 when the IPO listed with a gain and 0 when it did not, so no conversion is needed.

print(df["Listing_Gains"].value_counts())
# Output:
# Listing_Gains
# 1    174
# 0    145
# Name: count, dtype: int64

print("gain rate:", round(df["Listing_Gains"].mean(), 3))
# Output: gain rate: 0.545

About 54.5 percent of the IPOs listed with a gain (174 out of 319). That makes this a balanced dataset: the two outcomes are close to evenly split. Balance is good news for evaluation, because when one class hugely outnumbers the other, plain accuracy can be misleading. A picture makes the balance clear.

Bar chart comparing the count of IPOs that listed with a gain versus those that did not, showing a roughly even split
Most Indian IPOs in the dataset listed with a gain, but the split is close to even, which makes accuracy a fair first metric.

Why the balance matters

If 95 percent of IPOs had listed with a gain, a lazy model that always predicts “gain” would score 95 percent accuracy while learning nothing. Because this target is close to a coin flip, a model genuinely has to learn the patterns to beat the baseline of about 55 percent. Always check your target’s balance before trusting an accuracy number.

The Features

The six numeric features describe the offering itself: things like the issue size, the subscription demand from different investor categories, and the offer price. You do not need to memorize them yet. The important point is that they are all numeric, which is exactly what a neural network expects after a little scaling. You will explore and prepare them in detail in the coming lessons.

# Separate the features (X) from the target (y)
target = "Listing_Gains"
X = df.drop(columns=[target]).select_dtypes("number")
y = df[target]

print("Feature columns:", X.shape[1])
print("Observations:   ", X.shape[0])
# Output:
# Feature columns: 6
# Observations:    319

By the now-familiar convention, the features live in X and the target in y. With 319 observations this is a small dataset by deep learning standards, which is a useful reminder: deep learning is a tool, not a magic wand. On data this size you will keep your networks modest and lean on good practice to avoid overfitting.


How This Connects to the Rest of the Module

You now have the full map. The remaining lessons walk the training loop from the inside out:

  • Tensors are the data structure everything rides on, so the next lesson teaches TensorFlow’s tensor operations directly.
  • The model comes next: you will build a network with the Keras Sequential API, then train it, then deepen it with more layers.
  • Backpropagation and the optimizer are handled for you by Keras during fit, but you now understand exactly what they are doing.
  • The data, the Indian IPO table, is the thread tying every lesson together, ending in a project where you predict listing gains end to end.

Keeping the five-step loop in mind as you go will make each new piece feel like a familiar part of one machine rather than an isolated trick.


Practice Exercises

Now it is your turn. Try these before checking the hints.

Exercise 1: Confirm the Target Balance

Load the Indian IPO dataset and verify the class balance yourself. Print the count of each class in Listing_Gains and the fraction of IPOs that listed with a gain, rounded to three decimals.

import pandas as pd

# download: https://datatweets.com/datasets/indian_ipo.csv
df = pd.read_csv("indian_ipo.csv")

# Your code here

Hint

Use df["Listing_Gains"].value_counts() for the counts, and round(df["Listing_Gains"].mean(), 3) for the gain rate. Because the target is already 1/0, taking the mean gives you the fraction of ones directly. You should see counts of 174 and 145 and a gain rate of 0.545.

Exercise 2: Label the Steps of the Training Loop

Without writing any code, list the five stages of the high-level training loop in the correct order, and in one sentence each, say what stage does. This cements the mental model you will rely on for the rest of the module.

# Fill in the order:
# 1. ?
# 2. ?
# 3. ?
# 4. ?
# 5. ?

Hint

The order is: (1) data to tensors, (2) the model makes a prediction with a forward pass, (3) the loss measures the error, (4) backpropagation computes the gradients, and (5) the optimizer updates the weights. Steps 2 through 5 repeat for many batches and epochs.

Exercise 3: Count Features and a Naive Baseline

Separate the numeric features from the target, print how many feature columns you have, and compute the accuracy of the simplest possible “model”: one that always predicts the majority class (gain). Comparing any real model to this baseline tells you whether it learned anything.

target = "Listing_Gains"

# Your code here

Hint

Build features with df.drop(columns=[target]).select_dtypes("number") and check .shape[1] for the count (6). The majority-class baseline accuracy is just the gain rate, df[target].mean(), about 0.545, since always guessing “gain” is right exactly that often. Any trained model worth keeping should beat this.


Summary

Congratulations! You now understand what deep learning is, why a framework like TensorFlow and Keras is worth learning, and how the training loop turns data into a working model. Let’s review what you learned.

Key Concepts

What Deep Learning Is

  • Deep learning uses stacked layers of neurons to learn useful representations of data automatically, instead of relying on hand-engineered features
  • A neuron computes a weighted sum plus a bias, then applies a nonlinear activation
  • Shallow networks have few layers; deep networks stack many, trading more capacity for more data and compute

Why a Framework

  • TensorFlow runs tensor math on CPU or GPU; Keras is its high-level, readable interface
  • Frameworks handle tensors, automatic differentiation, ready-made layers and optimizers, and a clean training loop so you do not reimplement them

The Training Loop

  • Data becomes tensors, the model predicts via forward propagation, the loss measures error, backpropagation computes gradients, and the optimizer updates the weights
  • One full pass over the data is an epoch; the loop repeats over many batches and epochs
  • Keras hides this entire loop behind model.fit(...), but the five steps never change

The Indian IPO Dataset

  • 319 IPOs, 6 numeric features, and a binary target Listing_Gains (already 1/0)
  • The goal is to predict whether an IPO lists with a gain
  • The target is balanced at a gain rate of about 0.545, so accuracy is a fair first metric and the baseline to beat is roughly 55 percent

Why This Matters

The training loop you learned here is the single most important idea in this entire course. Every neural network, no matter how large or specialized, is trained by predicting, measuring the loss, backpropagating gradients, and stepping the optimizer. When you later type model.fit(...) and watch the loss fall, you will know precisely what those numbers mean and why they move.

Just as important, you saw that deep learning is a tool with trade-offs, not a guaranteed win. On a small, balanced dataset like the Indian IPOs, a modest network and honest evaluation will serve you far better than blindly stacking layers. That judgment, knowing when depth helps and when it just adds risk, is what separates someone who can run a framework from someone who can actually solve problems with it. The rest of this module builds both skills together.


Next Steps

You now understand the concepts behind deep learning and the loop that powers it. In the next lesson, you will get hands-on with the data structure everything runs on: tensors. You will learn how to create them, reshape them, and run the operations that make up a forward pass.

Continue to Lesson 2 - Introduction to TensorFlow Operations

Learn to create, reshape, and compute with tensors, the core data structure of TensorFlow.

Back to Module Overview

Return to the Deep Learning with TensorFlow module overview.


Keep Building Your Skills

You have taken your first step into deep learning with TensorFlow. The training loop you mapped out here, predict, measure, backpropagate, update, is the heartbeat of every neural network you will ever build. Hold on to that picture as you move through tensors, models, and training in the lessons ahead. Each new piece slots into the same loop, and the IPO problem keeps you grounded in a real question: will this offering list with a gain? Master the loop, and the framework becomes a tool you command rather than a mystery you operate.