Ser*_*mir 3 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
Run Code Online (Sandbox Code Playgroud)
我读了我的文本文件加载方法
%young=1
%myopic=2
%no=3 etc.
load iris.txt
net = newsom(1,[1 5]);
[net,tr] = train(net,1);
plotsomplanes(net);
Run Code Online (Sandbox Code Playgroud)
错误代码:
??? 未定义的函数或方法'plotsomplanes'用于'network'类型的输入参数.
给定您正在显示的文本文件,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'
Run Code Online (Sandbox Code Playgroud)
我应该提一下,你可能需要一个更大的数据集(更多实例)来获得任何有意义的结果......
%# 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)
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
3145 次 |
| 最近记录: |