DeepLearningLab - Ipynb - Colab
DeepLearningLab - Ipynb - Colab
ipynb - Colab
keyboard_arrow_down Experiment 1
Creating a basic network and analyze its performance.
Objective:
To implement a basic linear regression model, analyze its performance, and evaluate its
effectiveness in predicting outcomes based on a given dataset.
Prerequisites:
Experimental Setup
Software Requirements:
Python (preferably version 3.x) Jupyter Notebook or any Python IDE (e.g., PyCharm, VS Code)
Required libraries: numpy, matplotlib, tensorflow
Hardware Requirements:
where:
Experimental Procedure
https://colab.research.google.com/drive/1byIFyWQqeZtED0Va9nTlHnrndYJ9J3Ai#printMode=true 1/6
4/22/25, 8:43 PM DeepLearningLab.ipynb - Colab
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
np.random.seed(42)
num_samples = 100 # Number of data points
x_train = np.random.rand(num_samples, 1) * 10 # Random X values between 0 and 10
y_train = 3 * x_train + 2 + np.random.randn(num_samples, 1) # Linear relation with noise
model = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(1,)) # Single neuron for regression
])
/usr/local/lib/python3.11/dist-packages/keras/src/layers/core/dense.py:87: UserWarnin
super().__init__(activity_regularizer=activity_regularizer, **kwargs)
https://colab.research.google.com/drive/1byIFyWQqeZtED0Va9nTlHnrndYJ9J3Ai#printMode=true 2/6
4/22/25, 8:43 PM DeepLearningLab.ipynb - Colab
plt.legend()
plt.show()
# Initialize parameters
m = 0 # Slope
b = 0 # Intercept
learning_rate = 0.1
epochs = 1000
n = len(X)
# Training loop
for epoch in range(epochs):
# Predictions
y_pred = m * X + b
https://colab.research.google.com/drive/1byIFyWQqeZtED0Va9nTlHnrndYJ9J3Ai#printMode=true 3/6
4/22/25, 8:43 PM DeepLearningLab.ipynb - Colab
# Compute cost
cost = compute_cost(y, y_pred)
# Compute gradients
dm = (-1 / n) * np.sum(X * (y - y_pred))
db = (-1 / n) * np.sum(y - y_pred)
# Update parameters
m -= learning_rate * dm
b -= learning_rate * db
# Final parameters
print(f"Final Parameters: Slope = {m:.2f}, Intercept = {b:.2f}")
https://colab.research.google.com/drive/1byIFyWQqeZtED0Va9nTlHnrndYJ9J3Ai#printMode=true 4/6
4/22/25, 8:43 PM DeepLearningLab.ipynb - Colab
Precautions:
Choose an appropriate learning rate: Too high leads to divergence, too low causes slow
learning.
Ensure data is normalized: Large feature values can lead to unstable training.
Sources of Error:
https://colab.research.google.com/drive/1byIFyWQqeZtED0Va9nTlHnrndYJ9J3Ai#printMode=true 5/6
4/22/25, 8:43 PM DeepLearningLab.ipynb - Colab
The loss function should decrease over epochs, showing successful training.
The final plot should show the neural network fitting the sine function.
The animation should display how the predictions evolve over time.
Short questions.
https://colab.research.google.com/drive/1byIFyWQqeZtED0Va9nTlHnrndYJ9J3Ai#printMode=true 6/6