[Python] 8. Sigmoid & Logistic
import numpy as np import pandas as pd import matplotlib.pyplot as plt import math x = np.array( [1., 2., 3., 4., 5., 6.] ) y = np.array( [ 5., 7., 9., 11., 13., 15.] ) w = 0 b = 0 n = len(x) epochs = 5000 learning_rate = 0.01 for i in range(epochs): hy = w*x + b # w=2, b=3 cost = np.sum((hy-y)**2)/n gradientW = np.sum(2*x*(w*x+b-y))/n gradientB = np.sum(2*1*(w*x+b-y))/n w=w-learning_rate*gradie..
[Python] 4. 회귀 : cost(mse) test, gradient, scipy.stats 예제
import numpy as np import pandas as pd import matplotlib.pyplot as plt import scipy.stats as st cost(MSE) test def cost(x,y,w): c=0 for i in np.arange(len(x)): hx = w*x[i] c = c+(hx-y[i])**2 return c/len(x) x_data = [1,2,3] y_data = [1,2,3] print(cost(x_data,y_data,-1)) print(cost(x_data,y_data,0)) print(cost(x_data,y_data,1)) print(cost(x_data,y_data,2)) print(cost(x_data,y_data,3)) [OUT] : 18...