We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/** * @param {[xi:number,yi:number][]} dataArr */ function start(dataArr) { //线性函数模板 const yFn = (w,b,x) => w * x + b // 样本数量 const m = dataArr.length /** * 损失函数 J * @param {number} w * @param {number} b */ const J = (w,b) => dataArr.reduce((t,[xi,yi]) => t + (yFn(w,b,xi) - yi) ** 2,0) / (m * 2) // 获取 w,b关于 损失函数J的 导数 const get_dj_wb = (w,b) => dataArr.reduce((t,[xi,yi],i) => { t.dj_dw += (yFn(w,b,xi) - yi) * xi t.dj_db += (yFn(w,b,xi) - yi) if (i + 1 === m) { t.dj_dw /= m t.dj_db /= m } return t },{ dj_dw: 0,dj_db: 0 }) //初始参数 w ,b let w = 0,b = 0 // 学习率 let L = 0.01 //开始训练 for (let i = 0; i < 10; i++) { let sun_shi = J(w,b) console.log('sun_shi',sun_shi) console.log('w',w) console.log('b',b) let { dj_dw,dj_db } = get_dj_wb(w,b) w = w - L * dj_dw b = b - L * dj_db } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
请问一下,为啥我的训练损失值不对呢,越来越大,是不是哪里有问题
The text was updated successfully, but these errors were encountered: