gpt4 book ai didi

MATLAB - knnclassify 的用法

转载 作者:行者123 更新时间:2023-11-30 08:41:57 24 4
gpt4 key购买 nike

做的时候:

load training.mat
training = G

load testing.mat
test = G

然后:

>> knnclassify(test.Inp, training.Inp, training.Ltr)

??? Error using ==> knnclassify at 91
The length of GROUP must equal the number of rows in TRAINING.

自:

>> size(training.Inp)
ans =
40 40 2016

还有:

>> length(training.Ltr)
ans =
2016

如何为 knnclassify(训练)training.inp 3-D 矩阵提供第二个参数,以便行数为 2016(第三维)?

最佳答案

假设您的 3D 数据被解释为 2016 年每个实例(第三维)的 40×40 特征矩阵,我们将不得不将其重新排列为大小为 2016×1600 的矩阵(行是样本,列是尺寸):

%# random data instead of the `load data.mat`
testing = rand(40,40,200);
training = rand(40,40,2016);
labels = randi(3, [2016 1]); %# a class label for each training instance
%# (out of 3 possible classes)

%# arrange data as a matrix whose rows are the instances,
%# and columns are the features
training = reshape(training, [40*40 2016])';
testing = reshape(testing, [40*40 200])';

%# k-nearest neighbor classification
prediction = knnclassify(testing, training, labels);

关于MATLAB - knnclassify 的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1903165/

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