MATLAB中的自组织映射(SOM)问题

时间:2011-01-02 13:02:30

标签: matlab machine-learning som self-organizing-maps

我有一个包含数据的文本文件。 我的文字文件:

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

我读了我的文本文件加载方法

%young=1
%myopic=2
%no=3 etc.

load iris.txt
net = newsom(1,[1 5]);
[net,tr] = train(net,1);
plotsomplanes(net);

错误代码:

  

???未定义的功能或方法   ' plotsomplanes'输入参数   键入' network'。

1 个答案:

答案 0 :(得分:8)

鉴于您正在显示的文本文件,LOAD功能将无法正常工作。您应该使用TEXTSCAN来解析文本文件。然后我使用GRP2IDX将名义数据转换为数字属性(它将为每个属性值分配1,2,3,..)。在这种情况下,数据变为:

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

我应该提一下,你可能需要一个更大的数据集(更多实例)来获得任何有意义的结果......

%# 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