Skip to content

Instantly share code, notes, and snippets.

View antondevv's full-sized avatar

Anton Franzen antondevv

View GitHub Profile
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")
weight,height
1,3
2,5
4,6
@antondevv
antondevv / cost_function
Last active September 22, 2021 12:41
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
@antondevv
antondevv / Initialise
Created September 22, 2021 13:09
initialise
m = 0
b = 0
Learning_rate = 0.00000005
cost = 0
times_to_iterate = 1000
@antondevv
antondevv / gradient_descent
Last active September 22, 2021 13:17
gradient_descent
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))
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()
@antondevv
antondevv / final_file
Last active September 22, 2021 13:52
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
@antondevv
antondevv / text.txt
Last active November 3, 2021 09:59
sample text
What a beautiful day to be outside!
@antondevv
antondevv / clean.py
Created November 3, 2021 10:29
import
import string
import re
@antondevv
antondevv / punct.py
Last active November 3, 2021 10:35
remove punct
remove_punctuation = re.compile('[%s]' % re.escape(string.punctuation))
tokens = [remove_punctuation.sub('', w) for w in tokenized]