简体   繁体   中英

Regularization of Logistic Regression coefficients in MATLAB

I'm trying to implement a Logistic Regression with regularization (either L1 or L2). The mnrfit() function does not implement regularization. Is there any built-in function that can do the regularization or do I have to roll my own regularization code? If so, are there any tutorials that I can look at? The papers I have been looking at are rather mathematically dense.

Liblinear was the standard we used.

http://www.csie.ntu.edu.tw/~cjlin/liblinear/

L1 as well as L2 regularization are very easy to implement.

L1 regularization works by subtracting a fixed amount of the absolute value of your weights after each training step. So with an L1 regularization coefficient of eg 0.01, your weights (1.0, -2.0, 3.0) would become (0.99, -1.99, 2.99).

L2 regularization works by subtracting a percentage of your weights. With a coefficient of 0.01, this means multiplying your weight vector by 1. - 0.01 = 0.99. The weights (1.0, -2.0, 3.0) would become (0.99, -1.98, 2.97). This is also known as weight decay .

As you can see, L1 regularization pulls small weights towards 0. L2 regularization on the other side has almost no effect on small weights but drastically reduces large weights.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM