use of com.google.cloud.aiplatform.v1.schema.predict.prediction.TabularClassificationPredictionResult in project java-aiplatform by googleapis.
the class PredictTabularClassificationSample method predictTabularClassification.
static void predictTabularClassification(String instance, String project, String endpointId) throws IOException {
PredictionServiceSettings predictionServiceSettings = PredictionServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create(predictionServiceSettings)) {
String location = "us-central1";
EndpointName endpointName = EndpointName.of(project, location, endpointId);
ListValue.Builder listValue = ListValue.newBuilder();
JsonFormat.parser().merge(instance, listValue);
List<Value> instanceList = listValue.getValuesList();
Value parameters = Value.newBuilder().setListValue(listValue).build();
PredictResponse predictResponse = predictionServiceClient.predict(endpointName, instanceList, parameters);
System.out.println("Predict Tabular Classification Response");
System.out.format("\tDeployed Model Id: %s\n", predictResponse.getDeployedModelId());
System.out.println("Predictions");
for (Value prediction : predictResponse.getPredictionsList()) {
TabularClassificationPredictionResult.Builder resultBuilder = TabularClassificationPredictionResult.newBuilder();
TabularClassificationPredictionResult result = (TabularClassificationPredictionResult) ValueConverter.fromValue(resultBuilder, prediction);
for (int i = 0; i < result.getClassesCount(); i++) {
System.out.printf("\tClass: %s", result.getClasses(i));
System.out.printf("\tScore: %f", result.getScores(i));
}
}
}
}
Aggregations