问题
I have a text file that include data. My text file:
young, myopic, no, reduced, no
young, myopic, no, normal, soft
young, myopic, yes, reduced, no
young, myopic, yes, normal, hard
young, hyperopia, no, reduced, no
young, hyperopia, no, normal, soft
young, hyperopia, yes, reduced, no
young, hyperopia, yes, normal, hard
I read my text file load method
%young=1
%myopic=2
%no=3 etc.
load iris.txt
net = newsom(1,[1 5]);
[net,tr] = train(net,1);
plotsomplanes(net);
Error code:
??? Undefined function or method 'plotsomplanes' for input arguments of type 'network'.
回答1:
Given the text file you're showing, the LOAD function will not work. You should use TEXTSCAN to parse the text file. I then use GRP2IDX to convert the nominal data into numeric attributes (it will assign 1,2,3,.. for each attribute values). In this case the data becomes:
>> data =
1 1 1 1 1
1 1 1 2 2
1 1 2 1 1
1 1 2 2 3
1 2 1 1 1
1 2 1 2 2
1 2 2 1 1
1 2 2 2 3
>> labels{:}
ans =
'young'
ans =
'myopic'
'hyperopia'
ans =
'no'
'yes'
ans =
'reduced'
'normal'
ans =
'no'
'soft'
'hard'
I should mention that you will probably need a much larger dataset (more instances) to get any meaningful results...
%# read text file
fid = fopen('iris.txt');
D = textscan(fid, '%s %s %s %s %s', 'Delimiter',',');
fclose(fid);
%# convert nominal to numeric
%#data = cell2mat( cellfun(@grp2idx, D, 'UniformOutput',false) );
data = zeros(numel(D{1}),numel(D));
labels = cell(size(D));
for i=1:numel(D)
[data(:,i) labels{i}] = grp2idx(D{i});
end
%# build SOM
net = newsom(data', [4 4]);
[net,tr] = train(net, data');
figure, plotsomhits(net, data')
figure, plotsomplanes(net)
来源:https://stackoverflow.com/questions/4578473/self-organizing-maps-som-problem-in-matlab