3) Create a user-defined function for the given Python program. Import data into Python from filename.csv. Use the same parameters and variables as defined in the following Python programs. Run your programs.
3-Gradient descent method error_sq_list = Loss mean square error list
bob1 = 0.0 # Initialization of the parameters
alpha = 10e-1 # Learning rate
num_iterations = 100 # Number of iterations/replications
len_samples = len(sales) # Number of samples
m_samples = range(len_samples) # List of samples index
count = 0
while count < num_iterations:
dbO.db1 = 0.0 # The derivative of the parameters with respect to the loss function
L = du/db # error_sq = 0 # errorsq = predicted sales - actual sales)^2
for i in samples:
predict_minus_actual = predict_sales[i]
dbO += predict_minus_actual
db1 += predict_minus_actual * tv_ad[i]
error_sq = predict_minus_actual^2 # Compute square error and accumulate
bO = bO - alpha * dbO / len_samples
b1 = b1 - alpha * db1 / len_samples
error_sq_list.append((error_sq / len_samples)
count += 1
print("Gradient Descent Method: sales = round(b0, 3, round(b1, 3)).tv_ad")