作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
做的时候:
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/
做的时候: load training.mat training = G load testing.mat test = G 然后: >> knnclassify(test.Inp, training
我是一名优秀的程序员,十分优秀!