【问题标题】:Error in training data in Google Prediction API using PHP使用 PHP 在 Google Prediction API 中训练数据时出错
【发布时间】:2012-03-18 22:44:24
【问题描述】:

我在 PHP 中使用 Google 预测 API。

使用 OAuth 2.0 成功完成授权。我将数据保存在云端的 csv 文件中。我在 Training 类中使用 setDataLocation 方法给出了它的位置。但是在训练/插入数据时出现以下错误:

致命错误:未捕获的异常“apiException”,消息“未知” 函数:->->insert()' in C:\xampp\htdocs\google-api-php-client\src\service\apiServiceResource.php:81 堆栈跟踪:#0 C:\xampp\htdocs\google-api-php-client\src\contrib\apiPredictionService.php(60): apiServiceResource->__call('insert', Array) #1 C:\xampp\htdocs\google-api-php-client\examples\analytics\new2.php(51): 训练模型服务资源->插入(对象(apiPredictionService), Array) #2 {main} 投入 C:\xampp\htdocs\google-api-php-client\src\service\apiServiceResource.php 在第 81 行

这是我的代码 sn-p:

if ($client->getAccessToken()) {
    $data = array();
    $buzzy = new Training();
    $predictionService = new apiPredictionService($client);
    $trainedmodels = $predictionService->trainedmodels;
    $buzzzy = new TrainedmodelsServiceResource();
    $me = $buzzy->setStorageDataLocation('my_data.csv');
    $mee = $buzzy->getStorageDataLocation();
    // $ma = $buzzy->getTrainingStatus();
    $setid_in = $buzzy->setId($buzzy->getStorageDataLocation());
    $setid_out = $buzzy->getId();
    echo $setid_out;
    //print_r($predictionService);
    //$insert_1 = $buzzzy->insert($buzzy,array());

    // This is line 81 in my code:
    $insert2=$trainedmodels->insert($predictionService,array());
}

我无法继续进行。我打算训练然后调用预测函数。

【问题讨论】:

    标签: php google-prediction


    【解决方案1】:

    我刚刚编写了一个测试程序来使用 PHP 进行预测,并且能够使其正常工作。这是神奇的序列:

       $id = "your-model-id-goes-here";
       $predictionText = "This is a test";
       $predictionData = new InputInput();
       $predictionData->setCsvInstance(array($predictionText));
       // My model takes a single feature but if your model needs more than one 
       // feature, simply include more values in the csvInstance array, like this...
       // $predictionData->setCsvInstance(array($data1, $data2, ..., $dataN));
       $input = new Input();
       $input->setInput($predictionData);
       print_r($predictionService->trainedmodels->predict($id, $input));
    

    这会显示来自预测请求的未格式化 JSON 响应,如下所示:

    Array ( [kind] => prediction#output [id] => languages [selfLink] =>    
    https://www.googleapis.com/prediction/v1.4/trainedmodels/languages/predict 
    [outputLabel] => French [outputMulti] => Array ( [0] => Array ( [label] => 
    English [score] => 0.333297 ) [1] => Array ( [label] => French [score] => 
    0.339412 ) [2] => Array ( [label] => Spanish [score] => 0.327291 ) ) )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 2015-04-20
      • 1970-01-01
      相关资源
      最近更新 更多