prediction-gen.go 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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.3"
  8. // ...
  9. // predictionService, err := prediction.New(oauthHttpClient)
  10. package prediction // import "google.golang.org/api/prediction/v1.3"
  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.3"
  41. const apiName = "prediction"
  42. const apiVersion = "v1.3"
  43. const basePath = "https://www.googleapis.com/prediction/v1.3/"
  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.Training = NewTrainingService(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. Training *TrainingService
  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 NewTrainingService(s *Service) *TrainingService {
  85. rs := &TrainingService{s: s}
  86. return rs
  87. }
  88. type TrainingService 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 [Categorical models only].
  131. OutputLabel string `json:"outputLabel,omitempty"`
  132. // OutputMulti: A list of classes with their estimated probabilities
  133. // [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.
  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. // Id: The unique name for the predictive model.
  175. Id string `json:"id,omitempty"`
  176. // Kind: What kind of resource this is.
  177. Kind string `json:"kind,omitempty"`
  178. // ModelInfo: Model metadata.
  179. ModelInfo *TrainingModelInfo `json:"modelInfo,omitempty"`
  180. // SelfLink: A URL to re-request this resource.
  181. SelfLink string `json:"selfLink,omitempty"`
  182. // TrainingStatus: The current status of the training job. This can be
  183. // one of following: RUNNING; DONE; ERROR; ERROR: TRAINING JOB NOT FOUND
  184. TrainingStatus string `json:"trainingStatus,omitempty"`
  185. // Utility: A class weighting function, which allows the importance
  186. // weights for classes to be specified [Categorical models only].
  187. Utility []*TrainingUtility `json:"utility,omitempty"`
  188. // ServerResponse contains the HTTP response code and headers from the
  189. // server.
  190. googleapi.ServerResponse `json:"-"`
  191. // ForceSendFields is a list of field names (e.g. "Id") to
  192. // unconditionally include in API requests. By default, fields with
  193. // empty values are omitted from API requests. However, any non-pointer,
  194. // non-interface field appearing in ForceSendFields will be sent to the
  195. // server regardless of whether the field is empty or not. This may be
  196. // used to include empty fields in Patch requests.
  197. ForceSendFields []string `json:"-"`
  198. }
  199. func (s *Training) MarshalJSON() ([]byte, error) {
  200. type noMethod Training
  201. raw := noMethod(*s)
  202. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  203. }
  204. // TrainingModelInfo: Model metadata.
  205. type TrainingModelInfo struct {
  206. // ClassWeightedAccuracy: Estimated accuracy of model taking utility
  207. // weights into account [Categorical models only].
  208. ClassWeightedAccuracy float64 `json:"classWeightedAccuracy,omitempty"`
  209. // ClassificationAccuracy: A number between 0.0 and 1.0, where 1.0 is
  210. // 100% accurate. This is an estimate, based on the amount and quality
  211. // of the training data, of the estimated prediction accuracy. You can
  212. // use this is a guide to decide whether the results are accurate enough
  213. // for your needs. This estimate will be more reliable if your real
  214. // input data is similar to your training data [Categorical models
  215. // only].
  216. ClassificationAccuracy float64 `json:"classificationAccuracy,omitempty"`
  217. // ConfusionMatrix: An output confusion matrix. This shows an estimate
  218. // for how this model will do in predictions. This is first indexed by
  219. // the true class label. For each true class label, this provides a pair
  220. // {predicted_label, count}, where count is the estimated number of
  221. // times the model will predict the predicted label given the true
  222. // label. Will not output if more then 100 classes [Categorical models
  223. // only].
  224. ConfusionMatrix *TrainingModelInfoConfusionMatrix `json:"confusionMatrix,omitempty"`
  225. // ConfusionMatrixRowTotals: A list of the confusion matrix row totals
  226. ConfusionMatrixRowTotals *TrainingModelInfoConfusionMatrixRowTotals `json:"confusionMatrixRowTotals,omitempty"`
  227. // MeanSquaredError: An estimated mean squared error. The can be used to
  228. // measure the quality of the predicted model [Regression models only].
  229. MeanSquaredError float64 `json:"meanSquaredError,omitempty"`
  230. // ModelType: Type of predictive model (CLASSIFICATION or REGRESSION)
  231. ModelType string `json:"modelType,omitempty"`
  232. // NumberClasses: Number of classes in the trained model [Categorical
  233. // models only].
  234. NumberClasses int64 `json:"numberClasses,omitempty,string"`
  235. // NumberInstances: Number of valid data instances used in the trained
  236. // model.
  237. NumberInstances int64 `json:"numberInstances,omitempty,string"`
  238. // ForceSendFields is a list of field names (e.g.
  239. // "ClassWeightedAccuracy") to unconditionally include in API requests.
  240. // By default, fields with empty values are omitted from API requests.
  241. // However, any non-pointer, non-interface field appearing in
  242. // ForceSendFields will be sent to the server regardless of whether the
  243. // field is empty or not. This may be used to include empty fields in
  244. // Patch requests.
  245. ForceSendFields []string `json:"-"`
  246. }
  247. func (s *TrainingModelInfo) MarshalJSON() ([]byte, error) {
  248. type noMethod TrainingModelInfo
  249. raw := noMethod(*s)
  250. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  251. }
  252. // TrainingModelInfoConfusionMatrix: An output confusion matrix. This
  253. // shows an estimate for how this model will do in predictions. This is
  254. // first indexed by the true class label. For each true class label,
  255. // this provides a pair {predicted_label, count}, where count is the
  256. // estimated number of times the model will predict the predicted label
  257. // given the true label. Will not output if more then 100 classes
  258. // [Categorical models only].
  259. type TrainingModelInfoConfusionMatrix struct {
  260. }
  261. // TrainingModelInfoConfusionMatrixRowTotals: A list of the confusion
  262. // matrix row totals
  263. type TrainingModelInfoConfusionMatrixRowTotals struct {
  264. }
  265. // TrainingUtility: Class label (string).
  266. type TrainingUtility struct {
  267. }
  268. type Update struct {
  269. // ClassLabel: The true class label of this instance
  270. ClassLabel string `json:"classLabel,omitempty"`
  271. // CsvInstance: The input features for this instance
  272. CsvInstance []interface{} `json:"csvInstance,omitempty"`
  273. // ForceSendFields is a list of field names (e.g. "ClassLabel") to
  274. // unconditionally include in API requests. By default, fields with
  275. // empty values are omitted from API requests. However, any non-pointer,
  276. // non-interface field appearing in ForceSendFields will be sent to the
  277. // server regardless of whether the field is empty or not. This may be
  278. // used to include empty fields in Patch requests.
  279. ForceSendFields []string `json:"-"`
  280. }
  281. func (s *Update) MarshalJSON() ([]byte, error) {
  282. type noMethod Update
  283. raw := noMethod(*s)
  284. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  285. }
  286. // method id "prediction.hostedmodels.predict":
  287. type HostedmodelsPredictCall struct {
  288. s *Service
  289. hostedModelName string
  290. input *Input
  291. urlParams_ gensupport.URLParams
  292. ctx_ context.Context
  293. }
  294. // Predict: Submit input and request an output against a hosted model
  295. func (r *HostedmodelsService) Predict(hostedModelName string, input *Input) *HostedmodelsPredictCall {
  296. c := &HostedmodelsPredictCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  297. c.hostedModelName = hostedModelName
  298. c.input = input
  299. return c
  300. }
  301. // Fields allows partial responses to be retrieved. See
  302. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  303. // for more information.
  304. func (c *HostedmodelsPredictCall) Fields(s ...googleapi.Field) *HostedmodelsPredictCall {
  305. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  306. return c
  307. }
  308. // Context sets the context to be used in this call's Do method. Any
  309. // pending HTTP request will be aborted if the provided context is
  310. // canceled.
  311. func (c *HostedmodelsPredictCall) Context(ctx context.Context) *HostedmodelsPredictCall {
  312. c.ctx_ = ctx
  313. return c
  314. }
  315. func (c *HostedmodelsPredictCall) doRequest(alt string) (*http.Response, error) {
  316. var body io.Reader = nil
  317. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  318. if err != nil {
  319. return nil, err
  320. }
  321. ctype := "application/json"
  322. c.urlParams_.Set("alt", alt)
  323. urls := googleapi.ResolveRelative(c.s.BasePath, "hostedmodels/{hostedModelName}/predict")
  324. urls += "?" + c.urlParams_.Encode()
  325. req, _ := http.NewRequest("POST", urls, body)
  326. googleapi.Expand(req.URL, map[string]string{
  327. "hostedModelName": c.hostedModelName,
  328. })
  329. req.Header.Set("Content-Type", ctype)
  330. req.Header.Set("User-Agent", c.s.userAgent())
  331. if c.ctx_ != nil {
  332. return ctxhttp.Do(c.ctx_, c.s.client, req)
  333. }
  334. return c.s.client.Do(req)
  335. }
  336. // Do executes the "prediction.hostedmodels.predict" call.
  337. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  338. // code is an error. Response headers are in either
  339. // *Output.ServerResponse.Header or (if a response was returned at all)
  340. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  341. // check whether the returned error was because http.StatusNotModified
  342. // was returned.
  343. func (c *HostedmodelsPredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  344. gensupport.SetOptions(c.urlParams_, opts...)
  345. res, err := c.doRequest("json")
  346. if res != nil && res.StatusCode == http.StatusNotModified {
  347. if res.Body != nil {
  348. res.Body.Close()
  349. }
  350. return nil, &googleapi.Error{
  351. Code: res.StatusCode,
  352. Header: res.Header,
  353. }
  354. }
  355. if err != nil {
  356. return nil, err
  357. }
  358. defer googleapi.CloseBody(res)
  359. if err := googleapi.CheckResponse(res); err != nil {
  360. return nil, err
  361. }
  362. ret := &Output{
  363. ServerResponse: googleapi.ServerResponse{
  364. Header: res.Header,
  365. HTTPStatusCode: res.StatusCode,
  366. },
  367. }
  368. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  369. return nil, err
  370. }
  371. return ret, nil
  372. // {
  373. // "description": "Submit input and request an output against a hosted model",
  374. // "httpMethod": "POST",
  375. // "id": "prediction.hostedmodels.predict",
  376. // "parameterOrder": [
  377. // "hostedModelName"
  378. // ],
  379. // "parameters": {
  380. // "hostedModelName": {
  381. // "description": "The name of a hosted model",
  382. // "location": "path",
  383. // "required": true,
  384. // "type": "string"
  385. // }
  386. // },
  387. // "path": "hostedmodels/{hostedModelName}/predict",
  388. // "request": {
  389. // "$ref": "Input"
  390. // },
  391. // "response": {
  392. // "$ref": "Output"
  393. // },
  394. // "scopes": [
  395. // "https://www.googleapis.com/auth/prediction"
  396. // ]
  397. // }
  398. }
  399. // method id "prediction.training.delete":
  400. type TrainingDeleteCall struct {
  401. s *Service
  402. data string
  403. urlParams_ gensupport.URLParams
  404. ctx_ context.Context
  405. }
  406. // Delete: Delete a trained model
  407. func (r *TrainingService) Delete(data string) *TrainingDeleteCall {
  408. c := &TrainingDeleteCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  409. c.data = data
  410. return c
  411. }
  412. // Fields allows partial responses to be retrieved. See
  413. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  414. // for more information.
  415. func (c *TrainingDeleteCall) Fields(s ...googleapi.Field) *TrainingDeleteCall {
  416. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  417. return c
  418. }
  419. // Context sets the context to be used in this call's Do method. Any
  420. // pending HTTP request will be aborted if the provided context is
  421. // canceled.
  422. func (c *TrainingDeleteCall) Context(ctx context.Context) *TrainingDeleteCall {
  423. c.ctx_ = ctx
  424. return c
  425. }
  426. func (c *TrainingDeleteCall) doRequest(alt string) (*http.Response, error) {
  427. var body io.Reader = nil
  428. c.urlParams_.Set("alt", alt)
  429. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  430. urls += "?" + c.urlParams_.Encode()
  431. req, _ := http.NewRequest("DELETE", urls, body)
  432. googleapi.Expand(req.URL, map[string]string{
  433. "data": c.data,
  434. })
  435. req.Header.Set("User-Agent", c.s.userAgent())
  436. if c.ctx_ != nil {
  437. return ctxhttp.Do(c.ctx_, c.s.client, req)
  438. }
  439. return c.s.client.Do(req)
  440. }
  441. // Do executes the "prediction.training.delete" call.
  442. func (c *TrainingDeleteCall) Do(opts ...googleapi.CallOption) error {
  443. gensupport.SetOptions(c.urlParams_, opts...)
  444. res, err := c.doRequest("json")
  445. if err != nil {
  446. return err
  447. }
  448. defer googleapi.CloseBody(res)
  449. if err := googleapi.CheckResponse(res); err != nil {
  450. return err
  451. }
  452. return nil
  453. // {
  454. // "description": "Delete a trained model",
  455. // "httpMethod": "DELETE",
  456. // "id": "prediction.training.delete",
  457. // "parameterOrder": [
  458. // "data"
  459. // ],
  460. // "parameters": {
  461. // "data": {
  462. // "description": "mybucket/mydata resource in Google Storage",
  463. // "location": "path",
  464. // "required": true,
  465. // "type": "string"
  466. // }
  467. // },
  468. // "path": "training/{data}",
  469. // "scopes": [
  470. // "https://www.googleapis.com/auth/prediction"
  471. // ]
  472. // }
  473. }
  474. // method id "prediction.training.get":
  475. type TrainingGetCall struct {
  476. s *Service
  477. data string
  478. urlParams_ gensupport.URLParams
  479. ifNoneMatch_ string
  480. ctx_ context.Context
  481. }
  482. // Get: Check training status of your model
  483. func (r *TrainingService) Get(data string) *TrainingGetCall {
  484. c := &TrainingGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  485. c.data = data
  486. return c
  487. }
  488. // Fields allows partial responses to be retrieved. See
  489. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  490. // for more information.
  491. func (c *TrainingGetCall) Fields(s ...googleapi.Field) *TrainingGetCall {
  492. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  493. return c
  494. }
  495. // IfNoneMatch sets the optional parameter which makes the operation
  496. // fail if the object's ETag matches the given value. This is useful for
  497. // getting updates only after the object has changed since the last
  498. // request. Use googleapi.IsNotModified to check whether the response
  499. // error from Do is the result of In-None-Match.
  500. func (c *TrainingGetCall) IfNoneMatch(entityTag string) *TrainingGetCall {
  501. c.ifNoneMatch_ = entityTag
  502. return c
  503. }
  504. // Context sets the context to be used in this call's Do method. Any
  505. // pending HTTP request will be aborted if the provided context is
  506. // canceled.
  507. func (c *TrainingGetCall) Context(ctx context.Context) *TrainingGetCall {
  508. c.ctx_ = ctx
  509. return c
  510. }
  511. func (c *TrainingGetCall) doRequest(alt string) (*http.Response, error) {
  512. var body io.Reader = nil
  513. c.urlParams_.Set("alt", alt)
  514. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  515. urls += "?" + c.urlParams_.Encode()
  516. req, _ := http.NewRequest("GET", urls, body)
  517. googleapi.Expand(req.URL, map[string]string{
  518. "data": c.data,
  519. })
  520. req.Header.Set("User-Agent", c.s.userAgent())
  521. if c.ifNoneMatch_ != "" {
  522. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  523. }
  524. if c.ctx_ != nil {
  525. return ctxhttp.Do(c.ctx_, c.s.client, req)
  526. }
  527. return c.s.client.Do(req)
  528. }
  529. // Do executes the "prediction.training.get" call.
  530. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  531. // code is an error. Response headers are in either
  532. // *Training.ServerResponse.Header or (if a response was returned at
  533. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  534. // to check whether the returned error was because
  535. // http.StatusNotModified was returned.
  536. func (c *TrainingGetCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  537. gensupport.SetOptions(c.urlParams_, opts...)
  538. res, err := c.doRequest("json")
  539. if res != nil && res.StatusCode == http.StatusNotModified {
  540. if res.Body != nil {
  541. res.Body.Close()
  542. }
  543. return nil, &googleapi.Error{
  544. Code: res.StatusCode,
  545. Header: res.Header,
  546. }
  547. }
  548. if err != nil {
  549. return nil, err
  550. }
  551. defer googleapi.CloseBody(res)
  552. if err := googleapi.CheckResponse(res); err != nil {
  553. return nil, err
  554. }
  555. ret := &Training{
  556. ServerResponse: googleapi.ServerResponse{
  557. Header: res.Header,
  558. HTTPStatusCode: res.StatusCode,
  559. },
  560. }
  561. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  562. return nil, err
  563. }
  564. return ret, nil
  565. // {
  566. // "description": "Check training status of your model",
  567. // "httpMethod": "GET",
  568. // "id": "prediction.training.get",
  569. // "parameterOrder": [
  570. // "data"
  571. // ],
  572. // "parameters": {
  573. // "data": {
  574. // "description": "mybucket/mydata resource in Google Storage",
  575. // "location": "path",
  576. // "required": true,
  577. // "type": "string"
  578. // }
  579. // },
  580. // "path": "training/{data}",
  581. // "response": {
  582. // "$ref": "Training"
  583. // },
  584. // "scopes": [
  585. // "https://www.googleapis.com/auth/prediction"
  586. // ]
  587. // }
  588. }
  589. // method id "prediction.training.insert":
  590. type TrainingInsertCall struct {
  591. s *Service
  592. training *Training
  593. urlParams_ gensupport.URLParams
  594. ctx_ context.Context
  595. }
  596. // Insert: Begin training your model
  597. func (r *TrainingService) Insert(training *Training) *TrainingInsertCall {
  598. c := &TrainingInsertCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  599. c.training = training
  600. return c
  601. }
  602. // Fields allows partial responses to be retrieved. See
  603. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  604. // for more information.
  605. func (c *TrainingInsertCall) Fields(s ...googleapi.Field) *TrainingInsertCall {
  606. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  607. return c
  608. }
  609. // Context sets the context to be used in this call's Do method. Any
  610. // pending HTTP request will be aborted if the provided context is
  611. // canceled.
  612. func (c *TrainingInsertCall) Context(ctx context.Context) *TrainingInsertCall {
  613. c.ctx_ = ctx
  614. return c
  615. }
  616. func (c *TrainingInsertCall) doRequest(alt string) (*http.Response, error) {
  617. var body io.Reader = nil
  618. body, err := googleapi.WithoutDataWrapper.JSONReader(c.training)
  619. if err != nil {
  620. return nil, err
  621. }
  622. ctype := "application/json"
  623. c.urlParams_.Set("alt", alt)
  624. urls := googleapi.ResolveRelative(c.s.BasePath, "training")
  625. urls += "?" + c.urlParams_.Encode()
  626. req, _ := http.NewRequest("POST", urls, body)
  627. googleapi.SetOpaque(req.URL)
  628. req.Header.Set("Content-Type", ctype)
  629. req.Header.Set("User-Agent", c.s.userAgent())
  630. if c.ctx_ != nil {
  631. return ctxhttp.Do(c.ctx_, c.s.client, req)
  632. }
  633. return c.s.client.Do(req)
  634. }
  635. // Do executes the "prediction.training.insert" call.
  636. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  637. // code is an error. Response headers are in either
  638. // *Training.ServerResponse.Header or (if a response was returned at
  639. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  640. // to check whether the returned error was because
  641. // http.StatusNotModified was returned.
  642. func (c *TrainingInsertCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  643. gensupport.SetOptions(c.urlParams_, opts...)
  644. res, err := c.doRequest("json")
  645. if res != nil && res.StatusCode == http.StatusNotModified {
  646. if res.Body != nil {
  647. res.Body.Close()
  648. }
  649. return nil, &googleapi.Error{
  650. Code: res.StatusCode,
  651. Header: res.Header,
  652. }
  653. }
  654. if err != nil {
  655. return nil, err
  656. }
  657. defer googleapi.CloseBody(res)
  658. if err := googleapi.CheckResponse(res); err != nil {
  659. return nil, err
  660. }
  661. ret := &Training{
  662. ServerResponse: googleapi.ServerResponse{
  663. Header: res.Header,
  664. HTTPStatusCode: res.StatusCode,
  665. },
  666. }
  667. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  668. return nil, err
  669. }
  670. return ret, nil
  671. // {
  672. // "description": "Begin training your model",
  673. // "httpMethod": "POST",
  674. // "id": "prediction.training.insert",
  675. // "path": "training",
  676. // "request": {
  677. // "$ref": "Training"
  678. // },
  679. // "response": {
  680. // "$ref": "Training"
  681. // },
  682. // "scopes": [
  683. // "https://www.googleapis.com/auth/devstorage.full_control",
  684. // "https://www.googleapis.com/auth/devstorage.read_only",
  685. // "https://www.googleapis.com/auth/devstorage.read_write",
  686. // "https://www.googleapis.com/auth/prediction"
  687. // ]
  688. // }
  689. }
  690. // method id "prediction.training.predict":
  691. type TrainingPredictCall struct {
  692. s *Service
  693. data string
  694. input *Input
  695. urlParams_ gensupport.URLParams
  696. ctx_ context.Context
  697. }
  698. // Predict: Submit data and request a prediction
  699. func (r *TrainingService) Predict(data string, input *Input) *TrainingPredictCall {
  700. c := &TrainingPredictCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  701. c.data = data
  702. c.input = input
  703. return c
  704. }
  705. // Fields allows partial responses to be retrieved. See
  706. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  707. // for more information.
  708. func (c *TrainingPredictCall) Fields(s ...googleapi.Field) *TrainingPredictCall {
  709. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  710. return c
  711. }
  712. // Context sets the context to be used in this call's Do method. Any
  713. // pending HTTP request will be aborted if the provided context is
  714. // canceled.
  715. func (c *TrainingPredictCall) Context(ctx context.Context) *TrainingPredictCall {
  716. c.ctx_ = ctx
  717. return c
  718. }
  719. func (c *TrainingPredictCall) doRequest(alt string) (*http.Response, error) {
  720. var body io.Reader = nil
  721. body, err := googleapi.WithoutDataWrapper.JSONReader(c.input)
  722. if err != nil {
  723. return nil, err
  724. }
  725. ctype := "application/json"
  726. c.urlParams_.Set("alt", alt)
  727. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}/predict")
  728. urls += "?" + c.urlParams_.Encode()
  729. req, _ := http.NewRequest("POST", urls, body)
  730. googleapi.Expand(req.URL, map[string]string{
  731. "data": c.data,
  732. })
  733. req.Header.Set("Content-Type", ctype)
  734. req.Header.Set("User-Agent", c.s.userAgent())
  735. if c.ctx_ != nil {
  736. return ctxhttp.Do(c.ctx_, c.s.client, req)
  737. }
  738. return c.s.client.Do(req)
  739. }
  740. // Do executes the "prediction.training.predict" call.
  741. // Exactly one of *Output or error will be non-nil. Any non-2xx status
  742. // code is an error. Response headers are in either
  743. // *Output.ServerResponse.Header or (if a response was returned at all)
  744. // in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to
  745. // check whether the returned error was because http.StatusNotModified
  746. // was returned.
  747. func (c *TrainingPredictCall) Do(opts ...googleapi.CallOption) (*Output, error) {
  748. gensupport.SetOptions(c.urlParams_, opts...)
  749. res, err := c.doRequest("json")
  750. if res != nil && res.StatusCode == http.StatusNotModified {
  751. if res.Body != nil {
  752. res.Body.Close()
  753. }
  754. return nil, &googleapi.Error{
  755. Code: res.StatusCode,
  756. Header: res.Header,
  757. }
  758. }
  759. if err != nil {
  760. return nil, err
  761. }
  762. defer googleapi.CloseBody(res)
  763. if err := googleapi.CheckResponse(res); err != nil {
  764. return nil, err
  765. }
  766. ret := &Output{
  767. ServerResponse: googleapi.ServerResponse{
  768. Header: res.Header,
  769. HTTPStatusCode: res.StatusCode,
  770. },
  771. }
  772. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  773. return nil, err
  774. }
  775. return ret, nil
  776. // {
  777. // "description": "Submit data and request a prediction",
  778. // "httpMethod": "POST",
  779. // "id": "prediction.training.predict",
  780. // "parameterOrder": [
  781. // "data"
  782. // ],
  783. // "parameters": {
  784. // "data": {
  785. // "description": "mybucket/mydata resource in Google Storage",
  786. // "location": "path",
  787. // "required": true,
  788. // "type": "string"
  789. // }
  790. // },
  791. // "path": "training/{data}/predict",
  792. // "request": {
  793. // "$ref": "Input"
  794. // },
  795. // "response": {
  796. // "$ref": "Output"
  797. // },
  798. // "scopes": [
  799. // "https://www.googleapis.com/auth/prediction"
  800. // ]
  801. // }
  802. }
  803. // method id "prediction.training.update":
  804. type TrainingUpdateCall struct {
  805. s *Service
  806. data string
  807. update *Update
  808. urlParams_ gensupport.URLParams
  809. ctx_ context.Context
  810. }
  811. // Update: Add new data to a trained model
  812. func (r *TrainingService) Update(data string, update *Update) *TrainingUpdateCall {
  813. c := &TrainingUpdateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  814. c.data = data
  815. c.update = update
  816. return c
  817. }
  818. // Fields allows partial responses to be retrieved. See
  819. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  820. // for more information.
  821. func (c *TrainingUpdateCall) Fields(s ...googleapi.Field) *TrainingUpdateCall {
  822. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  823. return c
  824. }
  825. // Context sets the context to be used in this call's Do method. Any
  826. // pending HTTP request will be aborted if the provided context is
  827. // canceled.
  828. func (c *TrainingUpdateCall) Context(ctx context.Context) *TrainingUpdateCall {
  829. c.ctx_ = ctx
  830. return c
  831. }
  832. func (c *TrainingUpdateCall) doRequest(alt string) (*http.Response, error) {
  833. var body io.Reader = nil
  834. body, err := googleapi.WithoutDataWrapper.JSONReader(c.update)
  835. if err != nil {
  836. return nil, err
  837. }
  838. ctype := "application/json"
  839. c.urlParams_.Set("alt", alt)
  840. urls := googleapi.ResolveRelative(c.s.BasePath, "training/{data}")
  841. urls += "?" + c.urlParams_.Encode()
  842. req, _ := http.NewRequest("PUT", urls, body)
  843. googleapi.Expand(req.URL, map[string]string{
  844. "data": c.data,
  845. })
  846. req.Header.Set("Content-Type", ctype)
  847. req.Header.Set("User-Agent", c.s.userAgent())
  848. if c.ctx_ != nil {
  849. return ctxhttp.Do(c.ctx_, c.s.client, req)
  850. }
  851. return c.s.client.Do(req)
  852. }
  853. // Do executes the "prediction.training.update" call.
  854. // Exactly one of *Training or error will be non-nil. Any non-2xx status
  855. // code is an error. Response headers are in either
  856. // *Training.ServerResponse.Header or (if a response was returned at
  857. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  858. // to check whether the returned error was because
  859. // http.StatusNotModified was returned.
  860. func (c *TrainingUpdateCall) Do(opts ...googleapi.CallOption) (*Training, error) {
  861. gensupport.SetOptions(c.urlParams_, opts...)
  862. res, err := c.doRequest("json")
  863. if res != nil && res.StatusCode == http.StatusNotModified {
  864. if res.Body != nil {
  865. res.Body.Close()
  866. }
  867. return nil, &googleapi.Error{
  868. Code: res.StatusCode,
  869. Header: res.Header,
  870. }
  871. }
  872. if err != nil {
  873. return nil, err
  874. }
  875. defer googleapi.CloseBody(res)
  876. if err := googleapi.CheckResponse(res); err != nil {
  877. return nil, err
  878. }
  879. ret := &Training{
  880. ServerResponse: googleapi.ServerResponse{
  881. Header: res.Header,
  882. HTTPStatusCode: res.StatusCode,
  883. },
  884. }
  885. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  886. return nil, err
  887. }
  888. return ret, nil
  889. // {
  890. // "description": "Add new data to a trained model",
  891. // "httpMethod": "PUT",
  892. // "id": "prediction.training.update",
  893. // "parameterOrder": [
  894. // "data"
  895. // ],
  896. // "parameters": {
  897. // "data": {
  898. // "description": "mybucket/mydata resource in Google Storage",
  899. // "location": "path",
  900. // "required": true,
  901. // "type": "string"
  902. // }
  903. // },
  904. // "path": "training/{data}",
  905. // "request": {
  906. // "$ref": "Update"
  907. // },
  908. // "response": {
  909. // "$ref": "Training"
  910. // },
  911. // "scopes": [
  912. // "https://www.googleapis.com/auth/prediction"
  913. // ]
  914. // }
  915. }