1 %> @brief Lasso Classifier
3 %> This is a 2-
class classifier, won't work if dataset has more than two classes.
5 %> This classifier cannot correct
for weights either, so
if the dataset is unbalanced, it is better to undersample the dataset to balance the classes
7 %> This classifier uses a LASSO
function that has no
"intercept" in it, it assumes that the variables have been mean-centered, so the variables need to be
8 %> mean-centered. Standardization is actually recommended!
10 %> In order to use with more than two classes, please encapsulate inside an
aggr_pairs
13 %> Number of features to have non-zero coefficient
17 precond_threshold = 0;
18 precond_no_factors = 10;
21 properties(SetAccess=
protected)
22 %> Regression coefficients
28 o.classtitle = 'LASSO';
33 methods(Access=protected)
35 function o = do_boot(o)
40 % TODO actually this could even be multiple-trainable
41 function o = do_train(o, data)
42 o.classlabels = data.classlabels;
46 % ww = data.get_weights(); % weights per class
47 % weights = zeros(1, data.no); % weights per observation
50 % weights(data.classes == i-1) = ww(i);
55 irerror('Lasso classifier works with two classes only!');
65 % Univariate regression
66 a = zeros(data.nf, 1);
72 % Excludes features corresponding to small threshold
74 ii(a < o.precond_threshold) = [];
77 % PCA of reduced matrix
79 S = S(:, 1:min(o.precond_no_factors, size(S, 2)));
85 % Least-squares regression to
finally compute the Y
for the Lasso
86 Y = S*((S
'*S)\(S'*Y));
92 o.L = lasso(data.X, Y, -o.nf_select,
false);
100 function est = do_use(o, data)
102 est.classlabels = o.classlabels;
103 est = est.copy_from_data(data);
107 Y = data.X*o.L; % regression in action
108 Y(Y < -1) = -1; % Contains estimations between -1 ...
109 Y(Y > 1) = 1; % ... and 1
110 Y = Y/2+0.5; % normalizes to 0-1 instead
112 Y = [1-Y, Y]; % makes matrix of posterior probabilities for a 2-class classifier
function assert_meancentered(in X, in tolerance)
Dataset representing estimation.