Cross validated penalized logistic regression - one standard deviation rule I am new to this topic and would like to understand it better. I want to build a binary classifier based on penalized logistic regression. I have 10 features and 23 observations: 16 from class "0" and 7 from the second class "1" (yes, it is pretty unbalanced). I work with matlab and I used the following code to learn the classifier:
>> [B,FitInfo] = lassoglm(X,y,'binomial','CV',5,'Weights',weightsFunc(y),'Options',opt)

with:
>> weightsFunc = @(y) 0.5*[ones(numel(find(~y)),1)/numel(find(~y));
   ones(numel(find(y)),1)/numel(find(y))]

which computes weights of each point (due to unbalanced data sets). 
X is the design matrix 23x10 and y - vector of zeros and ones.
The problem is how to interpret and understand the result. Cross validation does find the minimal value of lambda (green circle), but in order to select the relevant features, we should use the "one standard deviation" rule and this rule gives all coefficients are zero (blue circle).

Questions: 


*

*How to work with unbalanced data sets? Is my procedure correct (by assigning weights to observations)? I tried to oversample the class with less observations (simply by doubling the observations), but it produces slightly different result.

*How to select features after the penalization, if one-std rule penalizes everything?
 A: The problem here isn't balance, it's sample size: you have 27 observations. The deviance statistic, shown in your figure, is insensitive to class composition issues. You'll need much more data to build a useful classifier. Your questions are focused on the wrong issue, because there's just nothing that you can meaningfully do with $n=27$ data in this context -- cross-validation is a data-intensive process.
A: To expand a bit on the fine answer from @user777, with respect to both the present data set and the broader conceptual question:
First, one good way to think about why LASSO penalized all your variables in this case is that you did not have enough data points to justify any regression model at all. In that respect, the LASSO did what it was supposed to. With only 7 cases in your least prevalent class, it prevented you from building an over-fit model that would be unlikely to generalize beyond this particular data set. The rule of thumb about 10 cases of the least-prevalent class per independent variable in logistic regression isn't based on cross-validation requirements, as your comment might seem to suggest. It's a first line of defense against over-fitting. 
I'm not convinced that you need to apply any special procedures to deal with imbalance between the classes here, particularly with only about a 2:1 class-membership ratio and if you expect that this data sample fairly represents the underlying population.
Second, more generally, it's not clear that there is a solid theoretical reason for the one-standard-deviation rule. It seems more to be a useful heuristic tool for cutting down a very large number of potential predictor variables into a manageable number. It's certainly harder to explain to someone else than is basing the choice of penalty on the minimization of cross-validation error.
Third, with a moderate number of potential predictor variables as in this case, you might consider ridge regression rather than LASSO as the penalization method. LASSO, like all variable-selection techniques, can lead to unstable choices of variables, highly dependent on the data sample, when predictor variables are correlated. Ridge regression maintains all predictor variables, tending to keep correlated variables together while penalizing coefficients to minimize overfitting. It's probably more useful if your main interest is in prediction. Or if you do need to do some variable selection, consider the hybrid elastic net.
If you haven't already, read some useful texts on regression modeling, like Harrell's Regression Modeling Strategies or An Introduction to Statistical Learning for more detailed information.
