函数或变量 'knnclassify' 无法识别。
Show older comments
之前是matlab2016b,写的这个KNN,跑的没什么问题,中午重装matlab换成2019b了,同样的程序上午还在用,下午就不行了。
%数据集划分
flag=fix(0.8*n);
x_train=data(idx(1:flag),:);
y_train=label(idx(1:flag),:);
x_test=data(idx(flag+1:end),:);
y_test=label(idx(flag+1:end),:);
%knn分类
class = knnclassify(x_test, x_train, y_train,2);%k取2
acc=sum(class==y_test)/size(class,1);
plot(class,'k*');
hold on;
plot(y_test,'ro');
legend('预测值','实际值')
Accepted Answer
More Answers (0)
Categories
Find more on 最近邻 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!