{{ message }}

Instantly share code, notes, and snippets.

MyRibbonApps

Last active Sep 22, 2021
final_file
View final_file
 import pandas as pd import matplotlib.pyplot as plt import numpy as np data = pd.read_csv('data.csv') # print(data) def cost_function(m, b, points): the_total_error = 0 sum_error = 0
Created Sep 22, 2021
View gist:aa7b173eb0a7a29b9777cd757f596104
 for i in range(times_to_iterate): m, b = gradient_descent(m, b, data, Learning_rate) plt.scatter(data['weight'], data['height']) plt.plot(list(range(0, 5)), [m * x + b for x in range(0 , 5)], color="red") plt.show()
Last active Sep 22, 2021
 def gradient_descent(m_now, b_now, points, L): the_slope_of_thecost_depending_on_m = 0 the_slope_of_thecost_depending_on_b = 0 n = len(points) for i in range(n): x = points.iloc[i].weight y = points.iloc[i].height the_slope_of_thecost_depending_on_m += - (2/n) * x * (y - (m_now * x + b_now))
Created Sep 22, 2021
initialise
View Initialise
 m = 0 b = 0 Learning_rate = 0.00000005 cost = 0 times_to_iterate = 1000
Last active Sep 22, 2021
cost_function
View cost_function
 def cost_function(m, b, points): the_total_error = 0 sum_error = 0 for i in range(len(points)): x = points.iloc[i].weight y = points.iloc[i].height the_total_error += (y - (m * x + b)) ** 2 sum_error += the_total_error print(sum_error) return sum_error
Created Sep 22, 2021
data.csv
View gist:57ba4057f5ff45a15c6193794fd0223f
 weight,height 1,3 2,5 4,6
Created Sep 22, 2021
first part
View gist:1187df57b8d7c0aa8ef3f53b44b25444
 import matplotlib.pyplot as plt import pandas as pd import numpy as np #Print our data data = pd.read_csv('data.csv') print(data) plt.scatter(data['weight'], data['height']) plt.xlabel("Weight")