Using SVM on a matrix

I have a large matrix with values ranging from -255 to 255. How do I use matalb to perform a svm analysis on the matrix to perform a linear classification between the negative and positive values?

回答(1 个)

ND = ndims(YourMatrix);
IDXs = cell(1,ND);
[IDXs{:}] = ind2sub(size(YourMatrix), (1:numel(YourMatrix)).');
Data_for_SVM = horzcat(IDXs{:}, YourMatrix(:));
Now you can pass Data_for_SVM to an appropriate SVM-related routine.
What the above function is doing is creating a matrix in which each row corresponds to the indices of a single element of the array, followed by the content of the element. Like
1 1 A(1,1)
2 1 A(2,1)
3 1 A(3,1)
1 2 A(1,2)
2 2 A(2,2)
3 2 A(3,2)
This gives the SVM functions information about the position and value of each entry in the matrix.
The code was deliberately written to not depend upon the matrix being 2D, since you did not specify a dimension of the matrix.
It is not at all clear to me what klnds of responses you were hoping to get? A hyperplane that "optimally" divides the negative and positive values??

类别

帮助中心File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品

版本

R2022b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by