Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self-Organizing Maps (SOM) problem in MATLAB

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'.

like image 745
Serdar Demir Avatar asked Dec 15 '25 10:12

Serdar Demir


1 Answers

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)

alt text alt text

like image 99
Amro Avatar answered Dec 17 '25 00:12

Amro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!