What does the value supplied to the Predict
Method
option "L2Regularization"
correspond to?
It does not seem to correspond to the conventional definition of $\lambda$ in the context of linear regression:
$$J(\mathbf{w})= \text{MSE}(\mathbf{w})+\lambda \mathbf{w}^{T}\cdot\mathbf{w}$$
For example
Predict[dmat -> y, Method->{"LinearRegression", "L2Regularization"->lambda}, PerformanceGoal->"Quality"]
does not produce the same predictions as a function generated from
Minimize[Mean[(dmat.w-y)^2] + lambda*w.w, w]
unless there's no regularization (lambda = 0
).
Moreover, I can't see how to use Predict
with "L2Regularization"
to regularize only weights, but not bias (as is common on NN applications), as in
p=Prepend[w, b];
Minimize[Mean[(dmat.p-y)^2] + lambda*w.w, p]
where dmat
is of the form DesignMatrix[...,IncludeConstantBasis->True]
.
What value should I use for "L2Regularization"
to match the effect of lambda
? What options or other changes do I need to make to have Predict
only regularize weights?
(*
Generate things for an MWE
*)
x = Partition[ RandomReal[{0,10},200], 2];
f = #1-4#2+2*#1^3-50*#1 Sin[#1]Cos[#2]&;
y = MapThread[f ][Transpose@x]+RandomReal[{-400,400},Length@x];
basisFuncs = {1, x1, x2, x1^2, x2^2, x1^4, x2^4, x1^5, x2^5,x1 Sin[x1]Cos[x2]};
weights = Symbol/@(ToString[StringForm["w``",#]]&/@Range[Length[basisFuncs]-1]);
bias = Symbol@"b";
params = Prepend[weights,bias];
dmat = DesignMatrix[MapThread[Append,{x, y}],basisFuncs, {x1, x2},IncludeConstantBasis->False];
(*
With no regularization, the fit matches, though the Predict soluton has an extra, near-zero term that appears to be a side effect of the biases column in dmat.
*)
lambda=0;
Minimize[Mean[(dmat.params-y)^2] + lambda*weights.weights,params][[2]]
PredictorInformation[Predict[dmat->y,Method->{"LinearRegression","L2Regularization"-> lambda}, PerformanceGoal->"Quality"],"Function"]
PredictorInformation[Predict[Rest/@dmat->y,Method->{"LinearRegression","L2Regularization"-> lambda}, PerformanceGoal->"Quality"],"Function"]
(*
With regularization, the fits don't match, even if all params are regularized.
*)
lambda=50;
Minimize[Mean[(dmat.params-y)^2] + lambda*weights.weights,params][[2]]
PredictorInformation[Predict[dmat->y,Method->{"LinearRegression","L2Regularization"-> lambda}, PerformanceGoal->"Quality"],"Function"]
PredictorInformation[Predict[Rest/@dmat->y,Method->{"LinearRegression","L2Regularization"-> lambda}, PerformanceGoal->"Quality"],"Function"]
Minimize[Mean[(dmat.params-y)^2] + lambda*params.params,params][[2]]
lambda = 0
,Predict
andMinimize
produce exactly the same results (as expected). Withlambda ≠ 0
Predict
andMinimize
give completely different results, suggesting that MMA's"L2Regularization"
parameter is something distinct from $\lambda$. The question is: what is it? $\endgroup$"L2Regularization"
clearly does not have this meaning. What does it mean? $\endgroup$But in MMA, "L2Regularization" clearly does not have this meaning. How clearly?
Maybe the L2Regularization works like Ridge or L2Regularizeation=f(lambda)?, but just the parameters scope is different from another implement? This is very normal in the ML packages. I even cann't produce your result ofMinimize[Mean[(dmat.w-y)^2]+lambda*w.w,w]
General::stop: Further output of NMinimize::nnum will be suppressed during this calculation.
$\endgroup$