ranking icon indicating copy to clipboard operation
ranking copied to clipboard

How to predict with libsvm data?

Open supercar1 opened this issue 1 year ago • 3 comments

Hello! I'm training and evaluating data in the libsvm format (using tf_ranking_libsvm.py), however I'd like to do predictions too, but I'm having no success at it. I'm not really good at coding, so is there any straightforward way to do it? I've already seen #69, #65, #77, #78 and some others, and while some people were able to predict, from my understanding, those methods are not available now.

Some of the proposed solutions were to do "ranker.predict()", or "estimator.predict()", but it appears those are "undefined names". Some solutions were based on a "libsvm_generator", but from what I've seen, that function has been removed.

Any help would be appreciated, thank you very much! :)

supercar1 avatar Jul 13 '22 22:07 supercar1

@xuanhuiwang sorry to be bothering, but you seemed to be quite active in those past issues. Do you have any sugestion of how to predict (after testing and evaluation) with libsvm data?

supercar1 avatar Jul 19 '22 12:07 supercar1

For training and evaluating with libsvm data, there is now a libsvm parser in the tensorflow_datasets package here, which can act as a generator. An example of how this parser is used can be found here.

At a high-level, you should be able to use something like this to get predictions on libsvm files (this is a rough sketch and not a complete solution):

model.fit()
...
path = "... path to your libsvm file ..."
with tf.io.gfile.GFile(path, "r") as f:
  for input in LibSVMRankingParser(f, {0: "feature_0", 1: "feature_1", ...}, "label"):
    label = input.pop("label")
    predictions = model(input)
    ...

rjagerman avatar Aug 23 '22 18:08 rjagerman

I will close this issue now. Feel free to reach out or re-open if you have further questions about LibSVM-style data.

rjagerman avatar Sep 16 '22 08:09 rjagerman