提问人:Inigo EC 提问时间:5/16/2023 更新时间:10/24/2023 访问量:85
在Laravel项目中找不到Rubix ML类
Rubix ML class not found in Laravel project
问:
我已经按照此处指定的方式进行了安装:https://docs.rubixml.com/2.0/installation.htmlRubix ML
composer
我创建了以下代码:
<?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
我是否缺少命名空间或其他东西?
答:
0赞
Ayder Acivaap
10/24/2023
#1
不要忘记在代码的开头,在第一个“use”语句之前包含以下行:
include __DIR__ . '/vendor/autoload.php';
评论