0
votes

I'm using HOG in order to extract a set of features trough an Image A. the HOG returns a features' vector of 1xN elements. However the linear SVM accept only 2 features for each sample i.e the training data matrix's size is Mx2. so how i can adapt the HOG vector to be trained on linear SVM. Please help me. Thanks

1

1 Answers

2
votes

What do you mean by "the linear SVM accept only 2 features for each sample"? You may be confused on how the SVM function accepts its training data. Here's a quick example of how I use it:

First, lets train an SVM model using fitcsvm using 500 samples of random data (the rows in the training data matrix), each with 1000 elements (the columns in the training data matrix), where the first 250 samples are in class 1 (first 250 rows of training labels), and the last 250 samples are in class 0 (last 250 rows of training labels):

>> training_data = rand(500, 1000);
>> training_labels = [ones(250,1); zeros(250,1)];
>> 
>> svm_model = fitcsvm(training_data, testing_data)

svm_model = 

  ClassificationSVM
      PredictorNames: {1x1000 cell}
        ResponseName: 'Y'
          ClassNames: [0 1]
      ScoreTransform: 'none'
     NumObservations: 500
               Alpha: [418x1 double]
                Bias: 2.3217
    KernelParameters: [1x1 struct]
      BoxConstraints: [500x1 double]
     ConvergenceInfo: [1x1 struct]
     IsSupportVector: [500x1 logical]
              Solver: 'SMO'


  Properties, Methods

We can generate some random test data for 10 test samples, each with 1000 elements, and create some predictions from it:

>> test_data = rand(10, 1000);
>> predicted_classes = predict(svm_model, test_data)

predicted_classes =

     1
     1
     1
     1
     1
     0
     0
     0
     1
     0

Does that answer your question?