How to train SVM on features matrix?

3 ビュー (過去 30 日間)
Phoenix98
Phoenix98 2019 年 1 月 10 日
回答済み: Akshat 2025 年 1 月 29 日 18:42
Hi,
I tried to train SVM on cell array which each element is 20x120 double, How to train SVM fitcecoc on cell which each cell element contains 20x120 array features?

回答 (1 件)

Akshat
Akshat 2025 年 1 月 29 日 18:42
As per the documentation of "fitcecoc" given here https://www.mathworks.com/help/stats/fitcecoc.html#bue3oc9-2, you can see the input table takes in a 2D data, which is basically, numObservations x numFeatures. This means each observation (or sample) is a row, and each feature is a column. If your data is inherently multi-dimensional (like images or matrices), you need to flatten these into a single row to fit this format.
I am assuming your data is a matrix, and hence it will need to be flattened out.
Following that, it is a simple implementation of an "fitcecoc" classifier. Here is some boilerplate code:
% Assume 'data' is your cell array where each cell is a 20x120 matrix
% Assume 'labels' is a vector containing the label for each matrix
numObservations = numel(data);
reshapedData = zeros(numObservations, 20 * 120);
for i = 1:numObservations
reshapedData(i, :) = reshape(data{i}, 1, []);
end
% Train the SVM using fitcecoc
% 'labels' should be a column vector with the same number of rows as reshapedData
svmModel = fitcecoc(reshapedData, labels);
Hope this helps!

カテゴリ

Help Center および File ExchangeClassification Ensembles についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by