MATLAB Answers

0

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

Rayan Fayad さんによって質問されました 2019 年 7 月 10 日
最新アクティビティ Divya Gaddipati さんによって 回答されました 2019 年 7 月 18 日
%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(:));

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Divya Gaddipati 2019 年 7 月 18 日

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:

  0 件のコメント

サインイン to comment.



Translated by