Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to predict with libsvm data? #327

Open
supercar1 opened this issue Jul 13, 2022 · 3 comments
Open

How to predict with libsvm data? #327

supercar1 opened this issue Jul 13, 2022 · 3 comments

Comments

@supercar1
Copy link

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
Copy link
Author

@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?

@rjagerman
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants