lasso glm cvpartition error

조회 수: 1 (최근 30일)
V
V 2018년 8월 22일
댓글: James Gerber 2023년 11월 28일
Hello!
I am trying to run lassoglm with cv and I seem to receive the following error:
_Error using lassoglm>processLassoParameters (line 742) There are too few observations for crossvalidation. At least one training set has fewer than two observations.
Error in lassoglm (line 260) processLassoParameters(X,Y,pwts,alpha,nLambda,lambdaRatio,lambda,dfmax, ..._
I first run cvp = cvpartition(groups,'k',5), I also tried 2 and 3 folds Then I run [B, FitInfo] = lassoglm(X,Y,'binomial','CV',cvp); I have two groups(size(group1)= 54, size(group2)=78) Any help to troubleshoot this would be very much appreciated.
Many thanks, V

답변 (1개)

Amal George M
Amal George M 2018년 8월 31일
Hi V,
You encounter this message as the function needs partitions that match the total number of observations (after stripping NaNs and Infs and zero observation weights). Lassoglm ignores any rows which have at least one NaN or Inf values. Therefore, you end up with, a lesser number of observations. However, 'cvpartition' has already partitioned the original observations, which causes a mismatch in the number of observations and this error message.
Please try removing all the missing values (and the corresponding index from the response variable 'groups') before you pass the data to 'cvpartition'.
For example, you can remove all the rows which contain a NaN value by doing the following: >> idx2Remove = any(isnan(X), 2); >> X(idx2Remove, :)= []; >> groups(idx2Remove) = [];
  댓글 수: 2
Jason Climer
Jason Climer 2023년 7월 24일
This is a terrible error message for this problem. It's clear that the potential for an error was handled but the two causes of the error were lumped together on line 813 of lassoglm. This should be updated.
James Gerber
James Gerber 2023년 11월 28일
There is a similar problem in lasso.m on line 524 in R2023b with a misleading error message. There I got the error "There are too few observations for crossvalidation. At least one training set has fewer than two observations." and the reason was that there were a few zero weights.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Classification Ensembles에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by