ml/sgd-linear-model.js
function regularizeL2(weights, gradientCount, stepSize, regParam) {
  const [gradient, count] = gradientCount;

  for (let i = 0; i < gradient.length; i++) {
    let grad = (gradient[i] || 0) / count;
    weights[i] = weights[i] || 0;
    weights[i] -= stepSize * (grad + regParam * weights[i]);
  }
}
function regularizeL2(weights, gradientCount, stepSize, regParam) {
  const [gradient, count] = gradientCount;

  for (let i = 0; i < gradient.length; i++) {
    let grad = (gradient[i] || 0) / count;
    weights[i] = weights[i] || 0;
    weights[i] -= stepSize * (grad + regParam * weights[i]);
  }
}
function regularizeL2 ( weights , gradientCount , stepSize , regParam ) { const [ gradient , count ] = gradientCount ; for ( let i = 0 ; i < gradient . length ; i ++ ) { let grad = ( gradient [ i ] || 0 ) / count ; weights [ i ] = weights [ i ] || 0 ; weights [ i ] -= stepSize * ( grad + regParam * weights [ i ] ) ; } }
L2, a.k.a ridge regression
L2 a . k . a ridge regression