本文整理匯總了Java中com.google.api.services.prediction.Prediction類的典型用法代碼示例。如果您正苦於以下問題:Java Prediction類的具體用法?Java Prediction怎麽用?Java Prediction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Prediction類屬於com.google.api.services.prediction包,在下文中一共展示了Prediction類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MpcaGooglePredictionAPIClassifier
import com.google.api.services.prediction.Prediction; //導入依賴的package包/類
public MpcaGooglePredictionAPIClassifier() throws GeneralSecurityException, IOException, Exception {
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// initialize the data store factory
dataDir = new FileDataStoreFactory(DATA_DIR);
storeDir = new FileDataStoreFactory(STORE_DIR);
// authorization
Credential credential = authorize();
// set up global Prediction instance
client = new Prediction.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
}
示例2: authenticate
import com.google.api.services.prediction.Prediction; //導入依賴的package包/類
public Prediction authenticate() {
JsonFactory JSON_FACTORY = new JacksonFactory();
Set<String> scopes = new HashSet<String>();
scopes.add(PredictionScopes.DEVSTORAGE_FULL_CONTROL);
scopes.add(PredictionScopes.DEVSTORAGE_READ_ONLY);
scopes.add(PredictionScopes.DEVSTORAGE_READ_WRITE);
scopes.add(PredictionScopes.PREDICTION);
GoogleCredential credential = null;
try {
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(Constants.GCP_ACCOUNT_ID)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(new File(Constants.GCP_ACCOUNT_KEY))
.build();
// set up global Prediction instance
client = new Prediction.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(Constants.APPLICATION_NAME).build();
} catch (Exception x) {
x.printStackTrace();
}
return client;
}
示例3: main
import com.google.api.services.prediction.Prediction; //導入依賴的package包/類
public static void main(String[] args) {
try {
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// initialize the data store factory
//dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// authorization
MpcaGooglePredictionAPIClassifier bla = new MpcaGooglePredictionAPIClassifier();
Credential credential = bla.authorize();
// set up global Prediction instance
client = new Prediction.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
Output output = bla.getGoogleOutput("I'm very happy");
//client.trainedmodels().predict("109973074802", "sentiment", input).execute();
System.out.println(output.toPrettyString());
List<Output.OutputMulti> multi = output.getOutputMulti();
System.out.println("--------------------------");
for (Output.OutputMulti oo : multi) {
//System.out.println(oo.toPrettyString());
System.out.println(oo.getScore());
}
} catch (IOException e) {
System.err.println(e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}