endroid/prediction-io

此包已被废弃且不再维护。未建议替代包。

Endroid PredictionIo 客户端

3.0.0 2018-03-04 22:08 UTC

README

endroid 提供

Build Status Latest Stable Version Total Downloads License

Prediction IO 库提供了一个客户端,该客户端提供了对 PredictionIo 推荐引擎的简单访问。PredictionIo 是一个开源的机器学习服务器,供软件开发者创建预测功能,如个性化、推荐和内容发现。

通过一组简单的调用,所有服务器功能都暴露给了您的应用程序。您可以添加用户和项目,在这些用户和项目之间注册动作,并从任何 PredictionIo 推荐引擎中检索由此信息推导出的推荐。应用范围从在网店中显示推荐产品到在社交协作网络中发现相关专家。

Recommendations

需求

安装

使用 Composer 安装库。

$ composer require endroid/prediction-io

使用

use Endroid\PredictionIo\EventClient;
use Endroid\PredictionIo\EngineClient;

$apiKey = '...';
$eventClient = new EventClient($apiKey);
$recommendationEngineClient = new EngineClient('http://localhost:8000');
$similarProductEngineClient = new EngineClient('http://localhost:8001');

// Populate with users and items
$userProperties = ['address' => '1234 Street, San Francisco, CA 94107', 'birthday' => '22-04-1991'];
$eventClient->createUser('user_1', $userProperties);
$itemProperties = ['categories' => [123, 1234, 12345]];
$eventClient->createItem('product_1', $itemProperties);

// Record actions
$actionProperties = ['firstView' => true];
$eventClient->recordUserActionOnItem('view', 'user_1', 'product_1', $actionProperties);

// Return recommendations
$itemCount = 20;
$recommendedProducts = $recommendationEngineClient->getRecommendedItems('user_1', $itemCount);
$similarProducts = $similarProductEngineClient->getSimilarItems('product_1', $itemCount);

Symfony 集成

在内核中注册 Symfony 包。

// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Endroid\PredictionIo\Bundle\PredictionIoBundle\EndroidPredictionIoBundle(),
    ];
}

默认参数可以通过配置进行覆盖。

endroid_prediction_io:
    event_server:
        url: http://localhost:7070
    apps:
        app_one:
            key: '...'
            engines:
                recommendation:
                    url: http://localhost:8000
                similarproduct:
                    url: http://localhost:8001
                viewedthenbought:
                    url: http://localhost:8002
                complementarypurchase:
                    url: http://localhost:8003
                productranking:
                    url: http://localhost:8004
                leadscoring:
                    url: http://localhost:8005
        app_two:
            key: '...'
            engines:
                complementarypurchase:
                    url: http://localhost:8006
                leadscoring:
                    url: http://localhost:8007
                    

现在您可以按照以下方式检索事件和引擎客户端。

/** @var EventClient $eventClient */
$eventClient = $this->get('endroid.prediction_io.app_one.event_client');

/** @var EngineClient $recommendationEngineClient */
$recommendationEngineClient = $this->get('endroid.prediction_io.app_one.recommendation.engine_client');

/** @var EngineClient $similarProductEngineClient */
$similarProductEngineCl![Recommendations](https://raw.githubusercontent.com/endroid/PredictionIo/master/assets/recommendations.png)ient = $this->get('endroid.prediction_io.app_one.similarproduct.engine_client');

Docker

存在许多用于运行 PredictionIo 服务器的 Docker 镜像。我个人使用了 spereio 镜像来创建一个图像,该图像创建、训练和部署推荐引擎,并启动 PIO 服务器。它启动了一个 cron,每 5 分钟训练一次模型。您可以在 这里 找到该镜像。

Vagrant box

PredictionIo 提供了一个包含开箱即用的 PredictionIo 服务器的 Vagrant box

版本控制

版本号遵循 MAJOR.MINOR.PATCH 方案。向后兼容的更改将尽量保持最小,但请注意,这些可能会发生。在生产中锁定您的依赖关系,并在升级时测试您的代码。

许可

此包遵循 MIT 许可证。有关完整的版权和许可信息,请查看与源代码一起分发的 LICENSE 文件。