You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1187 lines
37 KiB

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