I have correctly and successfully set up training data and can run a prediction with expected outcomes if I use the API explorer interface in a certain way for the Google prediction API.
I can also run a single feature prediction from localhost based on the examples given by google in php.
My training data has 51 features that I want to run the prediction against. The model is sound and has returned an unbiased 92% accuracy rating. I have no issue with the trained model which is based on 25000 instances.
In a somewhat related question Marc Cohen gave the following example in php to run a prediction which works perfectly for the languages demo file or any single feature prediction.
//------------------
I just wrote a test program to make a prediction using PHP and was able to get this working. Here's the magic sequence:
$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));
This displays the unformatted JSON response from the prediction request, like so:
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 ) ) )
//--------------------
The note he has made re multi feature ie: // 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));
implies to me that one only needs to pass the $predictionText variable as "Feature_1","Feature_2","Feature_3",....."Feature_N" and one is good to go.
The data I am using is mainly numeric. eg: 69,13,10,9,101,69,94,96,96,96......9 and I have tried it with and without quotes but consistently get the same prediction back.
If I use the API explorer and enter a new array element into it for all the data to predict ie:
"input": {
"csvInstance": [
"84",
"63",
"30",
"30",
...........
it will predict the correct answer.
If I use the Explorer and enter data as per Marcs example. ie: "84","63","30","30","207","83","87","94","94","94","94","94","94","94","38","57","143","144","164","164","164","164","164".........
the same data will give totally different results with this second method always returning the same result.
Obviously I am doing something wrong here. I have tried all the php json encode options and anything else I can think of to format this correctly to work in my php script or indeed in the API explorer but to no avail.
Can anyone please let me know how to format the $predictionText
properly.
My code below. ( I have tried with and without quotes and purely numeric )
$predictionText = '84,63,30,30,207,83,87,94,94,94,94,94,94,94,38,57,143,144,164,164,164,164,164,"New Moon",115,221,31,62,-14,-106,-43,-4,43,-174,-224,25,93,142,78,87,29,-65,44,33,34,19,16,14,13,12,11';
$predictionData = new Google_InputInput();
$predictionData->setCsvInstance(array($predictionText) );
$input = new Google_Input();
$input->setInput($predictionData);
$result = $predictionService->trainedmodels->predict($id, $input);
print("</div><br><br><h2>Prediction Result:</h2>");
print_r($result);
Thank You.