|
| 1 | +const nodeCloud = require("../../lib/"); |
| 2 | +const ncProviders = nodeCloud.getProviders({ overrideProviders: false }); |
| 3 | + |
| 4 | +const machineLearningModule = ncProviders.google.autoML(); |
| 5 | + |
| 6 | +function displayModels() { |
| 7 | + machineLearningModule.listModels({ location: "us-central1" }).then( |
| 8 | + result => { |
| 9 | + console.log("Output :", result); |
| 10 | + }, |
| 11 | + error => { |
| 12 | + console.error(error); |
| 13 | + } |
| 14 | + ); |
| 15 | +} |
| 16 | + |
| 17 | +function importData() { |
| 18 | + const data = { |
| 19 | + targetDataset: { |
| 20 | + id: "TBL2227541288641626112", |
| 21 | + location: "us-central1" |
| 22 | + }, |
| 23 | + // The source should be located in the same region as the target dataset |
| 24 | + source: ["gs://node_cloud/netflix_titles.csv"] |
| 25 | + }; |
| 26 | + machineLearningModule.importDataSet(data).then( |
| 27 | + result => { |
| 28 | + console.log("Output :", result); |
| 29 | + }, |
| 30 | + error => { |
| 31 | + console.error(error); |
| 32 | + } |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +function createDataset() { |
| 37 | + const datasetDetails = { location: "us-central1", name: "NetflixAndChill" }; |
| 38 | + machineLearningModule.createDataset(datasetDetails).then( |
| 39 | + result => { |
| 40 | + console.log("Output :", result); |
| 41 | + }, |
| 42 | + error => { |
| 43 | + console.error(error); |
| 44 | + } |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +function createModel() { |
| 49 | + const modelDetails = { |
| 50 | + location: "us-central1", |
| 51 | + datasetId: "TBL2227541288641626112", |
| 52 | + tableId: "550696995841376256", |
| 53 | + columnId: "1191783743090589696", |
| 54 | + trainBudget: "1000", |
| 55 | + modelName: "showClassifier" |
| 56 | + }; |
| 57 | + |
| 58 | + machineLearningModule.createModel(modelDetails).then( |
| 59 | + result => { |
| 60 | + console.log("Output :", result); |
| 61 | + console.log("Training started..."); |
| 62 | + }, |
| 63 | + error => { |
| 64 | + console.error(error); |
| 65 | + } |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +function getDataset() { |
| 70 | + machineLearningModule |
| 71 | + .getDataset({ |
| 72 | + location: "us-central1", |
| 73 | + datasetId: "TBL2227541288641626112" |
| 74 | + }) |
| 75 | + .then( |
| 76 | + result => { |
| 77 | + console.log("Output :", result); |
| 78 | + }, |
| 79 | + error => { |
| 80 | + console.error(error); |
| 81 | + } |
| 82 | + ); |
| 83 | +} |
| 84 | + |
| 85 | +function deployModel() { |
| 86 | + machineLearningModule |
| 87 | + .deployModel({ |
| 88 | + location: "us-central1", |
| 89 | + modelId: "TBL3874357918887313408" |
| 90 | + }) |
| 91 | + .then( |
| 92 | + result => { |
| 93 | + console.log("Model deployment completed :", result); |
| 94 | + }, |
| 95 | + error => { |
| 96 | + console.error(error); |
| 97 | + } |
| 98 | + ); |
| 99 | +} |
| 100 | + |
| 101 | +function undeployModel() { |
| 102 | + machineLearningModule |
| 103 | + .undeployModel({ |
| 104 | + location: "us-central1", |
| 105 | + modelId: "TBL3874357918887313408" |
| 106 | + }) |
| 107 | + .then( |
| 108 | + result => { |
| 109 | + console.log("Model successfully undeployed :", result); |
| 110 | + }, |
| 111 | + error => { |
| 112 | + console.error(error); |
| 113 | + } |
| 114 | + ); |
| 115 | +} |
| 116 | + |
| 117 | +function getModel() { |
| 118 | + machineLearningModule |
| 119 | + .getModel({ |
| 120 | + location: "us-central1", |
| 121 | + modelId: "TBL3874357918887313408" |
| 122 | + }) |
| 123 | + .then( |
| 124 | + result => { |
| 125 | + console.log("Model name: ", result.displayName); |
| 126 | + console.log(result); |
| 127 | + }, |
| 128 | + error => { |
| 129 | + console.error(error); |
| 130 | + } |
| 131 | + ); |
| 132 | +} |
| 133 | + |
| 134 | +function exportDataset() { |
| 135 | + machineLearningModule |
| 136 | + .exportDataset({ |
| 137 | + location: "us-central1", |
| 138 | + datasetId: "TBL2227541288641626112", |
| 139 | + gcsUri: "gs://node_cloud/netflix_titles.csv" |
| 140 | + }) |
| 141 | + .then( |
| 142 | + result => { |
| 143 | + console.log("Data exporting completed"); |
| 144 | + console.log("Output :", result); |
| 145 | + }, |
| 146 | + error => { |
| 147 | + console.error(error); |
| 148 | + } |
| 149 | + ); |
| 150 | +} |
| 151 | + |
| 152 | +function deleteModel() { |
| 153 | + machineLearningModule |
| 154 | + .deleteModel({ |
| 155 | + location: "us-central1", |
| 156 | + modelId: "TBL3874357918887313408" |
| 157 | + }) |
| 158 | + .then( |
| 159 | + result => { |
| 160 | + console.log("Model successfully deleted"); |
| 161 | + console.log("Output :", result); |
| 162 | + }, |
| 163 | + error => { |
| 164 | + console.error(error); |
| 165 | + } |
| 166 | + ); |
| 167 | +} |
| 168 | + |
| 169 | +function deleteDataset() { |
| 170 | + machineLearningModule |
| 171 | + .deleteDataset({ |
| 172 | + location: "us-central1", |
| 173 | + datasetId: "TBL2227541288641626112" |
| 174 | + }) |
| 175 | + .then( |
| 176 | + result => { |
| 177 | + console.log("Dataset successfully deleted"); |
| 178 | + console.log("Output :", result); |
| 179 | + }, |
| 180 | + error => { |
| 181 | + console.error(error); |
| 182 | + } |
| 183 | + ); |
| 184 | +} |
0 commit comments