jfloff / pywFM

pywFM is a Python wrapper for Steffen Rendle's factorization machines library libFM
https://pypi.python.org/pypi/pywFM
MIT License
250 stars 43 forks source link

Added quick fix which should allow the model to run only the single-i… #16

Closed bbradt closed 7 years ago

bbradt commented 7 years ago

If the user sets the number of two-way interactions to 0, the model output file used by the wrapper outputs blanks under the pairwise interaction label. Under the current version, this raises a ValueError in the wrapper because wrapper assumes there will always be a compatible float following the two-way interaction header.

I added a quick fix which catches this ValueError and sets the two-way interactions to 0 if an incompatible (non-numerical) value is parsed. This allows users to input the number of two-way interactions (k2) as 0, which is useful for running the one-way or global-bias models as a baseline. This is more closely inline with the libfm Binary input behavior, which, when the number of two-way interactions is set to 0, models only the global or one-way biases.

There may be a way to handle the k2 input as 0 earlier in the setup phase of the wrapper, but this fix works. Catching the exception as a ValueError may create issues if for some reason the temporary model output file outputs other incompatible values which don't appear as a result of the user inputting 0 for k2.

jfloff commented 7 years ago

Quick and easy 👍 When you feel like improving the solution you are free to open another PR.

Thanks for the contribution!