primalnearestneighbours.m.svn-base

来自「a function inside machine learning」· SVN-BASE 代码 · 共 36 行

SVN-BASE
36
字号
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 + =
减小字号Ctrl + -
显示快捷键?