Effacer les filtres
Effacer les filtres

Loop machine learning algorithm functions

1 vue (au cours des 30 derniers jours)
Dylan den Hartog
Dylan den Hartog le 1 Nov 2021
Commenté : yanqi liu le 30 Déc 2021
I want to create a loop where multiple different machine learning models are created with the same input and output.
Lets say the input is:
x = [1 1 1 1 2 2 2 2 3 3 3 3]
and the output is:
y = categorical(["dog" "dog" "dog" "dog" "cat" "cat" "cat" "cat" "bird" "bird" "bird" "bird"])
I want to fit a KNN, SVM and a Decision Tree classifier. Instead of specifying:
A1 = fitcknn(x,y)
A2 = fitcecoc(x,y)
A3 = fitctree(x,y)
Instead of the above I want to create a loop going over the functions {fitcknn fitcecoc fitctree}
I tried something like this:
for classifier = [fitcknn fitcecoc fitctree]
A = classifier(x,y)
end

Réponse acceptée

Voss
Voss le 17 Déc 2021
funcs = {@fitcknn @fitcecoc @fitctree};
n_funcs_given = numel(funcs);
A = cell(1,n_funcs_given);
for i = 1:n_funcs_given
A{i} = funcs{i}(x,y);
end
  1 commentaire
yanqi liu
yanqi liu le 30 Déc 2021
yes,sir,it is great method
clc; clear all; close all;
x = [1 1 1 1 2 2 2 2 3 3 3 3];
y = categorical(["dog" "dog" "dog" "dog" "cat" "cat" "cat" "cat" "bird" "bird" "bird" "bird"]);
funcs = {@fitcknn @fitcecoc @fitctree};
n_funcs_given = numel(funcs);
A = cell(1,n_funcs_given);
for i = 1:n_funcs_given
A{i} = funcs{i}(x(:),y(:));
end
A
A = 1×3 cell array
{1×1 ClassificationKNN} {1×1 ClassificationECOC} {1×1 ClassificationTree}

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by