2

我对下面的代码有一个小问题,最后一行是具体的,我试图找到我的“样本”的类名,我的意思是我需要知道哪个正常和哪个蓝精灵属于我的 1000x6 样本的每一行.

%% sampling
normIdx = strmatch('normal.', Book2);
normalSubset = fulldata(normIdx, :);
normal = randperm(size(normalSubset , 1));
p = (normal(1:750)-1)';

%
smurfIdx = strmatch('smurf.', Book2);
smurfSubset = fulldata(smurfIdx, :);
smurf = randperm(size(smurfSubset , 1));
a = (smurf(1:250)-1)';

%
normalSample = normalSubset (p, :);
smurfSample = smurfSubset (a, :);

%
sample = [normalSample ; smurfSample]

%
sample = sample(randperm(1000),:);

%
idx = [a ; p];
K1 = Book2(idx (sample==1), :)

K1 应该等于 1000 个样本类标签,其中 750 个应该是正常的,250 个应该是 smurf,它们应该与样本中的同一行完全对应。Book2 包含类标签,我也有从中派生样本的完整数据。

Atm K1 导致:

Index exceeds matrix dimensions

可能有一种简单的方法可以将样本数据与 fulldata 中的数据相匹配,但我不确定 fulldata 中是否可能存在重复数据......所以匹配失败了,因为sample是随机的,所以我不知道是什么我可以将类标签与采样相匹配。

4

1 回答 1

1

你是这个意思吗?:

%
shuffle = randperm(1000);
sample = sample(shuffle,:);

%
idx = [a ; p];
K1 = Book2(idx (shuffle), :);
于 2012-11-16T09:59:47.343 回答