Self-Organizing Maps (SOM) problem in MATLAB

左心房为你撑大大i 提交于 2019-12-22 09:47:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!