Professional Documents
Culture Documents
Assignment 2
Assignment 2
Assignment#2
Implement GDA for fitting a line in a given dataset. Data is given in a text file. Program will
read data from the text file and fit a line to the data and display the data and line as a
graph. Bring your assignment in printed form.
import numpy as np
n = len(x)
for _ in range(num_iterations):
y_pred = m * x + b
m -= learning_rate * gradient_m
b -= learning_rate * gradient_b
return m, b
# Read data from the text file
x = data[:, 0]
y = data[:, 1]
# Hyperparameters
learning_rate = 0.01
num_iterations = 1000
y_line = m * x_line + b
plt.scatter(x, y, label='Data')
plt.xlabel('X')
plt.ylabel('Y')
plt.legend()
plt.grid(True)
plt.show()
# Print the fitted line equation