pyFM icon indicating copy to clipboard operation
pyFM copied to clipboard

How to save the trained model?

Open Darinyazanr opened this issue 7 years ago • 2 comments

I can't find the way for save the model?Could someone help to solve this? thx now I can run like this: fm = pylibfm.FM() fm.fit(X,y) fm.predict(v.transform({"user": "1", "item": "10", "age": 24})) but can't to find the way to save the model

Darinyazanr avatar Aug 23 '17 05:08 Darinyazanr

Hi @Darinyazanr, maybe "pickle" library can help you code as follows:

import pickle

fm = pylibfm.FM()
fm.fit(X,y)

with open('fm_model.pkl', 'wb') as f:
    pickle.dump(fm, f)
del fm # make sure variable is empty 
with open('fm_model.pkl', 'rb') as f:
    fm = pickle.load(f)

fm.predict(v.transform({"user": "1", "item": "10", "age": 24}))

after that you'll get a file named "fm_model.pkl" under the same directory

YiJingLin avatar Dec 07 '17 08:12 YiJingLin

@YiJingLin is that really worked? the pyfm.pylibfm.FM does not have a write attribute

fooSynaptic avatar Feb 17 '21 07:02 fooSynaptic