prediction-gen.go 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. // Package prediction provides access to the Prediction API.
  2. //
  3. // See https://developers.google.com/prediction/docs/developer-guide
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/prediction/v1.4"
  8. // ...
  9. // predictionService, err := prediction.New(oauthHttpClient)
  10. package prediction // import "google.golang.org/api/prediction/v1.4"
  11. import (
  12. "bytes"
  13. "encoding/json"
  14. "errors"
  15. "fmt"
  16. context "golang.org/x/net/context"
  17. ctxhttp "golang.org/x/net/context/ctxhttp"
  18. gensupport "google.golang.org/api/gensupport"
  19. googleapi "google.golang.org/api/googleapi"
  20. "io"
  21. "net/http"
  22. "net/url"
  23. "strconv"
  24. "strings"
  25. )
  26. // Always reference these packages, just in case the auto-generated code
  27. // below doesn't.
  28. var _ = bytes.NewBuffer
  29. var _ = strconv.Itoa
  30. var _ = fmt.Sprintf
  31. var _ = json.NewDecoder
  32. var _ = io.Copy
  33. var _ = url.Parse
  34. var _ = gensupport.MarshalJSON
  35. var _ = googleapi.Version
  36. var _ = errors.New
  37. var _ = strings.Replace
  38. var _ = context.Canceled
  39. var _ = ctxhttp.Do
  40. const apiId = "prediction:v1.4"
  41. const apiName = "prediction"
  42. const apiVersion = "v1.4"
  43. const basePath = "https://www.googleapis.com/prediction/v1.4/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // Manage your data and permissions in Google Cloud Storage
  47. DevstorageFullControlScope = "https://www.googleapis.com/auth/devstorage.full_control"
  48. // View your data in Google Cloud Storage
  49. DevstorageReadOnlyScope = "https://www.googleapis.com/auth/devstorage.read_only"
  50. // Manage your data in Google Cloud Storage
  51. DevstorageReadWriteScope = "https://www.googleapis.com/auth/devstorage.read_write"
  52. // Manage your data in the Google Prediction API
  53. PredictionScope = "https://www.googleapis.com/auth/prediction"
  54. )
  55. func New(client *http.Client) (*Service, error) {
  56. if client == nil {
  57. return nil, errors.New("client is nil")
  58. }
  59. s := &Service{client: client, BasePath: basePath}
  60. s.Hostedmodels = NewHostedmodelsService(s)
  61. s.Trainedmodels = NewTrainedmodelsService(s)
  62. return s, nil
  63. }
  64. type Service struct {
  65. client *http.Client
  66. BasePath string // API endpoint base URL
  67. UserAgent string // optional additional User-Agent fragment
  68. Hostedmodels *HostedmodelsService
  69. Trainedmodels *TrainedmodelsService
  70. }
  71. func (s *Service) userAgent() string {
  72. if s.UserAgent == "" {
  73. return googleapi.UserAgent
  74. }
  75. return googleapi.UserAgent + " " + s.UserAgent
  76. }
  77. func NewHostedmodelsService(s *Service) *HostedmodelsService {
  78. rs := &HostedmodelsService{s: s}
  79. return rs
  80. }
  81. type HostedmodelsService struct {
  82. s *Service
  83. }
  84. func NewTrainedmodelsService(s *Service) *TrainedmodelsService {
  85. rs := &TrainedmodelsService{s: s}
  86. return rs
  87. }
  88. type TrainedmodelsService struct {
  89. s *Service
  90. }
  91. type Input struct {
  92. // Input: Input to the model for a prediction
  93. Input *InputInput `json:"input,omitempty"`
  94. // ForceSendFields is a list of field names (e.g. "Input") to
  95. // unconditionally include in API requests. By default, fields with
  96. // empty values are omitted from API requests. However, any non-pointer,
  97. // non-interface field appearing in ForceSendFields will be sent to the
  98. // server regardless of whether the field is empty or not. This may be
  99. // used to include empty fields in Patch requests.
  100. ForceSendFields []string `json:"-"`
  101. }
  102. func (s *Input) MarshalJSON() ([]byte, error) {
  103. type noMethod Input
  104. raw := noMethod(*s)
  105. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  106. }
  107. // InputInput: Input to the model for a prediction
  108. type InputInput struct {
  109. // CsvInstance: A list of input features, these can be strings or
  110. // doubles.
  111. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  112. // ForceSendFields is a list of field names (e.g. "CsvInstance") to
  113. // unconditionally include in API requests. By default, fields with
  114. // empty values are omitted from API requests. However, any non-pointer,
  115. // non-interface field appearing in ForceSendFields will be sent to the
  116. // server regardless of whether the field is empty or not. This may be
  117. // used to include empty fields in Patch requests.
  118. ForceSendFields []string `json:"-"`
  119. }
  120. func (s *InputInput) MarshalJSON() ([]byte, error) {
  121. type noMethod InputInput
  122. raw := noMethod(*s)
  123. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  124. }
  125. type Output struct {
  126. // Id: The unique name for the predictive model.
  127. Id string `json:"id,omitempty"`
  128. // Kind: What kind of resource this is.
  129. Kind string `json:"kind,omitempty"`
  130. // OutputLabel: The most likely class label [Categorical models only].
  131. OutputLabel string `json:"outputLabel,omitempty"`
  132. // OutputMulti: A list of class labels with their estimated
  133. // probabilities [Categorical models only].
  134. OutputMulti []*OutputOutputMulti `json:"outputMulti,omitempty"`
  135. // OutputValue: The estimated regression value [Regression models only].
  136. OutputValue float64 `json:"outputValue,omitempty"`
  137. // SelfLink: A URL to re-request this resource.
  138. SelfLink string `json:"selfLink,omitempty"`
  139. // ServerResponse contains the HTTP response code and headers from the
  140. // server.
  141. googleapi.ServerResponse `json:"-"`
  142. // ForceSendFields is a list of field names (e.g. "Id") to
  143. // unconditionally include in API requests. By default, fields with
  144. // empty values are omitted from API requests. However, any non-pointer,
  145. // non-interface field appearing in ForceSendFields will be sent to the
  146. // server regardless of whether the field is empty or not. This may be
  147. // used to include empty fields in Patch requests.
  148. ForceSendFields []string `json:"-"`
  149. }
  150. func (s *Output) MarshalJSON() ([]byte, error) {
  151. type noMethod Output
  152. raw := noMethod(*s)
  153. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  154. }
  155. type OutputOutputMulti struct {
  156. // Label: The class label.
  157. Label string `json:"label,omitempty"`
  158. // Score: The probability of the class label.
  159. Score float64 `json:"score,omitempty"`
  160. // ForceSendFields is a list of field names (e.g. "Label") to
  161. // unconditionally include in API requests. By default, fields with
  162. // empty values are omitted from API requests. However, any non-pointer,
  163. // non-interface field appearing in ForceSendFields will be sent to the
  164. // server regardless of whether the field is empty or not. This may be
  165. // used to include empty fields in Patch requests.
  166. ForceSendFields []string `json:"-"`
  167. }
  168. func (s *OutputOutputMulti) MarshalJSON() ([]byte, error) {
  169. type noMethod OutputOutputMulti
  170. raw := noMethod(*s)
  171. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  172. }
  173. type Training struct {
  174. // DataAnalysis: Data Analysis.
  175. DataAnalysis *TrainingDataAnalysis `json:"dataAnalysis,omitempty"`
  176. // Id: The unique name for the predictive model.
  177. Id string `json:"id,omitempty"`
  178. // Kind: What kind of resource this is.
  179. Kind string `json:"kind,omitempty"`
  180. // ModelInfo: Model metadata.
  181. ModelInfo *TrainingModelInfo `json:"modelInfo,omitempty"`
  182. // SelfLink: A URL to re-request this resource.
  183. SelfLink string `json:"selfLink,omitempty"`
  184. // StorageDataLocation: Google storage location of the training data
  185. // file.
  186. StorageDataLocation string `json:"storageDataLocation,omitempty"`
  187. // StoragePMMLLocation: Google storage location of the preprocessing
  188. // pmml file.
  189. StoragePMMLLocation string `json:"storagePMMLLocation,omitempty"`
  190. // StoragePMMLModelLocation: Google storage location of the pmml model
  191. // file.
  192. StoragePMMLModelLocation string `json:"storagePMMLModelLocation,omitempty"`
  193. // TrainingStatus: The current status of the training job. This can be
  194. // one of following: RUNNING; DONE; ERROR; ERROR: TRAINING JOB NOT FOUND
  195. TrainingStatus string `json:"trainingStatus,omitempty"`
  196. // Utility: A class weighting function, which allows the importance
  197. // weights for class labels to be specified [Categorical models only].
  198. Utility []*TrainingUtility `json:"utility,omitempty"`
  199. // ServerResponse contains the HTTP response code and headers from the
  200. // server.
  201. googleapi.ServerResponse `json:"-"`
  202. // ForceSendFields is a list of field names (e.g. "DataAnalysis") to
  203. // unconditionally include in API requests. By default, fields with
  204. // empty values are omitted from API requests. However, any non-pointer,
  205. // non-interface field appearing in ForceSendFields will be sent to the
  206. // server regardless of whether the field is empty or not. This may be
  207. // used to include empty fields in Patch requests.
  208. ForceSendFields []string `json:"-"`
  209. }
  210. func (s *Training) MarshalJSON() ([]byte, error) {
  211. type noMethod Training
  212. raw := noMethod(*s)
  213. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  214. }
  215. // TrainingDataAnalysis: Data Analysis.
  216. type TrainingDataAnalysis struct {
  217. Warnings []string `json:"warnings,omitempty"`
  218. // ForceSendFields is a list of field names (e.g. "Warnings") to
  219. // unconditionally include in API requests. By default, fields with
  220. // empty values are omitted from API requests. However, any non-pointer,
  221. // non-interface field appearing in ForceSendFields will be sent to the
  222. // server regardless of whether the field is empty or not. This may be
  223. // used to include empty fields in Patch requests.
  224. ForceSendFields []string `json:"-"`
  225. }
  226. func (s *TrainingDataAnalysis) MarshalJSON() ([]byte, error) {
  227. type noMethod TrainingDataAnalysis
  228. raw := noMethod(*s)
  229. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  230. }
  231. // TrainingModelInfo: Model metadata.
  232. type TrainingModelInfo struct {
  233. // ClassWeightedAccuracy: Estimated accuracy of model taking utility
  234. // weights into account [Categorical models only].
  235. ClassWeightedAccuracy float64 `json:"classWeightedAccuracy,omitempty"`
  236. // ClassificationAccuracy: A number between 0.0 and 1.0, where 1.0 is
  237. // 100% accurate. This is an estimate, based on the amount and quality
  238. // of the training data, of the estimated prediction accuracy. You can
  239. // use this is a guide to decide whether the results are accurate enough
  240. // for your needs. This estimate will be more reliable if your real
  241. // input data is similar to your training data [Categorical models
  242. // only].
  243. ClassificationAccuracy float64 `json:"classificationAccuracy,omitempty"`
  244. // ConfusionMatrix: An output confusion matrix. This shows an estimate
  245. // for how this model will do in predictions. This is first indexed by
  246. // the true class label. For each true class label, this provides a pair
  247. // {predicted_label, count}, where count is the estimated number of
  248. // times the model will predict the predicted label given the true
  249. // label. Will not output if more then 100 classes [Categorical models
  250. // only].
  251. ConfusionMatrix *TrainingModelInfoConfusionMatrix `json:"confusionMatrix,omitempty"`
  252. // ConfusionMatrixRowTotals: A list of the confusion matrix row totals
  253. ConfusionMatrixRowTotals *TrainingModelInfoConfusionMatrixRowTotals `json:"confusionMatrixRowTotals,omitempty"`
  254. // MeanSquaredError: An estimated mean squared error. The can be used to
  255. // measure the quality of the predicted model [Regression models only].
  256. MeanSquaredError float64 `json:"meanSquaredError,omitempty"`
  257. // ModelType: Type of predictive model (CLASSIFICATION or REGRESSION)
  258. ModelType string `json:"modelType,omitempty"`
  259. // NumberInstances: Number of valid data instances used in the trained
  260. // model.
  261. NumberInstances int64 `json:"numberInstances,omitempty,string"`
  262. // NumberLabels: Number of class labels in the trained model
  263. // [Categorical models only].
  264. NumberLabels int64 `json:"numberLabels,omitempty,string"`
  265. // ForceSendFields is a list of field names (e.g.
  266. // "ClassWeightedAccuracy") to unconditionally include in API requests.
  267. // By default, fields with empty values are omitted from API requests.
  268. // However, any non-pointer, non-interface field appearing in
  269. // ForceSendFields will be sent to the server regardless of whether the
  270. // field is empty or not. This may be used to include empty fields in
  271. // Patch requests.
  272. ForceSendFields []string `json:"-"`
  273. }
  274. func (s *TrainingModelInfo) MarshalJSON() ([]byte, error) {
  275. type noMethod TrainingModelInfo
  276. raw := noMethod(*s)
  277. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  278. }
  279. // TrainingModelInfoConfusionMatrix: An output confusion matrix. This
  280. // shows an estimate for how this model will do in predictions. This is
  281. // first indexed by the true class label. For each true class label,
  282. // this provides a pair {predicted_label, count}, where count is the
  283. // estimated number of times the model will predict the predicted label
  284. // given the true label. Will not output if more then 100 classes
  285. // [Categorical models only].
  286. type TrainingModelInfoConfusionMatrix struct {
  287. }
  288. // TrainingModelInfoConfusionMatrixRowTotals: A list of the confusion
  289. // matrix row totals
  290. type TrainingModelInfoConfusionMatrixRowTotals struct {
  291. }
  292. // TrainingUtility: Class label (string).
  293. type TrainingUtility struct {
  294. }
  295. type Update struct {
  296. // CsvInstance: The input features for this instance
  297. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  298. // Label: The class label of this instance
  299. Label string `json:"label,omitempty"`
  300. // Output: The generic output value - could be regression value or class
  301. // label
  302. Output string `json:"output,omitempty"`
  303. // ForceSendFields is a list of field names (e.g. "CsvInstance") to
  304. // unconditionally include in API requests. By default, fields with
  305. // empty values are omitted from API requests. However, any non-pointer,
  306. // non-interface field appearing in ForceSendFields will be sent to the
  307. // server regardless of whether the field is empty or not. This may be
  308. // used to include empty fields in Patch requests.
  309. ForceSendFields []string `json:"-"`
  310. }
  311. func (s *Update) MarshalJSON() ([]byte, error) {
  312. type noMethod Update
  313. raw := noMethod(*s)
  314. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  315. }
  316. // method id "prediction.hostedmodels.predict":
  317. type HostedmodelsPredictCall struct {
  318. s *Service
  319. hostedModelName string
  320. input *Input
  321. urlParams_ gensupport.URLParams
  322. ctx_ context.Context
  323. }
  324. // Predict: Submit input and request an output against a hosted model.
  325. func (r *HostedmodelsService) Predict(hostedModelName string, input *Input) *HostedmodelsPredictCall {
  326. c := &HostedmodelsPredictCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  327. c.hostedModelName = hostedModelName
  328. c.input = input
  329. return c
  330. }
  331. // Fields allows partial responses to be retrieved. See
  332. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  333. // for more information.
  334. func (c *HostedmodelsPredictCall) Fields(s ...googleapi.Field) *HostedmodelsPredictCall {
  335. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  336. return c
  337. }
  338. // Context sets the context to be used in this call's Do method. Any
  339. // pending HTTP request will be aborted if the provided context is
  340. // canceled.
  341. func (c *HostedmodelsPredictCall) Context(ctx context.Context) *HostedmodelsPredictCall {
  342. c.ctx_ = ctx
  343. return c
  344. }
  345. func (c *HostedmodelsPredictCall) doRequest(alt string) (*http.Response, error) {
  346. var body io.Reader = nil
  347. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  348. if err != nil {
  349. return nil, err
  350. }
  351. ctype := "application/json"
  352. c.urlParams_.Set("alt", alt)
  353. urls := googleapi.ResolveRelative(c.s.BasePath, "hostedmodels/{hostedModelName}/predict")
  354. urls += "?" + c.urlParams_.Encode()
  355. req, _ := http.NewRequest("POST", urls, body)
  356. googleapi.Expand(req.URL, map[string]string{
  357. "hostedModelName": c.hostedModelName,
  358. })
  359. req.Header.Set("Content-Type", ctype)
  360. req.Header.Set("User-Agent", c.s.userAgent())
  361. if c.ctx_ != nil {
  362. return ctxhttp.Do(c.ctx_, c.s.client, req)
  363. }
  364. return c.s.client.Do(req)
  365. }
  366. // Do executes the "prediction.hostedmodels.predict" call.
  367. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  368. // code is an error. Response headers are in either
  369. // *Output.ServerResponse.Header or (if a response was returned at all)
  370. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  371. // check whether the returned error was because http.StatusNotModified
  372. // was returned.
  373. func (c *HostedmodelsPredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  374. gensupport.SetOptions(c.urlParams_, opts...)
  375. res, err := c.doRequest("json")
  376. if res != nil && res.StatusCode == http.StatusNotModified {
  377. if res.Body != nil {
  378. res.Body.Close()
  379. }
  380. return nil, &googleapi.Error{
  381. Code: res.StatusCode,
  382. Header: res.Header,
  383. }
  384. }
  385. if err != nil {
  386. return nil, err
  387. }
  388. defer googleapi.CloseBody(res)
  389. if err := googleapi.CheckResponse(res); err != nil {
  390. return nil, err
  391. }
  392. ret := &Output{
  393. ServerResponse: googleapi.ServerResponse{
  394. Header: res.Header,
  395. HTTPStatusCode: res.StatusCode,
  396. },
  397. }
  398. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  399. return nil, err
  400. }
  401. return ret, nil
  402. // {
  403. // "description": "Submit input and request an output against a hosted model.",
  404. // "httpMethod": "POST",
  405. // "id": "prediction.hostedmodels.predict",
  406. // "parameterOrder": [
  407. // "hostedModelName"
  408. // ],
  409. // "parameters": {
  410. // "hostedModelName": {
  411. // "description": "The name of a hosted model.",
  412. // "location": "path",
  413. // "required": true,
  414. // "type": "string"
  415. // }
  416. // },
  417. // "path": "hostedmodels/{hostedModelName}/predict",
  418. // "request": {
  419. // "$ref": "Input"
  420. // },
  421. // "response": {
  422. // "$ref": "Output"
  423. // },
  424. // "scopes": [
  425. // "https://www.googleapis.com/auth/prediction"
  426. // ]
  427. // }
  428. }
  429. // method id "prediction.trainedmodels.delete":
  430. type TrainedmodelsDeleteCall struct {
  431. s *Service
  432. id string
  433. urlParams_ gensupport.URLParams
  434. ctx_ context.Context
  435. }
  436. // Delete: Delete a trained model.
  437. func (r *TrainedmodelsService) Delete(id string) *TrainedmodelsDeleteCall {
  438. c := &TrainedmodelsDeleteCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  439. c.id = id
  440. return c
  441. }
  442. // Fields allows partial responses to be retrieved. See
  443. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  444. // for more information.
  445. func (c *TrainedmodelsDeleteCall) Fields(s ...googleapi.Field) *TrainedmodelsDeleteCall {
  446. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  447. return c
  448. }
  449. // Context sets the context to be used in this call's Do method. Any
  450. // pending HTTP request will be aborted if the provided context is
  451. // canceled.
  452. func (c *TrainedmodelsDeleteCall) Context(ctx context.Context) *TrainedmodelsDeleteCall {
  453. c.ctx_ = ctx
  454. return c
  455. }
  456. func (c *TrainedmodelsDeleteCall) doRequest(alt string) (*http.Response, error) {
  457. var body io.Reader = nil
  458. c.urlParams_.Set("alt", alt)
  459. urls := googleapi.ResolveRelative(c.s.BasePath, "trainedmodels/{id}")
  460. urls += "?" + c.urlParams_.Encode()
  461. req, _ := http.NewRequest("DELETE", urls, body)
  462. googleapi.Expand(req.URL, map[string]string{
  463. "id": c.id,
  464. })
  465. req.Header.Set("User-Agent", c.s.userAgent())
  466. if c.ctx_ != nil {
  467. return ctxhttp.Do(c.ctx_, c.s.client, req)
  468. }
  469. return c.s.client.Do(req)
  470. }
  471. // Do executes the "prediction.trainedmodels.delete" call.
  472. func (c *TrainedmodelsDeleteCall) Do(opts ...googleapi.CallOption) error {
  473. gensupport.SetOptions(c.urlParams_, opts...)
  474. res, err := c.doRequest("json")
  475. if err != nil {
  476. return err
  477. }
  478. defer googleapi.CloseBody(res)
  479. if err := googleapi.CheckResponse(res); err != nil {
  480. return err
  481. }
  482. return nil
  483. // {
  484. // "description": "Delete a trained model.",
  485. // "httpMethod": "DELETE",
  486. // "id": "prediction.trainedmodels.delete",
  487. // "parameterOrder": [
  488. // "id"
  489. // ],
  490. // "parameters": {
  491. // "id": {
  492. // "description": "The unique name for the predictive model.",
  493. // "location": "path",
  494. // "required": true,
  495. // "type": "string"
  496. // }
  497. // },
  498. // "path": "trainedmodels/{id}",
  499. // "scopes": [
  500. // "https://www.googleapis.com/auth/prediction"
  501. // ]
  502. // }
  503. }
  504. // method id "prediction.trainedmodels.get":
  505. type TrainedmodelsGetCall struct {
  506. s *Service
  507. id string
  508. urlParams_ gensupport.URLParams
  509. ifNoneMatch_ string
  510. ctx_ context.Context
  511. }
  512. // Get: Check training status of your model.
  513. func (r *TrainedmodelsService) Get(id string) *TrainedmodelsGetCall {
  514. c := &TrainedmodelsGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  515. c.id = id
  516. return c
  517. }
  518. // Fields allows partial responses to be retrieved. See
  519. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  520. // for more information.
  521. func (c *TrainedmodelsGetCall) Fields(s ...googleapi.Field) *TrainedmodelsGetCall {
  522. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  523. return c
  524. }
  525. // IfNoneMatch sets the optional parameter which makes the operation
  526. // fail if the object's ETag matches the given value. This is useful for
  527. // getting updates only after the object has changed since the last
  528. // request. Use googleapi.IsNotModified to check whether the response
  529. // error from Do is the result of In-None-Match.
  530. func (c *TrainedmodelsGetCall) IfNoneMatch(entityTag string) *TrainedmodelsGetCall {
  531. c.ifNoneMatch_ = entityTag
  532. return c
  533. }
  534. // Context sets the context to be used in this call's Do method. Any
  535. // pending HTTP request will be aborted if the provided context is
  536. // canceled.
  537. func (c *TrainedmodelsGetCall) Context(ctx context.Context) *TrainedmodelsGetCall {
  538. c.ctx_ = ctx
  539. return c
  540. }
  541. func (c *TrainedmodelsGetCall) doRequest(alt string) (*http.Response, error) {
  542. var body io.Reader = nil
  543. c.urlParams_.Set("alt", alt)
  544. urls := googleapi.ResolveRelative(c.s.BasePath, "trainedmodels/{id}")
  545. urls += "?" + c.urlParams_.Encode()
  546. req, _ := http.NewRequest("GET", urls, body)
  547. googleapi.Expand(req.URL, map[string]string{
  548. "id": c.id,
  549. })
  550. req.Header.Set("User-Agent", c.s.userAgent())
  551. if c.ifNoneMatch_ != "" {
  552. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  553. }
  554. if c.ctx_ != nil {
  555. return ctxhttp.Do(c.ctx_, c.s.client, req)
  556. }
  557. return c.s.client.Do(req)
  558. }
  559. // Do executes the "prediction.trainedmodels.get" call.
  560. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  561. // code is an error. Response headers are in either
  562. // *Training.ServerResponse.Header or (if a response was returned at
  563. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  564. // to check whether the returned error was because
  565. // http.StatusNotModified was returned.
  566. func (c *TrainedmodelsGetCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  567. gensupport.SetOptions(c.urlParams_, opts...)
  568. res, err := c.doRequest("json")
  569. if res != nil && res.StatusCode == http.StatusNotModified {
  570. if res.Body != nil {
  571. res.Body.Close()
  572. }
  573. return nil, &googleapi.Error{
  574. Code: res.StatusCode,
  575. Header: res.Header,
  576. }
  577. }
  578. if err != nil {
  579. return nil, err
  580. }
  581. defer googleapi.CloseBody(res)
  582. if err := googleapi.CheckResponse(res); err != nil {
  583. return nil, err
  584. }
  585. ret := &Training{
  586. ServerResponse: googleapi.ServerResponse{
  587. Header: res.Header,
  588. HTTPStatusCode: res.StatusCode,
  589. },
  590. }
  591. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  592. return nil, err
  593. }
  594. return ret, nil
  595. // {
  596. // "description": "Check training status of your model.",
  597. // "httpMethod": "GET",
  598. // "id": "prediction.trainedmodels.get",
  599. // "parameterOrder": [
  600. // "id"
  601. // ],
  602. // "parameters": {
  603. // "id": {
  604. // "description": "The unique name for the predictive model.",
  605. // "location": "path",
  606. // "required": true,
  607. // "type": "string"
  608. // }
  609. // },
  610. // "path": "trainedmodels/{id}",
  611. // "response": {
  612. // "$ref": "Training"
  613. // },
  614. // "scopes": [
  615. // "https://www.googleapis.com/auth/prediction"
  616. // ]
  617. // }
  618. }
  619. // method id "prediction.trainedmodels.insert":
  620. type TrainedmodelsInsertCall struct {
  621. s *Service
  622. training *Training
  623. urlParams_ gensupport.URLParams
  624. ctx_ context.Context
  625. }
  626. // Insert: Begin training your model.
  627. func (r *TrainedmodelsService) Insert(training *Training) *TrainedmodelsInsertCall {
  628. c := &TrainedmodelsInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  629. c.training = training
  630. return c
  631. }
  632. // Fields allows partial responses to be retrieved. See
  633. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  634. // for more information.
  635. func (c *TrainedmodelsInsertCall) Fields(s ...googleapi.Field) *TrainedmodelsInsertCall {
  636. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  637. return c
  638. }
  639. // Context sets the context to be used in this call's Do method. Any
  640. // pending HTTP request will be aborted if the provided context is
  641. // canceled.
  642. func (c *TrainedmodelsInsertCall) Context(ctx context.Context) *TrainedmodelsInsertCall {
  643. c.ctx_ = ctx
  644. return c
  645. }
  646. func (c *TrainedmodelsInsertCall) doRequest(alt string) (*http.Response, error) {
  647. var body io.Reader = nil
  648. body, err := googleapi.WithoutDataWrapper.JSONReader(c.training)
  649. if err != nil {
  650. return nil, err
  651. }
  652. ctype := "application/json"
  653. c.urlParams_.Set("alt", alt)
  654. urls := googleapi.ResolveRelative(c.s.BasePath, "trainedmodels")
  655. urls += "?" + c.urlParams_.Encode()
  656. req, _ := http.NewRequest("POST", urls, body)
  657. googleapi.SetOpaque(req.URL)
  658. req.Header.Set("Content-Type", ctype)
  659. req.Header.Set("User-Agent", c.s.userAgent())
  660. if c.ctx_ != nil {
  661. return ctxhttp.Do(c.ctx_, c.s.client, req)
  662. }
  663. return c.s.client.Do(req)
  664. }
  665. // Do executes the "prediction.trainedmodels.insert" call.
  666. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  667. // code is an error. Response headers are in either
  668. // *Training.ServerResponse.Header or (if a response was returned at
  669. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  670. // to check whether the returned error was because
  671. // http.StatusNotModified was returned.
  672. func (c *TrainedmodelsInsertCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  673. gensupport.SetOptions(c.urlParams_, opts...)
  674. res, err := c.doRequest("json")
  675. if res != nil && res.StatusCode == http.StatusNotModified {
  676. if res.Body != nil {
  677. res.Body.Close()
  678. }
  679. return nil, &googleapi.Error{
  680. Code: res.StatusCode,
  681. Header: res.Header,
  682. }
  683. }
  684. if err != nil {
  685. return nil, err
  686. }
  687. defer googleapi.CloseBody(res)
  688. if err := googleapi.CheckResponse(res); err != nil {
  689. return nil, err
  690. }
  691. ret := &Training{
  692. ServerResponse: googleapi.ServerResponse{
  693. Header: res.Header,
  694. HTTPStatusCode: res.StatusCode,
  695. },
  696. }
  697. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  698. return nil, err
  699. }
  700. return ret, nil
  701. // {
  702. // "description": "Begin training your model.",
  703. // "httpMethod": "POST",
  704. // "id": "prediction.trainedmodels.insert",
  705. // "path": "trainedmodels",
  706. // "request": {
  707. // "$ref": "Training"
  708. // },
  709. // "response": {
  710. // "$ref": "Training"
  711. // },
  712. // "scopes": [
  713. // "https://www.googleapis.com/auth/devstorage.full_control",
  714. // "https://www.googleapis.com/auth/devstorage.read_only",
  715. // "https://www.googleapis.com/auth/devstorage.read_write",
  716. // "https://www.googleapis.com/auth/prediction"
  717. // ]
  718. // }
  719. }
  720. // method id "prediction.trainedmodels.predict":
  721. type TrainedmodelsPredictCall struct {
  722. s *Service
  723. id string
  724. input *Input
  725. urlParams_ gensupport.URLParams
  726. ctx_ context.Context
  727. }
  728. // Predict: Submit model id and request a prediction
  729. func (r *TrainedmodelsService) Predict(id string, input *Input) *TrainedmodelsPredictCall {
  730. c := &TrainedmodelsPredictCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  731. c.id = id
  732. c.input = input
  733. return c
  734. }
  735. // Fields allows partial responses to be retrieved. See
  736. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  737. // for more information.
  738. func (c *TrainedmodelsPredictCall) Fields(s ...googleapi.Field) *TrainedmodelsPredictCall {
  739. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  740. return c
  741. }
  742. // Context sets the context to be used in this call's Do method. Any
  743. // pending HTTP request will be aborted if the provided context is
  744. // canceled.
  745. func (c *TrainedmodelsPredictCall) Context(ctx context.Context) *TrainedmodelsPredictCall {
  746. c.ctx_ = ctx
  747. return c
  748. }
  749. func (c *TrainedmodelsPredictCall) doRequest(alt string) (*http.Response, error) {
  750. var body io.Reader = nil
  751. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  752. if err != nil {
  753. return nil, err
  754. }
  755. ctype := "application/json"
  756. c.urlParams_.Set("alt", alt)
  757. urls := googleapi.ResolveRelative(c.s.BasePath, "trainedmodels/{id}/predict")
  758. urls += "?" + c.urlParams_.Encode()
  759. req, _ := http.NewRequest("POST", urls, body)
  760. googleapi.Expand(req.URL, map[string]string{
  761. "id": c.id,
  762. })
  763. req.Header.Set("Content-Type", ctype)
  764. req.Header.Set("User-Agent", c.s.userAgent())
  765. if c.ctx_ != nil {
  766. return ctxhttp.Do(c.ctx_, c.s.client, req)
  767. }
  768. return c.s.client.Do(req)
  769. }
  770. // Do executes the "prediction.trainedmodels.predict" call.
  771. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  772. // code is an error. Response headers are in either
  773. // *Output.ServerResponse.Header or (if a response was returned at all)
  774. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  775. // check whether the returned error was because http.StatusNotModified
  776. // was returned.
  777. func (c *TrainedmodelsPredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  778. gensupport.SetOptions(c.urlParams_, opts...)
  779. res, err := c.doRequest("json")
  780. if res != nil && res.StatusCode == http.StatusNotModified {
  781. if res.Body != nil {
  782. res.Body.Close()
  783. }
  784. return nil, &googleapi.Error{
  785. Code: res.StatusCode,
  786. Header: res.Header,
  787. }
  788. }
  789. if err != nil {
  790. return nil, err
  791. }
  792. defer googleapi.CloseBody(res)
  793. if err := googleapi.CheckResponse(res); err != nil {
  794. return nil, err
  795. }
  796. ret := &Output{
  797. ServerResponse: googleapi.ServerResponse{
  798. Header: res.Header,
  799. HTTPStatusCode: res.StatusCode,
  800. },
  801. }
  802. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  803. return nil, err
  804. }
  805. return ret, nil
  806. // {
  807. // "description": "Submit model id and request a prediction",
  808. // "httpMethod": "POST",
  809. // "id": "prediction.trainedmodels.predict",
  810. // "parameterOrder": [
  811. // "id"
  812. // ],
  813. // "parameters": {
  814. // "id": {
  815. // "description": "The unique name for the predictive model.",
  816. // "location": "path",
  817. // "required": true,
  818. // "type": "string"
  819. // }
  820. // },
  821. // "path": "trainedmodels/{id}/predict",
  822. // "request": {
  823. // "$ref": "Input"
  824. // },
  825. // "response": {
  826. // "$ref": "Output"
  827. // },
  828. // "scopes": [
  829. // "https://www.googleapis.com/auth/prediction"
  830. // ]
  831. // }
  832. }
  833. // method id "prediction.trainedmodels.update":
  834. type TrainedmodelsUpdateCall struct {
  835. s *Service
  836. id string
  837. update *Update
  838. urlParams_ gensupport.URLParams
  839. ctx_ context.Context
  840. }
  841. // Update: Add new data to a trained model.
  842. func (r *TrainedmodelsService) Update(id string, update *Update) *TrainedmodelsUpdateCall {
  843. c := &TrainedmodelsUpdateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  844. c.id = id
  845. c.update = update
  846. return c
  847. }
  848. // Fields allows partial responses to be retrieved. See
  849. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  850. // for more information.
  851. func (c *TrainedmodelsUpdateCall) Fields(s ...googleapi.Field) *TrainedmodelsUpdateCall {
  852. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  853. return c
  854. }
  855. // Context sets the context to be used in this call's Do method. Any
  856. // pending HTTP request will be aborted if the provided context is
  857. // canceled.
  858. func (c *TrainedmodelsUpdateCall) Context(ctx context.Context) *TrainedmodelsUpdateCall {
  859. c.ctx_ = ctx
  860. return c
  861. }
  862. func (c *TrainedmodelsUpdateCall) doRequest(alt string) (*http.Response, error) {
  863. var body io.Reader = nil
  864. body, err := googleapi.WithoutDataWrapper.JSONReader(c.update)
  865. if err != nil {
  866. return nil, err
  867. }
  868. ctype := "application/json"
  869. c.urlParams_.Set("alt", alt)
  870. urls := googleapi.ResolveRelative(c.s.BasePath, "trainedmodels/{id}")
  871. urls += "?" + c.urlParams_.Encode()
  872. req, _ := http.NewRequest("PUT", urls, body)
  873. googleapi.Expand(req.URL, map[string]string{
  874. "id": c.id,
  875. })
  876. req.Header.Set("Content-Type", ctype)
  877. req.Header.Set("User-Agent", c.s.userAgent())
  878. if c.ctx_ != nil {
  879. return ctxhttp.Do(c.ctx_, c.s.client, req)
  880. }
  881. return c.s.client.Do(req)
  882. }
  883. // Do executes the "prediction.trainedmodels.update" call.
  884. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  885. // code is an error. Response headers are in either
  886. // *Training.ServerResponse.Header or (if a response was returned at
  887. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  888. // to check whether the returned error was because
  889. // http.StatusNotModified was returned.
  890. func (c *TrainedmodelsUpdateCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  891. gensupport.SetOptions(c.urlParams_, opts...)
  892. res, err := c.doRequest("json")
  893. if res != nil && res.StatusCode == http.StatusNotModified {
  894. if res.Body != nil {
  895. res.Body.Close()
  896. }
  897. return nil, &googleapi.Error{
  898. Code: res.StatusCode,
  899. Header: res.Header,
  900. }
  901. }
  902. if err != nil {
  903. return nil, err
  904. }
  905. defer googleapi.CloseBody(res)
  906. if err := googleapi.CheckResponse(res); err != nil {
  907. return nil, err
  908. }
  909. ret := &Training{
  910. ServerResponse: googleapi.ServerResponse{
  911. Header: res.Header,
  912. HTTPStatusCode: res.StatusCode,
  913. },
  914. }
  915. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  916. return nil, err
  917. }
  918. return ret, nil
  919. // {
  920. // "description": "Add new data to a trained model.",
  921. // "httpMethod": "PUT",
  922. // "id": "prediction.trainedmodels.update",
  923. // "parameterOrder": [
  924. // "id"
  925. // ],
  926. // "parameters": {
  927. // "id": {
  928. // "description": "The unique name for the predictive model.",
  929. // "location": "path",
  930. // "required": true,
  931. // "type": "string"
  932. // }
  933. // },
  934. // "path": "trainedmodels/{id}",
  935. // "request": {
  936. // "$ref": "Update"
  937. // },
  938. // "response": {
  939. // "$ref": "Training"
  940. // },
  941. // "scopes": [
  942. // "https://www.googleapis.com/auth/prediction"
  943. // ]
  944. // }
  945. }