How do i fix error : 'model' parameter must be a character vector?

82 次查看(过去 30 天)
Hi everyone, sorry for asking this silly question. since i'm really new in nn matlab, i'm having difficulties to implement nn in matlab. so that you all can understand the bigger picture of what trouble i might have come across, i'm gonna give it in details.
first that i have data in xls document, each xls document contain 24 rows of data with 3 parameters (perimeter, diameter and area) of fruit database. this data is already a post-processed image (from preprocessing i saved the data in excel). then i normalized the data,
data1 = data1';
max_data = max(max(data1));
min_data = min(min(data1));
[m,n] = size(data1);
data_norm = zeros(m,n);
for x = 1:m
for y = 1:n
data_norm(x,y) = 0.1+0.8*(data1(x,y)-min_data)/(max_data-min_data);
end
end
afterward i use patternnet to train my data so that it can identify what kind of fruit i input to the gui system. it roughly like this :
net.trainFcn = 'trainlm';
net = patternnet(100, 'trainlm');
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-5;
net.divideFcn = 'dividerand'; % num of data that'll be divide
net.divideParam.trainRatio = 70/100; % training set
net.divideParam.valRatio = 15/100; % validation set
net.divideParam.testRatio = 15/100; % testing set
net = init(net);
[net,tr] = train(net, data_norm,group);
y = sim(net, data_norm);
....
%then classification from input and net to get classification fruit class...
....
result = round(sim(y,sample));
....
switch result
case 0
class='Firm';
case 1
class='Ripe';
case 2
class='Overripe';
end
so, i assume that from normalising the data, making the shape of the data change. How do i fix this? i search it online on MATLABanswers forum and someone have the same problem (not really the same) and the suggestion is this
but when i try it, my nn doesn't want to run and didn't display the nntraintool. What should i do to fix it?

采纳的回答

Walter Roberson
Walter Roberson 2019-8-16
[net,tr] = train(net, data_norm,group);
y = sim(net, data_norm);
y is going to be numeric and the same size as group
result = round(sim(y,sample));
There you are sim() on that numeric value. You need to sim() on a network.
You do not need to sim() on the original data unless you want to cross-check the accuracy of the network. The train() call already returns a network that knows the (approximate) classification rules, so you would
result = round(sim(net,sample));
  1 个评论
Bonaventura Sanjoyo
thank you for the reply, but i've tried it numerous time and it's still not working.
the error line shows input and also the parameter have diferent matrix forms if i changed the code and compile it from :
result = round(sim(y,sample));
to :
result = round(sim(net,sample));
is it because i put the class in the same data matrix excel sheet too?
if you want to know my data format, it'd be :
Number Picture files name Perimeter Diameter Areas (additional from myself)Class
1 fruits.jpg (number of pixels from post- 0
... image processing)
24 2
should i delete the additional class information in my data excel sheets? since i'm calling the classes using this command
group = data(:,4);

请先登录,再进行评论。

更多回答(1 个)

Xin Yee Tai
Xin Yee Tai 2020-8-12
Instead of 'sim', please try 'predict'.
Hope it helps!
  3 个评论
Xin Yee Tai
Xin Yee Tai 2020-8-12
Hi, thanks for correcting me. Could you please explain more about the different use between sim and predict? Thank you !

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by