日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

ML之UliR:利用非线性回归,梯度下降法(迭代十万次)求出学习参数θ,进而求得Cost函数最优值

發(fā)布時(shí)間:2025/3/21 68 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ML之UliR:利用非线性回归,梯度下降法(迭代十万次)求出学习参数θ,进而求得Cost函数最优值 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

ML之UliR:利用非線(xiàn)性回歸,梯度下降法(迭代十萬(wàn)次)求出學(xué)習(xí)參數(shù)θ,進(jìn)而求得Cost函數(shù)最優(yōu)值

?

?

目錄

輸出結(jié)果

代碼設(shè)計(jì)


?

?

輸出結(jié)果

更新……

?

代碼設(shè)計(jì)

import numpy as np import random def genData(numPoints,bias,variance): x = np.zeros(shape=(numPoints,2)) y = np.zeros(shape=(numPoints)) for i in range(0,numPoints): x[i][0]=1 x[i][1]=i y[i]=(i+bias)+random.uniform(0,1)%variance return x,ydef gradientDescent(x,y,theta,alpha,m,numIterations): xTran = np.transpose(x) for i in range(numIterations):hypothesis = np.dot(x,theta) loss = hypothesis-y cost = np.sum(loss**2)/(2*m) gradient=np.dot(xTran,loss)/mtheta = theta-alpha*gradient print ("Iteration %d | cost :%f" %(i,cost))return thetax,y = genData(100, 25, 10) #100行, print ("x:") print (x) print ("y:") print (y)m,n = np.shape(x) n_y = np.shape(y) print("m:"+str(m)+" n:"+str(n)+" n_y:"+str(n_y))numIterations = 100000 alpha = 0.0005 theta = np.ones(n) theta= gradientDescent(x, y, theta, alpha, m, numIterations) print(theta)

?

?

相關(guān)文章
ML之UliR:利用非線(xiàn)性回歸,梯度下降法(迭代十萬(wàn)次)求出學(xué)習(xí)參數(shù)θ,進(jìn)而求得Cost函數(shù)最優(yōu)值

?

?

?

總結(jié)

以上是生活随笔為你收集整理的ML之UliR:利用非线性回归,梯度下降法(迭代十万次)求出学习参数θ,进而求得Cost函数最优值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。