windows下Python中libffm简单使用

本文详细介绍了如何通过Git获取libFFM源代码并进行编译安装的过程,同时还提供了利用Python调用libFFM进行模型训练及预测的具体示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/zc02051126/article/details/54614230

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值