PRT Blog

MATLAB Pattern Recognition Open Free and Easy

PRT Logo

Pattern Recognition in MATLAB

The Pattern Recognition Toolbox for MATLAB® provides an easy to use and robust interface to dozens of pattern classification tools making cross-validation, data exploration, and classifier development rapid and simple. The PRT gives you the power to apply sophisticated data analysis techniques to your problem. If you have data and need to make predictions based on your data, the PRT can help you do more in less time.

Visualize Your Data

The PRT’s prtDataSet objects make using and visualizing your data a breeze. The multiple built in techniques for data visualization will help you interactively understand your data and develop the insights to help you make breakthroughs.

Streamline Your Processing

The PRT provides a wide array of inter-connectable pattern recognition approaches. Every PRT action can be connected to any other PRT actions to enable you to build the powerful processing pipelines to solve the problems you need to solve with a single tool.

Get Answers

Built in cross-validation techniques ensure that your performance estimates are robust, and are indicative of expected operating performance, and built in support for decision making takes the guesswork out of setting optimal thresholds to make binary or M-ary decisions based on your data.




Latest Post


twoClassParadigm

When using an M-ary classifier on a binary classification problem, sometimes you want multiple dimensional output and sometimes you don’t. In the PRT the default is to supply only a single output but this can be specified by setting the twoClassParadigm property of classifiers.

Contents

A Quick Example

Consider a binary classification problem with an m-ary classifer (prtClassMap).

dsTrain = prtDataGenUnimodal;
dsTest = prtDataGenUnimodal;

classifier = prtClassMap;
trainedClassifier = train(classifier, dsTrain);

plot(trainedClassifier);
title('Binary Classification with MAP','FontSize',16);

output = run(trainedClassifier, dsTest);

output.nFeatures
ans =
 1

As you can see the output only has one feature. But consider the same M-ary classifier with a 3-class problem.

dsTrainMary = prtDataGenMary;
dsTestMary = prtDataGenMary;

trainedClassifierMary = train(classifier, dsTrainMary);

plot(trainedClassifierMary);
title('M-ary Classification with MAP','FontSize',16);

outputMary = run(trainedClassifierMary, dsTestMary);

outputMary.nFeatures
ans =
 3

Now the output has 3 feautres. The trend continues with more classes, because prtClassMap declares itself as an Mary classififer

classifier.isNativeMary
ans =
 1

the output is (as it should) have a column corresponding to the confidence of each class. Binary classification is an exception.

twoClassParadigm

By default the PRT checks when M-ary classifiers are run on binary data to see if it should output a single confidence or binary confidences. The mode of operation is stored in twoClassParadigm which by default is set to the string M-ary.

classifier.twoClassParadigm
ans =
binary

If we return to the binary classification problem and set twoClassParadigm to mary we can see that we get the two outputs that we expect.

classifier.twoClassParadigm = 'mary';
trainedClassifierBinaryActingAsMary = train(classifier, dsTrain);

outputBinaryActingAsMary = run(trainedClassifierBinaryActingAsMary, dsTest);

outputBinaryActingAsMary.nFeatures
ans =
 2

Why did you do that?

We debated, but ultimately we decided that it was less confusing this way. It is more rare to want both outputs for a binary classification problem than it is to expect a single. Most users expected this to run out of the box.

classifier = prtClassMap;
trainedClassifier = train(classifier, dsTrain);
output = run(trainedClassifier, dsTest);

prtScoreRoc(output);
title('Binary Classification with an M-ary Classifier','FontSize',16);

If you change the classifier to non-m-ary classification (prtClassGlrt for example) you expect the same code to work only by changing the classifier declaration.

classifier = prtClassGlrt;
trainedClassifier = train(classifier, dsTrain);
output = run(trainedClassifier, dsTest);

prtScoreRoc(output);
title('Binary Classification with a Binary Classifier','FontSize',16);

Without the twoClassParadigm system it wouldn’t be as easy to switch classifiers for binary problems as an extra step would be required to manually select which column of the output should be used to calculate the ROC.

Conclusion

Well that’s twoClassParadigm. It’s a convenient feature of the PRT that not many people know about because they don’t have to. In the rare cases when you want the confidence assigned to each class, you now know how to get them.