Loop machine learning algorithm functions

2 visualizaciones (últimos 30 días)
Dylan den Hartog
Dylan den Hartog el 1 de Nov. de 2021
Comentada: yanqi liu el 30 de Dic. de 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

Respuesta aceptada

Voss
Voss el 17 de Dic. de 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 comentario
yanqi liu
yanqi liu el 30 de Dic. de 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}

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by