本文主要向大家介绍了机器学习入门之菜鸟之路——机器学习之非线性回归个人理解及python实现,通过具体的内容向大家展现,希望对大家学习机器学习入门有所帮助。
梯度下降:就是让数据顺着梯度最大的方向,也就是函数导数最大的放下下降,使其快速的接近结果。
Cost函数等公式太长,不在这打了。网上多得是。
这个非线性回归说白了就是缩小版的神经网络。
python实现:
1 import numpy as np
2 import random
3
4 def graientDescent(x,y,theta,alpha,m,numIterations):#梯度下降算法
5 xTrain =x.transpose()
6 for i in range(0,numIterations):#重复多少次
7 hypothesis=np.dot(x,theta) #h函数
8 loss=hypothesis-y
9
10 cost=np.sum(loss**2) / (2*m)
11 print("Iteration %d / cost:%f"%(i,cost))
12 graient=np.dot(xTrain,loss)/m
13 theta=theta-alpha*graient
14 return theta
15
16 def getData(numPoints,bias,variance):#自己生成待处理数据
17 x=n