error for crossval function

5 views (last 30 days)
MiauMiau
MiauMiau on 22 Oct 2014
Commented: MiauMiau on 24 Oct 2014
Hi
I get an error for the following code:
esti = @(x,y)(lasso(x,y))
>> A = crossval(esti,training(:,end-1),training(:,end))
Error using crossval>evalFun (line 480) The function '@(x,y)(lasso(x,y))' generated the following error: Too many input arguments.
Error in crossval>getFuncVal (line 497) funResult = evalFun(funorStr,arg(:));
Error in crossval (line 343) funResult = getFuncVal(1, nData, cvp, data, funorStr, []);
why is that? feval works for the same arguments
  2 Comments
Geoff Hayes
Geoff Hayes on 22 Oct 2014
The error message is telling you that too many (more than two) input parameters are being passed to the esti function (which only allows for two inputs). Looking at the documentation for crossval, if the call is
vals = crossval(fun,X)
then fun is a function handle to a function with two inputs. The final example indicates that if the function call is
cfMat = crossval(f,X,y,...)
which is similar to yours, then the f must be a handle to a function that takes four inputs - the first two being the training subsets for X and Y, and the latter two for the test subsets of X and Y.
You will have to adjust your call to crossval to do something similar. What are you hoping to achieve by passing the two training inputs with the lasso function?
MiauMiau
MiauMiau on 24 Oct 2014
Well, I was doing the fitting with lasso function and wanted to perform then crossvalidation on my dataset. I understand now that I write a function which would take care of applying the fitting (lasso) to the data splited by crossval, so I wrote an anonymous function which I pass to the crossval, whereby the annonymous function now applies lasso to the splitted datasets and in my case returns the MSE. Thanks for your inputs!

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!