2012-02-29 20 views
0

PHPでGoogle Prediction APIを使用しています。PHPを使用したGoogle Prediction APIのデータトレーニングでエラーが発生しました

OAuth 2.0を使用して承認が正常に完了しました。クラウド上のcsvファイルに自分のデータがあります。私はTrainingクラスのsetDataLocationメソッドを使用してその位置を与えました。しかし、トレーニング/データを挿入しながら、私は、次のエラーを得た:

Fatal error: Uncaught exception 'apiException' with message 'Unknown function: ->->insert()' in C:\xampp\htdocs\google-api-php-client\src\service\apiServiceResource.php:81 Stack trace: #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): TrainedmodelsServiceResource->insert(Object(apiPredictionService), Array) #2 {main} thrown in C:\xampp\htdocs\google-api-php-client\src\service\apiServiceResource.php on line 81

これは私のコードスニペットです:

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()); 
} 

私がさらに進行することができません。私は訓練し、次に予測機能を呼び出す予定です。

答えて

1

私は、PHPを使用して予測を行うためのテストプログラムを作成しましたが、これを実現できました。ここでは魔法のシーケンスがあります:

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))) 

$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レスポンスを表示します

関連する問題