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 42 forks source link

Global bias is None, even k0 is True #25

Open snowsteper opened 6 years ago

snowsteper commented 6 years ago

I was trying to calculate the prediction value myself with the weight output by model and always got the wrong answer. Then I realized that the bias value is always None, even if I set k0=True manually.

fm = pywFM.FM(task='regression', num_iter=5, k2=2, k0=True)

I don't know whether the wrong answer came from the absence of bias, but it seems strange that the global_bias is always None.

How can I fix it? Or, is there any possibility I can calculate the prediction myself?

jfloff commented 6 years ago

Could you provide a MWE?

Thank you for the report!

kevin1kevin1k commented 3 years ago

I had the same issue, with both regression and classification. Below is an MWE. (I followed the installation for libfm, and installed the latest pywFM with https://github.com/jfloff/pywFM/issues/29#issuecomment-663429991)

import numpy as np
import pywFM

x = np.array([
    [0., 1.],
    [1., 0.],
])
y = np.array([-1., 1.])

fm = pywFM.FM("regression", num_iter=10, k0=True, seed=1)
model = fm.run(x, y, x, y) # using the same data for simplicity
print(model.predictions, model.global_bias)
# output: [-0.429961, 0.264456] None

Not sure if the issue is due to temp files. Thanks in advance!