Adaptive linear neurons model 线性神经元 运用梯度下降法 进行代价函数的最优化

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

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值