i'm trying to use Google Prediction API, I have added a new model via API call and now i'm trying to train it via API update calls. i managed to update it but from some reason some data is missing for example when i run trainedmodels.analyze via Google API's explorer i see some values are blank :
{
"kind": "prediction#analyze",
"id": "my_model_id",
"dataDescription": {
"outputFeature": {
"text": [
{
"value": "lost",
"count": "1"
},
{
"value": "won",
"count": "4"
}
]
},
"features": [
{
"index": "0",
"text": {
"count": "5"
}
},
{
"index": "1",
"categorical": {
"count": "5",
"values": [
{
"value": "google",
"count": "3"
},
{
"value": "mobile",
"count": "2"
}
]
}
},
{
"index": "2",
"categorical": {
"count": "5",
"values": [
{
"value": "google",
"count": "2"
},
{
"value": "organic",
"count": "3"
}
]
}
},
{
"index": "3",
"text": {
"count": "5"
}
},
{
"index": "4",
"text": {
"count": "5"
}
},
{
"index": "5",
"text": {
"count": "2"
}
}
]
}
}
I make the call via Google PHP client like so:
private function updateModel($ga_details,$label,$model_name)
{
$csv_instance = [];
$csv_instance[0] = $ga_details['user_type'];
$csv_instance[1] = $ga_details['device_category'];
$csv_instance[2] = $ga_details['source'];
$csv_instance[3] = $ga_details['campaign'];
$csv_instance[4] = $ga_details['medium'];
$csv_instance[5] = $ga_details['ad_group'];
try{
$prediction = new \Google_Service_Prediction($this->client);
$update = new \Google_Service_Prediction_Update();
$update->setCsvInstance($csv_instance);
$update->setOutput($label);
$res = $prediction->trainedmodels->update(config('prediction.PROJECT_ID'),$model_name,$update);
return ($res && $res->id) ? $res->id : false;
}catch (\Google_Service_Exception $e){
return Response::json([
'custom' => 'could not updateModel',
'message' => $e->getMessage(),
'code' => $e->getCode(),
'errors' => $e->getErrors()
]);
}
}
the values for $ga_details
are pre-defined by me (for tests):
$ga_details = [
"user_type" => "Returning Visitor",
"device_category" => "mobile",
"source" => "google",
"campaign" => "organic",
"medium" => "(not set)",
"ad_group" => "(not set)",
];
any idea why is user_type, medium and ad_group
is empty in my model? (i tried to take off the () and trin the white spaces but it didn't help).
Solved!
Funny i'm always finding myself answering to myself, but if I can help someone, why not? :)
I fixed this problem with encoding the values i pass in using PHP urlencode()
method.