How to input a 3D matrix to SVMtrain? (2class problem)

Hi. I have a 3D matrix Training (4x12x7) with first dimension being the number of samples. Group gives the labels +1 or -1. I get an error when I try to input this to svmtrain
Training(:,:,1) = [0 0 0 0 0 0 1 0 2 1 3 0; 0 0 0 1 1 0 0 1 2 2 1 0; 0 1 0 0 0 0 0 0 0 0 1 1;0 0 0 0 1 0 2 0 2 0 2 0];
Training(:,:,2) = [0 0 0 0 0 0 1 0 2 1 0 0; 0 0 0 1 1 0 0 1 0 2 1 1; 0 1 0 0 0 0 0 0 0 0 1 1;0 0 0 0 1 0 2 0 3 0 2 2];
Training(:,:,3) = [0 0 0 0 0 0 1 0 2 1 3 0; 0 0 0 0 1 0 0 1 2 0 1 0; 0 1 0 0 5 0 0 0 0 0 1 1;0 0 0 0 0 0 0 0 2 0 3 2];
Training(:,:,4) = [1 1 0 0 0 0 1 0 0 1 3 0; 0 4 0 2 0 0 0 0 2 0 2 1; 0 1 0 0 0 0 0 0 0 0 1 1;0 1 2 0 0 0 1 0 0 0 0 2];
Training(:,:,5) = [0 0 2 0 0 0 1 0 2 0 0 0; 0 0 0 3 1 0 0 1 2 2 1 1; 0 1 0 2 0 0 0 0 0 0 3 1;0 0 0 0 1 0 0 0 2 0 2 3];
Training(:,:,6) = [0 0 0 0 0 0 1 0 2 1 3 0; 0 0 0 1 0 0 0 1 1 2 0 1; 0 1 0 0 0 0 0 0 0 0 1 1;0 0 0 0 0 0 2 0 2 0 0 2];
Training(:,:,7) = [1 0 0 0 0 0 0 0 2 0 3 0; 0 0 0 1 1 0 0 1 2 1 1 1; 0 1 0 0 0 0 5 0 0 0 1 1;0 0 0 0 1 0 2 0 2 0 2 2];
Group = [1 1 -1 -1];
SVMStruct = svmtrain(Training,Group);
The error is below
??? Error using ==> svmtrain at 453
Error calculating the kernel function:
Transpose on ND array is not defined.
I think it is an issue with input of more than 2 dim. If "Training" is 4x12, there is no problem. Can any one help me? Thanks

 Accepted Answer

Just reshape your data such that svm understands what your observations are and what your targets are:
Tr = reshape(Training,[4 84])';
Group = [1 1 -1 -1];
SVMStruct = svmtrain(Tr,Group);

5 Comments

Thanks. so only 2D arrays can be input into svmtrain?
Yes and No,
Technically the 2D or 3Dness you are referring to are just the dimensions of the MATLAB matrix variable. In SVM and machine learning context, the dimension of your data is dictated by the number of columns in the matrix.
Take the classification example, a given row in your matrix is called an observation and can have many variables or columns. If there are 5 variables then the data is 5 dimensional and you may have hundreds of such observations. And this is convention in the world of statics and machine learning.
What you have is a 3D matrix in MATLAB and neither svmtrain nor any other classification tool will understand what this is unless you present it in the form I mentioned above. In this case I reshaped it so that svmtrain understands it.
So Yes to only 2D arrays are accepted by SVMTRAIN and No to if only 2D are supported.
Thanks. Now I understand how it works.
If you know about svm, I have an issue with slack variables/ distance to boundary. Will you be able to help out? Qn posted http://www.mathworks.com/matlabcentral/answers/62757-how-do-i-find-slack-variables-in-svm-distance-to-the-boundary Thanks again
Still get the same error Error using svmtrain (line 254) Y and TRAINING must have the same number of rows.
Hi I didn't know how to use svm classification with matrix ,I apply at the first MFCC so I wil have for each data a matrix (34*numbre of sample),I used 9 signals for the training and 9 for the test please there is any one know how to implement this??

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!