MATLAB Answers

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

7 ビュー (過去 30 日間)
Rayan Fayad
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 件のコメント

サインインしてコメントする。

回答 (1 件)

Divya Gaddipati
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 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by