googlepredictionv1.6 trainedmodels.update函数添加了一些空值



我正在尝试使用Google Prediction API,我已经通过API调用添加了一个新模型,现在我正在尝试通过API更新调用来训练它。我设法更新了它,但由于某些原因,一些数据丢失了。例如,当我通过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"
    }
   }
  ]
 }
}

我通过谷歌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在我的模型中是空的吗?(我试着去掉()和trin空格,但无济于事)。

已解决

有趣的是,我总是发现自己在回答自己,但如果我能帮助别人,为什么不呢?:)我使用PHP urlencode()方法对传入的值进行编码,解决了这个问题。

相关内容

  • 没有找到相关文章

最新更新