Laravel 项目中未找到 Rubix ML 类

问题描述 投票:0回答:1

我已经使用此处指定的

Rubix ML
安装了
composer
https://docs.rubixml.com/2.0/installation.html

我创建了以下代码:

<?php

use Illuminate\Console\Command;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Transformers\TextNormalizer;
use Rubix\ML\Transformers\WordCountVectorizer;
use Rubix\ML\Transformers\TfIdfTransformer;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Classifiers\KNearestNeighbors;
use Rubix\ML\CrossValidation\Reports\MulticlassBreakdown;
use Rubix\ML\CrossValidation\Reports\ConfusionMatrix;
class MLModel {
    public function predict($inputText)
    {
        // Load the trained model
        $modelPath = '/var/www/gdpr/tests/model.rbx';
        $modelData = file_get_contents($modelPath);
        $estimator = unserialize($modelData);

        // Preprocess the input text
        $textNormalizer = new TextNormalizer();
        $wordCountVectorizer = new WordCountVectorizer(10000);
        $tfIdfTransformer = new TfIdfTransformer();

        $inputText = $textNormalizer->transform([$inputText]);
        $inputText = $wordCountVectorizer->fit($inputText)->transform($inputText);
        $inputText = $tfIdfTransformer->fit($inputText)->transform($inputText);

        // Make a prediction
        $prediction = $estimator->predictSample($inputText[0]);

        return $prediction;
    }
}

$mlModel = new MLModel();

echo "Please enter your text: ";
$inputText = readline();
$prediction = $mlModel->predict($inputText);

echo "Prediction: {$prediction}";

?>

但是我收到以下错误:

PHP Fatal error:  Uncaught Error: Class "Rubix\ML\Transformers\TextNormalizer" not found in /var/www/myproject/tests/predict.php:23

我检查了

vendor
文件夹,可以在指定的
TextNormalizer
中看到
namespace
类。

该文件位于

(base_path)/tests
文件夹中。我尝试使用控制器命名空间将文件移动到控制器文件夹,但这不起作用。

我是否缺少名称空间或其他什么?

laravel namespaces
1个回答
0
投票

不要忘记在第一个“use”语句之前在代码开头包含此行:

include __DIR__ . '/vendor/autoload.php';
© www.soinside.com 2019 - 2024. All rights reserved.