MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / predict

Function predict

automl/tables/predict.v1beta1.js:44–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42 const modelFullId = automlClient.modelPath(projectId, computeRegion, modelId);
43
44 async function predict() {
45 // Set the payload by giving the row values.
46 const payload = {
47 row: {
48 values: inputs,
49 },
50 };
51
52 // Params is additional domain-specific parameters.
53 // Currently there is no additional parameters supported.
54 const [response] = await automlClient.predict({
55 name: modelFullId,
56 payload: payload,
57 params: {feature_importance: true},
58 });
59 console.log('Prediction results:');
60
61 for (const result of response.payload) {
62 console.log(`Predicted class name: ${result.displayName}`);
63 console.log(`Predicted class score: ${result.tables.score}`);
64
65 // Get features of top importance
66 const featureList = result.tables.tablesModelColumnInfo.map(
67 columnInfo => {
68 return {
69 importance: columnInfo.featureImportance,
70 displayName: columnInfo.columnDisplayName,
71 };
72 }
73 );
74 // Sort features by their importance, highest importance first
75 featureList.sort((a, b) => {
76 return b.importance - a.importance;
77 });
78
79 // Print top 10 important features
80 console.log('Features of top importance');
81 console.log(featureList.slice(0, 10));
82 }
83 }
84 predict();
85 // [END automl_tables_predict]
86}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected