1.打开git bash, 输入下面命令,获取libffm文件
git clone --recursive https://github.com/guestwalk/libffm.git
2.进入libffm文件夹
cd libffm
3.编译
make
例子
#路径
import os
os.getcwd()
os.chdir(r'E:\wdy\GIT\libffm')
os.getcwd()
os.system("start ffm-train.exe")
os.startfile("ffm-train.exe")
os.system("start ffm-predict.exe")
os.startfile("ffm-predict.exe")
import subprocess
#使用缺省参数训练模型
cmd = 'ffm-train bigdata.tr.txt model'
subprocess.call(cmd, shell=True)
#使用bigdata.te.txt作为validation数据
cmd = 'ffm-train -p bigdata.te.txt bigdata.tr.txt model'
subprocess.call(cmd, shell=True)
#使用5折交叉验证
cmd = 'ffm-train -v 5 bigdata.tr.txt'
subprocess.call(cmd, shell=True)
#用–quiet参数训练时不打印训练信息
cmd = 'ffm-train –quiet bigdata.tr.txt'
subprocess.call(cmd, shell=True)
#预测
cmd = 'ffm-predict bigdata.te.txt model output.txt'
subprocess.call(cmd, shell=True)
#基于磁盘的训练
cmd = 'ffm-train –no-rand –on-disk bigdata.tr.txt'
subprocess.call(cmd, shell=True)
#使用–auto-stop参数,当达到最优的validation损失时停止训练
cmd = 'ffm-train -p bigdata.te.txt -t 100 bigdata.tr.txt'
subprocess.call(cmd, shell=True)
参考资料
http://www.csie.ntu.edu.tw/~r01922136/libffm/
https://github.com/guestwalk/libffm
https://github.com/zgcgreat/tencent-ffm
http://blog.csdn.net/zc02051126/article/details/54614230