srendle / libfm

Library for factorization machines
GNU General Public License v3.0
1.49k stars 414 forks source link

Strange results on hello world example #27

Closed timnon closed 7 years ago

timnon commented 7 years ago

Please enlighten me, i tried the simplest possible example:

File train.libfm is set to

1 0:1 1:1

and ran it using

libFM -task r -method mcmc -train train.libfm -test train.libfm -iter 10 -dim ‘0,0,1’ -out output.libfm -save_model model.libfm

Hence, only the pairwise interactions should be used and its dimension is 1. The regression shows a perfect fit (as expected). However, looking at model.libfm gives me

#pairwise interactions Vj,f
0.0139959
0.711416

My expectations is that the first number times the second number (the pairwise interaction of the two features) should be 1 (the target of the regression), but it is always clearly sth else. Tried the same trivial example with fastFM and it behaved as expected.

chihming commented 7 years ago

Could you check your commend line? In my case, -method mcmc won't save model, and the program will be terminated automatically like:

WARNING: -save_model enabled only for SGD and ALS.

I tried using -method als, the model looks good to me.

./bin/libFM -task r -method als -train train.libfm -test train.libfm -iter 10 -dim ‘0,0,1’ -out output.libfm -save_model model.libfm

I can always get a satisfied result that the multiplication of the two is larger than 1, such as:

#pairwise interactions Vj,f
7.79554
0.128279

BTW, there is one trick in libfm that the predictions will be replaced by MAX value when the predictions are larger than MAX.

timnon commented 7 years ago

Thanks for the quick reply!

Switching to -method mcmc works for me! But why does -method mcmc not? I can also save the model with -method mcmc using the command from above:

libFM -task r -method mcmc -train train.libfm -test train.libfm -iter 10 -dim ‘0,0,1’ -out output.libfm -save_model model.libfm

Using -method sgd gives me the following error (i guess this is another problem):

Loading meta data...
Assertion failed: ((lr.size() == 1) || (lr.size() == 3)), function main, file libfm.cpp, line 386.
./run.sh: line 1: 13540 Abort trap: 6           ../libfm/bin/libFM -task r -method sgd -train train.libfm -test train.libfm -iter 10 -dim ‘0,0,1’ -out output.libfm -save_model model.libfm
chihming commented 7 years ago

The original design doesn't consider the saving function. The current saving function is later added. In general, the mcmc method is supposed to save the modeling parameters for each iteration. In other words, 100 iterations will save the modeling parameters 100 times, which is quite big if we use a large dimensional dataset. Instead, libfm selects to make the predictions on-the-fly so it won't produce a big modeling file (or occupies too much memory).

Add -learn_rate 0.1 could solve the sgd issue.

timnon commented 7 years ago

thanks!

crystallp commented 6 years ago

the result of output is always 0 or 1,but it want the predict value in 0 to 1,how about ?