// Update offsets and weights using reweightFunc val newInstances = instances.map { instance => val (newOffset, newWeight) = reweightFunc(instance, oldModel) Instance(newOffset, newWeight, instance.features) }
这里使用reweightFunc方法更新权重。具体的实现在广义线性回归的实现中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/** * The reweight function used to update offsets and weights * at each iteration of [[IterativelyReweightedLeastSquares]]. */ val reweightFunc: (Instance, WeightedLeastSquaresModel) => (Double, Double) = { (instance: Instance, model: WeightedLeastSquaresModel) => { val eta = model.predict(instance.features) val mu = fitted(eta) val offset = eta + (instance.label - mu) * link.deriv(mu) val weight = instance.weight / (math.pow(this.link.deriv(mu), 2.0) * family.variance(mu)) (offset, weight) } }