本文整理汇总了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();
}
}