lightfm/lightfm-php
最新稳定版本:v1.0.0
Composer 安装命令:
composer require lightfm/lightfm-php
包简介
PHP port of the LightFM Python library using FFI bindings to C implementation for hybrid recommender systems
关键字:
README 文档
README
PHP port of the LightFM Python library using FFI bindings to C implementation for hybrid recommender systems.
Installation
Install via Composer:
composer require lightfm/lightfm-php
Requirements
- PHP 8.0 or higher
- FFI extension enabled
- The bundled C library (
liblightfm.so)
Usage
<?php require_once 'vendor/autoload.php'; // Create a LightFM model $model = new LightFM([ 'no_components' => 30, 'loss' => 'warp', 'learning_rate' => 0.05 ]); // Fit the model with interaction data $interactions = new CSRMatrix($data, $rows, $cols); $model->fit($interactions); // Get recommendations $predictions = $model->predict($userIds, $itemIds);
Running the Examples
The repository includes a comprehensive demo script that showcases all major features of the library.
Prerequisites
- Install dependencies:
composer install
- Ensure the C library is compiled and available:
# The liblightfm.so file should be in the project root
ls -la liblightfm.so
Run the Demo
Execute the demo script from the project root:
php test/main.php
The demo will demonstrate:
- Loading synthetic MovieLens-like data
- Training models with WARP loss function
- Making predictions and generating recommendations
- Evaluating model performance with precision metrics
- Using user and item features
- Working with custom interaction data
Expected Output
The demo will display:
- Dataset statistics (users, items, interactions)
- Training progress and timing
- Model evaluation metrics (precision@5)
- Top recommendations for sample users
- Performance comparison with and without features
- Custom dataset predictions
Note: The current C implementation is simplified, so prediction scores may appear as zeros. This is expected behavior for the initial implementation.
Features
- Hybrid Recommender Systems: Supports both collaborative filtering and content-based filtering
- Multiple Loss Functions: WARP, BPR, and logistic loss functions
- Fast C Implementation: Uses FFI bindings to a compiled C library for performance
- CSR Matrix Support: Efficient sparse matrix operations
- Evaluation Metrics: Built-in precision, recall, and AUC metrics
Classes
LightFM: Main model class for training and predictionCSRMatrix: Sparse matrix implementation for efficient data handlingEvaluation: Evaluation metrics for model performanceMovieLensDataset: Dataset loader for MovieLens dataLightFMFFI: FFI bindings to the C library
License
Apache-2.0
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-07-01