gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 20:15:06 28 4
gpt4 key购买 nike

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

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);

错误代码:

??? Undefined function or method 'plotsomplanes' for input arguments of type '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'

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

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

关于matlab - MATLAB 中的自组织映射 (SOM) 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4578473/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com