⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primalnearestneighbours.m.svn-base

📁 a function inside machine learning
💻 SVN-BASE
字号:
function [trainInfo, testInfo, classifierInfo] = primalNearestNeighbours(trainX, trainY, testX, params); 
%A classifier based on the nearest neighbour algorithm 
%Inputs 
%trainX - the input training data 
%trainY - the input labels 
%testX - the test data 
%
%Outputs 
%predTrainY - the predicted training data labels 
%predTestY - the predicted test data labels 
%classifierInfo - statistics about the algorithm (currently, none) 

if nargin ~= 4
    fprintf('%s\n', help('primalNearestNeighbours'));
    error('Incorrect number of inputs - see above usage instructions.');
end

if ~binaryLabels(trainY) 
    error('Using primalNearestNeighbours with non binary labels'); 
end

if mod(params.k, 2) == 0 
    error('Number of neighbours k must be odd number'); 
end 

if size(trainY, 2) ~= 1 & params.k ~= 1 
    error('In multi label case can only work with k = 1'); 
end 

modelInfo = primalNearestNeighboursTrain(trainX, trainY, params); 
[trainInfo, trainPredictionInfo] = primalNearestNeighboursPredict(trainX, trainY, trainX, modelInfo, params); 
[testInfo, testPredictionInfo] = primalNearestNeighboursPredict(trainX, trainY, testX, modelInfo, params); 

classifierInfo = struct; 
classifierInfo.trainPredictionInfo = trainPredictionInfo; 
classifierInfo.testPredictionInfo = testPredictionInfo; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -