[머신러닝] Linear Regression
2020. 7. 12. 13:52ㆍ머신러닝
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
dfLoad=pd.read_csv('https://sites.google.com/site/vlsicir/testData_LinearRegression.txt', sep="\s+");
xxRaw=dfLoad["xx"]
yyRaw=dfLoad["yy"]
plt.plot(xxRaw, yyRaw, "r. ")
N=len(xxRaw)
X=np.c_[np.ones([N, 1]), xxRaw]
y=np.array(yyRaw).reshape(N, 1)
wOLS=np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)
xSample=np.arange(0, 2, 0.01)
xSamplePadding=np.c_[np.ones([200, 1]), xSample]
yPredict=xSamplePadding.dot(wOLS)
plt.plot(xSample, yPredict, "b.-")
N_iteration=10
wGD=np.zeros([2,1])
eta=0.1
for iteration in range(N_iteration):
print(wGD)
gradients=-(2/N)*(X.T.dot(y-X.dot(wGD)))
wGD=wGD-eta*gradients
'머신러닝' 카테고리의 다른 글
[머신러닝] Classification2 - Clustering (0) | 2020.09.20 |
---|---|
[머신러닝] Classification1 - Mixture Model & Clustering (0) | 2020.08.25 |
[머신러닝] k-NN Classification (0) | 2020.07.26 |
[머신러닝] Logistic Regression (0) | 2020.07.18 |
[머신러닝] Python 선형대수학 numpy 사용 (0) | 2020.07.04 |