[머신러닝] Logistic Regression
2020. 7. 18. 15:58ㆍ머신러닝
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
dfLoad=pd.read_csv('https://sites.google.com/site/vlsicir/testData_workHour_vs_passFail.txt', sep="\s+");
xxRaw=np.array(dfLoad.values[:,0])
yyRaw=np.array(dfLoad.values[:,1])
plt.plot(xxRaw, yyRaw, "k.")
def sigmoid(x):
return 1.0/(1+np.exp(-x))
#xxTest=np.linspace(-10, 10, num=101)
#plt.plot(xxTest, sigmoid(xxTest), "k-")
N=len(xxRaw)
x_bias=np.c_[np.ones([N, 1]), xxRaw]
y=yyRaw.reshape(N, 1)
X=x_bias.T
eta=0.1
N_iterations=1000
wGD=np.zeros([2, 1])
wGDbuffer=np.zeros([2, N_iterations+1])
for iteration in range(N_iterations):
mu=sigmoid(wGD.T.dot(X)).T
gradients=x_bias.T.dot(mu-y)
wGD=wGD-eta*gradients
wGDbuffer[:,iteration+1]=[wGD[0], wGD[1]]
xxTest=np.linspace(0, 10, num=N).reshape(N, 1)
xxTest_bias=np.c_[np.ones([N, 1]), xxTest]
aaa=sigmoid(wGD.T.dot(xxTest_bias.T))
plt.plot(xxTest, sigmoid(wGD.T.dot(xxTest_bias.T)).T, "r-.")
'머신러닝' 카테고리의 다른 글
[머신러닝] Classification2 - Clustering (0) | 2020.09.20 |
---|---|
[머신러닝] Classification1 - Mixture Model & Clustering (0) | 2020.08.25 |
[머신러닝] k-NN Classification (0) | 2020.07.26 |
[머신러닝] Linear Regression (0) | 2020.07.12 |
[머신러닝] Python 선형대수학 numpy 사용 (0) | 2020.07.04 |