|
| 1 | +/** |
| 2 | + * Copyright 2019, Google LLC |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +`use strict`; |
| 17 | +async function main( |
| 18 | + projectId = 'YOUR_PROJECT_ID', |
| 19 | + computeRegion = 'YOUR_REGION_NAME', |
| 20 | + datasetId = 'YOUR_DATASET_ID', |
| 21 | + tableId = 'TABLE_ID', |
| 22 | + columnId = 'COLUMN_ID', |
| 23 | + modelName = 'MODEL_NAME', |
| 24 | + trainBudget = 'TRAIN_BUDGET' |
| 25 | +) { |
| 26 | + // [START automl_tables_create_model] |
| 27 | + const automl = require(`@google-cloud/automl`); |
| 28 | + const client = new automl.v1beta1.AutoMlClient(); |
| 29 | + |
| 30 | + /** |
| 31 | + * Demonstrates using the AutoML client to create a model. |
| 32 | + * TODO(developer): Uncomment the following lines before running the sample. |
| 33 | + */ |
| 34 | + // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project"; |
| 35 | + // const computeRegion = '[REGION_NAME]' e.g., "us-central1"; |
| 36 | + // const datasetId = '[DATASET_ID]' e.g., "TBL2246891593778855936"; |
| 37 | + // const tableId = '[TABLE_ID]' e.g., "1991013247762825216"; |
| 38 | + // const columnId = '[COLUMN_ID]' e.g., "773141392279994368"; |
| 39 | + // const modelName = '[MODEL_NAME]' e.g., "testModel"; |
| 40 | + // const trainBudget = '[TRAIN_BUDGET]' e.g., "1000", |
| 41 | + // `Train budget in milli node hours`; |
| 42 | + |
| 43 | + // A resource that represents Google Cloud Platform location. |
| 44 | + const projectLocation = client.locationPath(projectId, computeRegion); |
| 45 | + |
| 46 | + // Get the full path of the column. |
| 47 | + const columnSpecId = client.columnSpecPath( |
| 48 | + projectId, |
| 49 | + computeRegion, |
| 50 | + datasetId, |
| 51 | + tableId, |
| 52 | + columnId |
| 53 | + ); |
| 54 | + |
| 55 | + // Set target column to train the model. |
| 56 | + const targetColumnSpec = {name: columnSpecId}; |
| 57 | + |
| 58 | + // Set tables model metadata. |
| 59 | + const tablesModelMetadata = { |
| 60 | + targetColumnSpec: targetColumnSpec, |
| 61 | + trainBudgetMilliNodeHours: trainBudget, |
| 62 | + }; |
| 63 | + |
| 64 | + // Set datasetId, model name and model metadata for the dataset. |
| 65 | + const myModel = { |
| 66 | + datasetId: datasetId, |
| 67 | + displayName: modelName, |
| 68 | + tablesModelMetadata: tablesModelMetadata, |
| 69 | + }; |
| 70 | + |
| 71 | + // Create a model with the model metadata in the region. |
| 72 | + client |
| 73 | + .createModel({parent: projectLocation, model: myModel}) |
| 74 | + .then(responses => { |
| 75 | + const initialApiResponse = responses[1]; |
| 76 | + console.log(`Training operation name: ${initialApiResponse.name}`); |
| 77 | + console.log(`Training started...`); |
| 78 | + }) |
| 79 | + .catch(err => { |
| 80 | + console.error(err); |
| 81 | + }); |
| 82 | + // [END automl_tables_create_model] |
| 83 | +} |
| 84 | +main(...process.argv.slice(2)).catch(console.error()); |
0 commit comments