Matlab 中的 crossval - Predfun 仅在参数为零时运行?

crossval in Matlab- Predfun only runs if it has zero arguments?

我正在尝试使用 Matlab 内置的 crossval 函数。我已设置逻辑回归函数并准备就绪,但我得到的行为不是我从文档中期望的。

来自Crossval documentation page,重载:

mse = crossval('mse',X,y,'Predfun',predfun)

似乎最符合我的需要。文件说

mse = crossval('mse',X,y,'Predfun',predfun) returns mse, a scalar containing a 10-fold cross validation estimate of mean-squared error for the function predfun. X can be a column vector, matrix, or array of predictors. y is a column vector of response values. X and y must have the same number of rows.

predfun is a function handle called with the training subset of X, the training subset of y, and the test subset of X as follows:

yfit = predfun(XTRAIN,ytrain,XTEST)

Each time it is called, predfun should use XTRAIN and ytrain to fit a regression model and then return fitted values in a column vector yfit. Each row of yfit contains the predicted values for the corresponding row of XTEST. crossval computes the squared errors between yfit and the corresponding response test set, and returns the overall mean across all test sets.

所以我在同目录的另一个文件中定义了一个函数,签名为:

function ytest = logRegTester(XTRAIN, ytrain, XTEST)

Matlab 给我错误

Error using logRegTester (line 11) Not enough input arguments.

为了进行实验,我尝试减少 logRegTester 预期的参数数量,发现 crossval 只有在参数为零时才会调用我的函数。这似乎与文档相矛盾,文档需要一个具有三个参数的函数。

请根据 predfun() 的要求使用 function handle @logRegTester 而不是直接使用 logRegTester。