【问题标题】:Recommendation Engine with PHP-ML and regression带有 PHP-ML 和回归的推荐引擎
【发布时间】:2018-11-07 02:30:11
【问题描述】:

当我想向当前客户推荐一些商品时,我尝试了解如何使用 PHP-ML

我的数据集(编号只是行号):

  1. 产品 1 与产品 2 一起购买
  2. 产品 1 与产品 2 一起购买
  3. 产品 1 与产品 3 一起购买
  4. 产品 1 与产品 2 一起购买
  5. 产品 2 与产品 4 一起购买
  6. 产品 Y.. 与产品 X.. 一起购买

作为我过去购买过产品 1 的客户。所以通常我会在我的推荐框中期待产品 2,因为 3 人与产品 1 一起购买了它。

我想我需要一些回归算法来给我产品 X 和产品 Y 之间的一些相关值。

我想过线性 SVR 算法,但我不知道如何训练它?

// Step 1: Load the Dataset
// Step 2: Prepare the Dataset
// Step 3: Generate the training/testing Dataset
$samples = [[1,2], [1,2], [1,3], [1,2], [2,4], [X,Y..]];
$targets = [?, ?, ? , ? , ? , ?];

$regression = new LeastSquares();
// Step 4: Train the classifier
$regression->train($samples, $targets);


echo $regression->predict([1,2]);

在我看来,我应该得到一些价值,例如 0.25 -> 25% 的购买产品 1 的客户也购买了产品 2。然后我可以订购我的预测并将订单放在我的推荐框中。 我的主要问题是,我应该用什么来做火车?我理解完全错误的东西吗?

谢谢

【问题讨论】:

    标签: php machine-learning linear-regression php-ml


    【解决方案1】:

    首先,您在这里不需要线性回归,如果您需要 you would have to convert the categorical data in order to do a numeric prediction。 通常您会使用虚拟变量,这意味着您的表格将从:

    | Product A | Product B |
    |-----------|-----------|
    |         1 |         2 |
    |         1 |         2 |
    |         1 |         3 |
    |         1 |         2 |
    |         2 |         4 |
    

    类似于:

    | Product 1  | Product 2 | Product 3 | Product 4 |
    |------------|-----------|-----------|-----------|
    |          1 |         1 |         0 |         0 |
    |          1 |         1 |         0 |         0 |
    |          1 |         0 |         1 |         0 |
    |          1 |         1 |         0 |         0 |
    |          0 |         1 |         0 |         1 |
    

    请参阅https://datascience.stackexchange.com/questions/28306/transform-categorical-variables-into-numerical 了解更多信息。 遗憾的是,我认为 PHP-ML 目前不支持分类数据编码。如果你不转换 您可能会得到 1.6 作为预测的分类数据,这并不意味着任何有用的东西。

    但是在 PHP-ML 中有一种更简单的方法可以做到这一点。您可以使用 Apriori 关联器。这样可以 了解哪些关联更频繁并预测它们。在下文中,您可以看到这一点。

    use Phpml\Association\Apriori;
    
    $samples = [[1,2], [1,2], [1,3], [1,2], [2,4]];
    $labels  = [];
    
    
    $associator = new Apriori($support = 0.5, $confidence = 0.5);
    $associator->train($samples, $labels);
    
    var_export($associator->predict([1]));
    // outputs  [[ 2 ]];  The right prediction!
    

    此外,当从事机器学习工作时,可以将数据拆分为所谓的训练 和测试集。这样您就可以直接测试您的 ML 模型。 It is also implemented in PHP-ML

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 2019-09-25
      • 1970-01-01
      • 2012-04-03
      • 2012-03-02
      • 2010-09-25
      相关资源
      最近更新 更多