问题
I know there is an weighted OLS solver, and a constrained OLS solver.
Is there a routine that combines the two?
回答1:
You can simulate OLS weighting by modifying the X and y inputs. In OLS, you solve β for
XtX β = Xty.
In Weighted OLS, you solve
XtX W β = Xt W y.
where W is a diagonal matrix with nonnegative entries. It follows that W0.5 exists, and you can formulate this as
(X W0.5)t(XW0.5) β = (X W0.5)t(XW0.5) y,
which is an OLS problem with X W0.5 and W0.5 y.
Consequently, by modifying the inputs, you can use a non-negative constraint system which does not directly recognize weights.
来源:https://stackoverflow.com/questions/36112290/weighted-non-negative-least-square-linear-regression-in-python