MATLAB - knnclassify 的用法

标签 matlab matrix machine-learning

做的时候:

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/

相关文章:

matlab - 如何在Matlab中输入数据?

matlab - 在 MATLAB 中计算分位数

c - 使用指针打印方阵

python - 执行矩阵乘法时出现内存错误

python - 多元线性回归中没有找到斜率和截距,nan值来了

r - Matlab 在 R 中的 sparse(i,j,s,m,n) 等价物

c++ - 如何使用 Matlab mex 输出二维整数数组?

c++ - OpenCV 快速垫元素​​和邻居访问

python - tensorflow 。值错误: The two structures don't have the same number of elements

machine-learning - SGD 型号 "overconfidence"