2个不稳定版本
0.2.0 | 2024年7月11日 |
---|---|
0.1.0 | 2021年11月17日 |
#110 in 机器学习
44KB
977 行
LIBFFM Rust
LIBFFM - 字段感知因子分解机 - 在Rust中
入门指南
LIBFFM Rust可以作为Rust库和命令行工具使用。
Rust库
安装
将以下行添加到您的应用程序的Cargo.toml
中的[dependencies]
libffm = "0.2"
使用方法
在LIBFFM格式中准备您的数据
0 0:0:1 1:1:1
1 0:2:1 1:3:1
训练模型
let model = libffm::Model::train("train.ffm").unwrap();
使用验证集和早停来防止过拟合
let model = libffm::Model::params()
.auto_stop(true)
.train_eval("train.ffm", "valid.ffm")
.unwrap();
进行预测
let (predictions, loss) = model.predict("test.ffm").unwrap();
将模型保存到文件
model.save("model.bin").unwrap();
从文件加载模型
let model = libffm::Model::load("model.bin").unwrap();
训练选项
let model = libffm::Model::params()
.learning_rate(0.2) // learning rate
.lambda(0.00002) // regularization parameter
.iterations(15) // number of iterations
.factors(4) // number of latent factors
.quiet(false) // quiet mode (no output)
.normalization(true) // use instance-wise normalization
.auto_stop(false) // stop at the iteration that achieves the best validation loss
.on_disk(false) // on-disk training
.train("train.ffm"); // train or train_eval
命令行工具
安装
运行
cargo install libffm --features cli
使用方法
在LIBFFM格式中准备您的数据
0 0:0:1 1:1:1
1 0:2:1 1:3:1
训练模型
ffm-train train.ffm model.bin
使用验证集和早停来防止过拟合
ffm-train -p valid.ffm --auto-stop train.ffm model.bin
进行预测
ffm-predict test.ffm model.bin output.txt
训练选项
FLAGS:
--auto-stop Stop at the iteration that achieves the best validation loss (must be used with -p)
--in-memory Enable in-memory training
--no-norm Disable instance-wise normalization
--quiet Quiet mode (no output)
OPTIONS:
-r <eta> Set learning rate [default: 0.2]
-k <factor> Set number of latent factors [default: 4]
-t <iteration> Set number of iterations [default: 15]
-l <lambda> Set regularization parameter [default: 0.00002]
-s <nr-threads> Set number of threads [default: 1]
-p <va-path> Set path to the validation set
致谢
此库是从LIBFFM C++库移植过来的,并使用相同的许可证。
历史
查看变更日志
贡献
鼓励每个人帮助改进此项目。以下是一些您可以提供帮助的方式
开始开发
git clone https://github.com/ankane/libffm-rust.git
cd libffm-rust
cargo test
cargo run --bin ffm-train --features cli
cargo run --bin ffm-predict --features cli
依赖项
~325–710KB
~12K SLoC