This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| weight,height | |
| 1,3 | |
| 2,5 | |
| 4,6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| m = 0 | |
| b = 0 | |
| Learning_rate = 0.00000005 | |
| cost = 0 | |
| times_to_iterate = 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| What a beautiful day to be outside! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string | |
| import re |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| remove_punctuation = re.compile('[%s]' % re.escape(string.punctuation)) | |
| tokens = [remove_punctuation.sub('', w) for w in tokenized] |
OlderNewer