Minimizing cost functions with gradient descent
【梯度下降法】
将平方误差的和作为代价函数J(w)( cost function )
利用梯度下降法最优化cost function
J(w)对于w求偏导:
=
所以 w更新为
代码中即 : self.w_[1:] += self.eta * (X.T).dot(y - output) output = X 点乘 W
权值w更新 = eta(learning rate ) * X点乘(y - X点乘W)
【python 实现 线性神经元】
源码 GIT地址:
【feature scaling 改善梯度下降法】
将数据进行标准化,变形为标准正态分布,使得梯度下降收敛更快
能够用较少的步数找到最优解(成本函数的最小值)
git地址 :https://github.com/xuman-Amy/Perceptron_python/blob/master/Adaline_python.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv("G:\Machine Learning\python machine learning\python machine learning code\code\ch02\iris.data",header = None)
# select setosa and versicolor
y = df.iloc[0:100, 4].values
y = np.where(y == 'Iris-setosa', -1, 1)
# extract sepal length and petal length
X = df.iloc[0:100, [0, 2]].values