Cross-validation part 3: using a dataset measure

Here we introduce what we refer to as a “dataset measure”. A dataset measure is a function with the following signature:

output = dataset_measure(dataset, args)

Thus any function you write can be used as a dataset measure as long as it can use this input scheme. In a similar way, our classifiers all have the same signature:

predictions = classifier(train_data, train_targets, test_data, opt)

This is useful for writing code that can be reused for different purposes. The cross-validation dataset measure function is written to work with any generic classifier, and returns the classification accuracy. This is done by passing a function handle to a classifier in the args struct input. For example, the function handle for the nearest neighbor classifier can be passed by the args struct by using the @function syntax:

args.classifier = @cosmo_classify_nn

In the code for cross validation below, your job is to write the missing for loop. This for loop must iterate over each data fold in args.partitions, call a generic classifier, and keep track of the number of correct classifications.

function ds_sa = cosmo_crossvalidation_measure(ds, varargin)

Hint: cosmo crossvalidation measure skl

Solution: cosmo crossvalidation measure