Created
June 16, 2020 12:42
-
-
Save ocakhasan/ad7829420efa33c086c9a85673fd2bca to your computer and use it in GitHub Desktop.
This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
def hypothesis(x, θ): | |
hypothesis = np.matmul(θ.T, x) | |
return hypothesis | |
def loss_function(h_x, y): | |
loss_error = 1 /2 *(h_x - y) *(h_x - y) | |
return loss_error | |
def update_parameters(THETA, hypothesis, x, y, learning_rate): | |
x = np.reshape(x, THETA.shape) | |
Updated_THETA = THETA - learning_rate *(hypothesis - y) *x | |
return Updated_THETA | |
df = pd.read_csv("output.csv") | |
X = df['X'] | |
y = df['y'] | |
X = np.array([[i] for i in X]) | |
xzeros = np.ones([X.shape[0], 1], dtype=X.dtype) | |
X = np.concatenate((xzeros, X), axis=1) | |
#THETA nın ilk değerleri sıfır olmalı. Daha sonra bunları güncelleyeceğiz | |
THETA = np.zeros([2, 1], dtype=np.float32) | |
#Öğrenme hızı | |
learning_rate = 0.01 | |
for x, y in zip(X, y): | |
#Bir tahmin yap | |
hypothesis_x = hypothesis(x, THETA) | |
#Hatanı ölç | |
loss = loss_function(hypothesis_x, y) | |
#Parametreleri güncelle | |
THETA = update_parameters(THETA, hypothesis_x, x, y, learning_rate) | |
print(THETA) #Output [[44.56747853], [18.34766775]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment