First Neural Network

Building your first neural network is an exciting step in your deep learning journey. In this lesson, you will learn how to create a simple neural network, train it on data, and evaluate its performance. This hands-on approach helps you understand how models learn patterns and make predictions.

What is a Neural Network?
A neural network is a computational model inspired by the human brain. It consists of layers of interconnected nodes (neurons):

  • Input Layer – Receives the data
  • Hidden Layers – Process and transform the data
  • Output Layer – Produces the final prediction

Steps to Build Your First Neural Network

  1. Define the problem and dataset
  2. Prepare and preprocess the data
  3. Build the model architecture
  4. Compile the model with optimizer and loss function
  5. Train the model on data
  6. Evaluate and test the model

Example: Simple Neural Network using Keras

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense# Sample dataset (features and labels)
X = [[0], [1], [2], [3], [4]]
y = [[0], [1], [2], [3], [4]]# Build the model
model = Sequential([
Dense(10, activation='relu', input_shape=(1,)),
Dense(1)
])# Compile the model
model.compile(optimizer='adam', loss='mean_squared_error')# Train the model
model.fit(X, y, epochs=100, verbose=0)# Make predictions
predictions = model.predict([[5]])
print(predictions)

Understanding the Code

  • Sequential Model: A linear stack of layers
  • Dense Layer: Fully connected layer where each neuron is connected to all inputs
  • Activation Function: Adds non-linearity (e.g., ReLU)
  • Optimizer: Updates weights to minimize loss (e.g., Adam)
  • Loss Function: Measures prediction error

Training the Model
During training:

  • The model makes predictions on input data
  • The error (loss) is calculated
  • Weights are updated using backpropagation
  • This process repeats over multiple epochs to improve accuracy

Evaluating the Model
After training, evaluate how well the model performs:

  • Compare predictions with actual values
  • Check loss and accuracy metrics
  • Test on new unseen data

Improving the Model
You can improve performance by:

  • Adding more layers or neurons
  • Increasing training epochs
  • Using better datasets
  • Tuning hyperparameters like learning rate and batch size

Applications

  • Predicting numerical values (regression)
  • Classifying data into categories
  • Recognizing patterns in images, text, and signals

Lesson Summary
In this lesson, you built your first neural network using Keras. You learned how to define a model, train it, make predictions, and improve its performance. This foundation prepares you for building more advanced deep learning models.

Home » Deep Learning Foundations (Beginner) > Deep Learning Frameworks > First Neural Network