google 预测 v 1.6 trainedmodels.update 函数添加一些空值
google prediction v 1.6 trainedmodels.update function add some empty values
我正在尝试使用 Google 预测 API,我已经通过 API 调用添加了一个新模型,现在我正在尝试通过 [=27= 对其进行训练] 更新来电。
我设法更新了它,但由于某些原因,一些数据丢失了,例如,当我通过 Google API 的资源管理器 运行 trainedmodels.analyze 时,我看到一些值是空白的:
{
"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"
}
}
]
}
}
我通过 Google PHP 客户端拨打电话:
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()
]);
}
}
$ga_details
的值是我预先定义的(用于测试):
$ga_details = [
"user_type" => "Returning Visitor",
"device_category" => "mobile",
"source" => "google",
"campaign" => "organic",
"medium" => "(not set)",
"ad_group" => "(not set)",
];
知道为什么 user_type, medium and ad_group
在我的模型中是空的吗? (我试着去掉 () 并去掉空格,但没有用)。
已解决!
有趣的是,我总是发现自己在回答自己,但如果我能帮助别人,为什么不呢? :)
我通过使用 PHP urlencode()
方法对我传递的值进行编码解决了这个问题。
我正在尝试使用 Google 预测 API,我已经通过 API 调用添加了一个新模型,现在我正在尝试通过 [=27= 对其进行训练] 更新来电。 我设法更新了它,但由于某些原因,一些数据丢失了,例如,当我通过 Google API 的资源管理器 运行 trainedmodels.analyze 时,我看到一些值是空白的:
{
"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"
}
}
]
}
}
我通过 Google PHP 客户端拨打电话:
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()
]);
}
}
$ga_details
的值是我预先定义的(用于测试):
$ga_details = [
"user_type" => "Returning Visitor",
"device_category" => "mobile",
"source" => "google",
"campaign" => "organic",
"medium" => "(not set)",
"ad_group" => "(not set)",
];
知道为什么 user_type, medium and ad_group
在我的模型中是空的吗? (我试着去掉 () 并去掉空格,但没有用)。
已解决!
有趣的是,我总是发现自己在回答自己,但如果我能帮助别人,为什么不呢? :)
我通过使用 PHP urlencode()
方法对我传递的值进行编码解决了这个问题。