This page contains an overview of Generalized Matrix Learning Vector Quantization (GMLVQ) and an example concerning the corresponding Matlab script.
With the Matlab script you can use the GLVQ variants Generalized Relevance LVQ (GRLVQ) and GMLVQ for classification, feature selection and linear dimensionality reduction.
function model = GMLVQ_train(trainSet, trainLab)
function [model,initialization,trainError,testError,costs] = GMLVQ_train(trainSet,trainLab,...
'PrototypesPerClass',2,'dim',2,'regularization',0)
load data/segment.dat;
data = segment(:,1:end-1);data(:,std(data)==0) = [];
label= segment(:,end);
indices = nFoldCrossValidation(data,'labels',label,'nb_samples',300,'nb_folds',1,...
'splits','random','comparable',1);
trainSet = data(indices{1},:);
trainLab = label(indices{1});
testIdx = 1:length(label);
testIdx(indices{1}) = [];
testSet = data(testIdx,:);
testLab = label(testIdx);
disp('preprocess the data using zscore');
[trainSet, zscore_model] = zscoreTransformation(trainSet);
testSet = zscoreTransformation(testSet, 'parameter', zscore_model);
GMLVQ_model = GMLVQ_train(trainSet, trainLab,'dim',18,'PrototypesPerClass',1);
GMLVQ_model_rank2 = GMLVQ_train(trainSet, trainLab,'dim',2,'PrototypesPerClass',[2,1,2,1,3,2,1]);
estimatedTrainLabels = GMLVQ_classify(trainSet, GMLVQ_model);
trainError = mean( trainLab ~= estimatedTrainLabels );
fprintf('GMLVQ: error on the train set: %f\n',trainError);
estimatedTestLabels = GMLVQ_classify(testSet, GMLVQ_model);
testError = mean( testLab ~= estimatedTestLabels );
fprintf('GMLVQ: error on the test set: %f\n',testError);
dataprojection = GMLVQ_project([trainSet;testSet], GMLVQ_model, 2);
gscatter(dataprojection(:,1),dataprojection(:,2),[trainLab;testLab],'','o',4,'off','dim 1','dim 2');