フィルターのクリア

Loop machine learning algorithm functions

1 回表示 (過去 30 日間)
Dylan den Hartog
Dylan den Hartog 2021 年 11 月 1 日
コメント済み: yanqi liu 2021 年 12 月 30 日
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

採用された回答

Voss
Voss 2021 年 12 月 17 日
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 件のコメント
yanqi liu
yanqi liu 2021 年 12 月 30 日
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}

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by