Google Prediction API: Node.js Client
![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-prediction/master.svg?style=flat)
Node.js idiomatic client for Prediction API.
The Cloud Prediction API provides a RESTful API to build Machine Learning models.
:warning: Deprecated Module |
---|
This library is deprecated. The API will be shut down on April 30, 2018. See the Prediction API End of Life FAQ for more information. |
Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in Client Libraries Explained.
Table of contents:
Quickstart
Before you begin
-
Select or create a Cloud Platform project.
Go to the projects page
-
Enable billing for your project.
Enable billing
-
Enable the Google Prediction API API.
Enable the API
-
Set up authentication with a service account so you can access the
API from your local workstation.
Installing the client library
npm install --save @google-cloud/prediction
Using the client library
var google = require('googleapis');
function auth(callback) {
google.auth.getApplicationDefault(function(err, authClient) {
if (err) {
return callback(err);
}
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
authClient = authClient.createScoped([
'https://www.googleapis.com/auth/prediction',
]);
}
callback(null, authClient);
});
}
function predict(phrase, callback) {
auth(function(err, authClient) {
if (err) {
return callback(err);
}
var hostedmodels = google.prediction({
version: 'v1.6',
auth: authClient,
}).hostedmodels;
hostedmodels.predict(
{
project: '414649711441',
hostedModelName: 'sample.sentiment',
resource: {
input: {
csvInstance: phrase.split(/\s/gi),
},
},
},
function(err, prediction) {
if (err) {
return callback(err);
}
console.log(`Sentiment for "${phrase}": ${prediction.outputLabel}`);
callback(null, prediction);
}
);
});
}
Samples
Samples are in the samples/
directory. The samples' README.md
has instructions for running the samples.
The Prediction API Node.js Client API Reference documentation
also contains samples.
Versioning
This library follows Semantic Versioning.
This library is deprecated. This means that it is no longer being
actively maintained and the only updates the library will receive will
be for critical security issues.
More Information: Google Cloud Platform Launch Stages
Contributing
Contributions welcome! See the Contributing Guide.
License
Apache Version 2.0
See LICENSE