pyFM icon indicating copy to clipboard operation
pyFM copied to clipboard

can't save and load model correctly

Open nasuka opened this issue 10 years ago • 12 comments

I tried to save trained FM model and load it by using pickle. I could save and load it , but loaded model predicted anomalous values like all zero. How do I save and load trained model correctly ?

nasuka avatar Nov 06 '15 02:11 nasuka

did you ever figure this out?

rohanag108 avatar Jun 08 '16 03:06 rohanag108

Hello, using the highest protocol available (-1) fixed the issue for me:

import cPickle as pickle  
#Save the trained model to file   
pickle.dump(model, open( "fittedmodel.pickle", "wb" ), -1)     # protocol=-1 : using the highest protocol available  
#Load the trained model from file  
model= pickle.load(open( "fittedmodel.pickle", "rb" ))   
print model.v

Hope this helps

nicolasfguillaume avatar Jun 18 '16 12:06 nicolasfguillaume

I have the same problem. Using the highest protocol didnt work for me:(

tanql avatar Oct 04 '16 23:10 tanql

same issue here. I can save it and load it, but the predict method returns all 0s.

jrzaurin avatar Jan 25 '17 18:01 jrzaurin

I have the same issue.

joblib.dump(model, 'fm.pkl')
model = joblib.load('fm.pkl')

ktrueda avatar Mar 07 '17 11:03 ktrueda

I have the same error

hapream avatar Jul 17 '17 12:07 hapream

Have someone solve this problem?

Darinyazanr avatar Aug 23 '17 07:08 Darinyazanr

I ended up using fastFM and ultimately, when we went to production, we used ALS on pySpark. Another option is perhaps trying lightfm. Good luck!

jrzaurin avatar Aug 23 '17 09:08 jrzaurin

@jrzaurin Do you have solved this issue? fastFM can save model well?

Darinyazanr avatar Aug 23 '17 10:08 Darinyazanr

As far as I can remember, both fastFm and lightFM saved the model with no problem. Regarding to fastFM I believe in their site they mentioned that is an academic project and not suited for production, but that might have changed have a look to their documenation. Regarding to lightFM, I believe the people at lyst used it (for me it did not work well). Good luck!

jrzaurin avatar Aug 23 '17 10:08 jrzaurin

@jrzaurin thx very much.I will try to use lightFM. But I really don't kown why predict all 0s. fm<pyfm.pylibfm.FM instance at 0x31a5ef0> ('fm', array([[ 0.04463324, 0.16691201, -0.026428 , -0.09678349, 0.00591884, 0.151462 , 0.03368704, -0.03023687, -0.08386418], [-0.05177313, 0.02535079, -0.2484704 , -0.06514199, -0.17754692, 0.02342858, 0.12393999, -0.06503343, -0.02662149], [-0.05387198, 0.04207405, -0.00952863, -0.07698761, -0.01837245, 0.01768089, 0.07370562, 0.06938626, -0.08155303], [ 0.03876805, 0.0106537 , -0.03145769, -0.06997129, 0.00529883, 0.09341078, 0.14598721, -0.15788771, 0.09522664], [-0.06024594, 0.04614449, -0.00039591, 0.0777348 , -0.04931128, 0.06085309, 0.03142342, -0.07113038, 0.1005296 ], [ 0.0211259 , -0.08731488, 0.09841571, -0.00702032, 0.1778722 , -0.00426561, 0.00464802, 0.10008996, 0.13210467], [ 0.11710963, -0.07851948, 0.05037158, -0.22096869, 0.0221839 , -0.22044528, 0.06681716, -0.04526808, -0.14862625], [ 0.09367802, 0.03140169, 0.02186942, 0.06581881, 0.04394821, 0.02565542, 0.02248762, 0.14576877, -0.1542256 ], [-0.14858283, -0.04868577, 0.0234426 , -0.00569702, 0.15142498, -0.13743753, -0.04227515, -0.00504726, 0.07348803], [-0.07020803, -0.03101657, -0.1198239 , 0.08044487, 0.01856105, -0.28774227, 0.02996937, -0.0562063 , -0.06951357]])) model: ('model', array([[ 0.04463324, 0.16691201, -0.026428 , -0.09678349, 0.00591884, 0.151462 , 0.03368704, -0.03023687, -0.08386418], [-0.05177313, 0.02535079, -0.2484704 , -0.06514199, -0.17754692, 0.02342858, 0.12393999, -0.06503343, -0.02662149], [-0.05387198, 0.04207405, -0.00952863, -0.07698761, -0.01837245, 0.01768089, 0.07370562, 0.06938626, -0.08155303], [ 0.03876805, 0.0106537 , -0.03145769, -0.06997129, 0.00529883, 0.09341078, 0.14598721, -0.15788771, 0.09522664], [-0.06024594, 0.04614449, -0.00039591, 0.0777348 , -0.04931128, 0.06085309, 0.03142342, -0.07113038, 0.1005296 ], [ 0.0211259 , -0.08731488, 0.09841571, -0.00702032, 0.1778722 , -0.00426561, 0.00464802, 0.10008996, 0.13210467], [ 0.11710963, -0.07851948, 0.05037158, -0.22096869, 0.0221839 , -0.22044528, 0.06681716, -0.04526808, -0.14862625], [ 0.09367802, 0.03140169, 0.02186942, 0.06581881, 0.04394821, 0.02565542, 0.02248762, 0.14576877, -0.1542256 ], [-0.14858283, -0.04868577, 0.0234426 , -0.00569702, 0.15142498, -0.13743753, -0.04227515, -0.00504726, 0.07348803], [-0.07020803, -0.03101657, -0.1198239 , 0.08044487, 0.01856105, -0.28774227, 0.02996937, -0.0562063 , -0.06951357]])) model<pyfm.pylibfm.FM instance at 0x31aac68> predict:[ 5.],model:[ 0.]

Darinyazanr avatar Aug 23 '17 11:08 Darinyazanr

I ended up using fastFM and ultimately, when we went to production, we used ALS on pySpark. Another option is perhaps trying lightfm. Good luck!

fastFm does not support windows

Pager07 avatar Mar 14 '20 15:03 Pager07