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개)
Walter Roberson
2023년 7월 28일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!