use of com.google.cloud.aiplatform.v1.schema.predict.prediction.TabularRegressionPredictionResult in project java-aiplatform by googleapis.
the class PredictTabularRegressionSample method predictTabularRegression.
static void predictTabularRegression(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 Regression Response");
System.out.format("\tDisplay Model Id: %s\n", predictResponse.getDeployedModelId());
System.out.println("Predictions");
for (Value prediction : predictResponse.getPredictionsList()) {
TabularRegressionPredictionResult.Builder resultBuilder = TabularRegressionPredictionResult.newBuilder();
TabularRegressionPredictionResult result = (TabularRegressionPredictionResult) ValueConverter.fromValue(resultBuilder, prediction);
System.out.printf("\tUpper bound: %f\n", result.getUpperBound());
System.out.printf("\tLower bound: %f\n", result.getLowerBound());
System.out.printf("\tValue: %f\n", result.getValue());
}
}
}
Aggregations