Filter löschen
Filter löschen

Loop machine learning algorithm functions

1 Ansicht (letzte 30 Tage)
Dylan den Hartog
Dylan den Hartog am 1 Nov. 2021
Kommentiert: yanqi liu am 30 Dez. 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

Akzeptierte Antwort

Voss
Voss am 17 Dez. 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 Kommentar
yanqi liu
yanqi liu am 30 Dez. 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}

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by