Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
liakdimi1 committed Jul 22, 2023
1 parent 5aefc00 commit 51c8190
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions machine_learning/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
import numpy as np
import requests
import matplotlib.pyplot as plt


def collect_dataset():
Expand Down Expand Up @@ -41,7 +42,6 @@ def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):
curr_features - alpha_ * gradient(w.r.t. feature)
"""
n = len_data

prod = np.dot(theta, data_x.transpose())
prod -= data_y.transpose()
sum_grad = np.dot(prod, data_x)
Expand Down Expand Up @@ -70,8 +70,8 @@ def run_linear_regression(data_x, data_y):
:param data_y : contains the output (result vector)
:return : feature for line of best fit (Feature vector)
"""
iterations = 100000
alpha = 0.0001550
iterations = 250000
alpha = 0.000326

no_features = data_x.shape[1]
len_data = data_x.shape[0] - 1
Expand Down Expand Up @@ -99,7 +99,7 @@ def mean_absolute_error(predicted_y, original_y):
def main():
"""Driver function"""
data = collect_dataset()

len_data = data.shape[0]
data_x = np.c_[np.ones(len_data), data[:, :-1]].astype(float)
data_y = data[:, -1].astype(float)
Expand All @@ -110,6 +110,5 @@ def main():
for i in range(0, len_result):
print(f"{theta[0, i]:.5f}")


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions machine_learning/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plt.axline(xy1=(0, reg.intercept_), slope=reg.coef_[0], color="blue", label="Sklearn")

0 comments on commit 51c8190

Please sign in to comment.