• 大小: 4KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: Matlab
  • 标签: KNN代码  

资源简介

Matlab代码,好用的KNN代码,直接用

资源截图

代码片段和文件信息

function rate = KNN(Train_dataTrain_labelTest_dataTest_labelkDistance_mark);
% K-Nearest-Neighbor classifier(K-NN classifier)
%Input:
%     Train_dataTest_data are training data set and test data
%     setrespectively.(Each row is a data point)
%     Train_labelTest_label are column vectors.They are labels of training
%     data set and test data setrespectively.
%     k is the number of nearest neighbors
%     Distance_mark           :   [‘Euclidean‘ ‘L2‘| ‘L1‘ | ‘Cos‘] 
%     ‘Cos‘ represents Cosine distance.
%Output:
%     rate:Accuracy of K-NN classifier
%
%    Examples:
%      
% %Classification problem with three classes
% A = rand(50300);
% B = rand(50300)+2;
% C = rand(50300)+3;
% % label vector for the three classes
% gnd = [ones(3001);2*ones(3001);3*ones(3001)];
% fea = [A B C]‘;
% trainIdx = [1:150301:450601:750]‘;
% testIdx = [151:300451:600751:900]‘;
% fea_Train = fea(trainIdx:);
% gnd_Train = gnd(trainIdx);
% fea_Test = fea(testIdx:);
% gnd_Test = gnd(testIdx);
% rate = KNN(fea_Traingnd_Trainfea_Testgnd_Test1)
%
%
%
%Reference:
%
% If you used my matlab code we appreciate it very much if you can cite our following papers:
% Jie Gui et al. “How to estimate the regularization parameter for spectral regression
% discriminant analysis and its kernel version?“ IEEE Transactions on Circuits and 
% Systems for Video Technology (Accepted)
% Jie Gui Zhenan Sun Wei Jia Rongxiang Hu Yingke Lei and Shuiwang Ji “Discriminant
% Sparse Neighborhood Preserving embedding for Face Recognition“ Pattern Recognition 
% vol. 45 no.8 pp. 2884–2893 2012 (SCI EI)
% Jie Gui Wei Jia Ling Zhu Shuling Wang and Deshuang Huang 
% “Locality Preserving Discriminant Projections for Face and Palmprint Recognition“ 
% Neurocomputing vol. 73 no.13-15 pp. 2696-2707 2010
% Jie Gui et al. “Semi-supervised learning with local and global consistency“ 
% International Journal of Computer Mathematics (Accepted)
% Jie Gui Shu-Lin Wang and Ying-ke Lei “Multi-step Dimensionality Reduction and 
% Semi-Supervised Graph-based Tumor Classification Using Gene expression 

评论

共有 条评论

相关资源