How can i calculate training and testing time of a model using classification learner app?

I am using wine dataset for experiment
% load wine_dataset
% [dummy, Target] = max(wineTargets);
% wineDataset = [wineInputs; Target];
I imported wineDataset matrix in classification learner app and train the data using Linear SVM and Quadratic SVM. How can I calculate training and testing time taken by model?

Risposte (1)

Export the code, and then use tic and toc.

3 Commenti

function [trainedClassifier, validationAccuracy] = trainClassifier(datasetTable)
% Convert input to table
datasetTable = table(datasetTable');
datasetTable.Properties.VariableNames = {'row'};
% Split matrices in the input table into vectors
datasetTable.row_1 = datasetTable.row(:,1);
datasetTable.row_2 = datasetTable.row(:,2);
datasetTable.row_3 = datasetTable.row(:,3);
datasetTable.row_4 = datasetTable.row(:,4);
datasetTable.row_5 = datasetTable.row(:,5);
datasetTable.row_6 = datasetTable.row(:,6);
datasetTable.row_7 = datasetTable.row(:,7);
datasetTable.row_8 = datasetTable.row(:,8);
datasetTable.row_9 = datasetTable.row(:,9);
datasetTable.row_10 = datasetTable.row(:,10);
datasetTable.row_11 = datasetTable.row(:,11);
datasetTable.row_12 = datasetTable.row(:,12);
datasetTable.row_13 = datasetTable.row(:,13);
datasetTable.row_14 = datasetTable.row(:,14);
datasetTable.row = [];
% Extract predictors and response
predictorNames = {'row_1', 'row_2', 'row_3', 'row_4', 'row_5', 'row_6', 'row_7', 'row_8', 'row_9', 'row_10', 'row_11', 'row_12', 'row_13'};
predictors = datasetTable(:,predictorNames);
predictors = table2array(varfun(@double, predictors));
response = datasetTable.row_14;
% Train a classifier
template = templateSVM('KernelFunction', 'linear', 'PolynomialOrder', [], 'KernelScale', 'auto', 'BoxConstraint', 1, 'Standardize', 1);
trainedClassifier = fitcecoc(predictors, response, 'Learners', template, 'Coding', 'onevsone', 'PredictorNames', {'row_1' 'row_2' 'row_3' 'row_4' 'row_5' 'row_6' 'row_7' 'row_8' 'row_9' 'row_10' 'row_11' 'row_12' 'row_13'}, 'ResponseName', 'row_14', 'ClassNames', [1 2 3]);
% Perform cross-validation
partitionedModel = crossval(trainedClassifier, 'KFold', 5);
% Compute validation accuracy
validationAccuracy = 1 - kfoldLoss(partitionedModel, 'LossFun', 'ClassifError');
%%Uncomment this section to compute validation predictions and scores:
% % Compute validation predictions and scores
% [validationPredictions, validationScores] = kfoldPredict(partitionedModel);
Where should i put tic and toc as 'fitcecoc' function using all data i.e. 178 observations to train the model?
Put tic where you want to start the stop watch, and put toc where you want to stop the stop watch and discover the elapsed time.
I know this is an old post, but I can't seem to find where I can export MATLAB code from the classification learner app. (Of course I can just copy, paste and adapt the above, but it would be nice to know how it was generated)
If anyone could link me to any useful articles/ docs I would appreciate that too.

Accedi per commentare.

Richiesto:

il 30 Lug 2016

Commentato:

il 25 Feb 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by