How do i use sequentialfs in matlab when using neural networks (patternnet) as a model?

1 view (last 30 days)
%after loading the data
c = cvpartition(y,'k',10);
opts = statset('display','iter');
classf = @(xtrain,ytrain,xtest,ytest)sum(classify(ytest,xtest,train(ytrain,xtrain)) ~= ytest);
[fs,history] = sequentialfs(classf,PD_Inputs,y,'cv',c,'options',opts)
Its not working and im getting this error:
Error using crossval>evalFun (line 480)
The function
'@(xtrain,ytrain,xtest,ytest)sum(classify(ytest,xtest,train(ytrain,xtrain))~=ytest)' generated
the following error:
Undefined function 'train' for input arguments of type 'double'.
Error in crossval>getFuncVal (line 497)
funResult = evalFun(funorStr,arg(:));

Answers (1)

Divya Gaddipati
Divya Gaddipati on 18 Jul 2019
Hi,
classf = @(xtrain,ytrain,xtest,ytest) sum(classify(ytest,xtest,train(ytrain,xtrain)) ~= ytest);
In the above declaration, you used the classify function from the Statistics and Machine Learning Toolbox which is https://www.mathworks.com/help/stats/classify.html
Since, you want to use a neural network, you should be using the classify and train functions from the Deep Learning Toolbox. The train function outputs the trained shallow neural network. The classify function returns the predicted labels and scores (if required).
For more information on how to use these functions, you can refer to the following links:
Also, since you want to use patternnet, one possible modification which can be made to your code is:
classf = @(xtrain, ytrain, xtest, ytest)
sum(classify(train(patternnet(50), xtrain, ytrain), xtest) ~= ytest);
You can also use the trainNetwork function which allows you to model your own deep neural networks or load any pre-trained network. For more information, you can refer to the following link:

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!