Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

1182 wiersze
37 KiB

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