rth / pysofia

bindings for the sofia-ml machine learning library
http://code.google.com/p/sofia-ml/
37 stars 12 forks source link

Problems while launching RankSVM #11

Open TheEdoardo93 opened 6 years ago

TheEdoardo93 commented 6 years ago

Hi, I tried out to use this library for training (and testing) RankSVM ranking model but I've received an error.

coef = pysofia.svm_train(X=X_data, y=y_target_labels, b=b_query_id, alpha = 0.01, loop='rank',
                                 learner=6, eta=0, n_samples=X_data.shape[0], n_features=X_data.shape[1])

When I launch the above code line, I've received an error:

Traceback (most recent call last):
  File "/Users/edoardo/PycharmProjects/MasterThesisProject/launcher/ThesisProject.py", line 244, in <module>
    class ThesisProject():
  File "/Users/edoardo/PycharmProjects/MasterThesisProject/launcher/ThesisProject.py", line 247, in ThesisProject
    launch_pipeline()
  File "/Users/edoardo/PycharmProjects/MasterThesisProject/launcher/ThesisProject.py", line 105, in launch_pipeline
    coef = rankSVM_PySofiaML.training(X_data=X_matrix, y_target_labels=y_array, b_query_id=query_id_array)
  File "/Users/edoardo/PycharmProjects/MasterThesisProject/learning_to_rank_algorithm/RankSVM_PySofiaML.py", line 10, in training
    learner=6, eta=0, n_samples=X_data.shape[0], n_features=X_data.shape[1])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pysofia/sofia_ml.py", line 94, in svm_train
    learner.value, loop.value, eta.value, step_probability)
AttributeError: 'int' object has no attribute 'value'

My question is: can you give me any tips for the correct input that this model expects? Without documentation, it's really hard to understand how to use this library!

P.S. the error I've received is a bug in your software or am I wrong while passing the parameters to the svm_train() method?

Thanks for the attention, Edoardo

rth commented 6 years ago

Here, svm_train train expects an enums not an integer to specify parameters. You can provide them with e.g.,

from pysofia.sofia_ml import  eta_type
pysofia.svm_train(..., eta=eta_type.basic_eta)

which would correspond to eta=0. And so on for all the other parameters defined in sofia_ml.py. See for instance how it is used in compat.py. Hope this helps.

Without documentation, it's really hard to understand how to use this library! P.S. the error I've received is a bug in your software or am I wrong while passing the parameters to the svm_train() method?

@TheEdoardo93 I appreciate your persistance :) I didn't write this wrapper, and I'm only helping a bit with maintenance. I am aware that the documentation isn't great, but at the moment I don't have the bandwidth to make it better. Any Pull Requests improve the documentaiton would be greatly appreciated!

TheEdoardo93 commented 6 years ago

Thanks, now I prove what you have said!

Another question: I want to use this library for applying Learning to Rank (in particular RankSVM). Can I use this library for my purpose? The first step of this algorithm (RankSVM) is to create the rank constraints: this step is performed by this library, Sofia-ml or do I have to write the code for doing this task on my own?

Thanks, best regards!