davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++

Home Page:http://dlib.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need to ensure if the ranking SVM supports multidimensional data

neur1n opened this issue · comments

Expected Behavior

A ranking SVM created by dlib.svm_rank_trainer can train multidimensional data.

Current Behavior

As shown in the svm_rank.py example and the documentations, the dlib.svm_rank_trainer seems only supports data of a N by 1 vector of floating numbers. And I've tried to put multidimensional Python list, dlib.vector, dlib.matrix into a dlib.vector and they didn't work. Just need to ensure that if training multidimensional data is possible is case I used the APIs incorrectly.

Steps to Reproduce

import dlib

    dr = [
        [0, 650.0, 150.0, 130.0, 80.0],
        [1, 450.0, 170.0, 100.0, 90.0],
        [2, 250.0, 160.0, 100.0, 50.0],
        [3, 550.0, 180.0,   90.0, 60.0],
        [4, 500.0, 150.0, 110.0, 70.0]
    ]

    dnr = [
        [0, 650.0, 150.0, 130.0, 80.0],
        [2, 450.0, 170.0, 100.0, 90.0],
        [1, 250.0, 160.0, 100.0, 50.0],
        [4, 550.0, 180.0,   90.0, 60.0],
        [3, 500.0, 150.0, 110.0, 70.0]
    ]

    training_set = dlib.ranking_pair()
    training_set.relevant.append(dr)
    training_set.nonrelevant.append(dnr)

    trainer = dlib.svm_rank_trainer()
    trainer.c = 10
    rank = trainer.train(training_set)

    print("Weights: {}".format(rank.weights))
  • Version: 19.23.1
  • Where did you get dlib: dlib.net
  • Platform: Windows 10, 64bit
  • Compiler: Visual Studio 2019 Community

Reshape your data so it is N by 1.

Seems like the only way for now. Thank you very much.