Search in sources :

Example 1 with TabularRegressionPredictionResult

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());
        }
    }
}
Also used : PredictionServiceSettings(com.google.cloud.aiplatform.v1.PredictionServiceSettings) EndpointName(com.google.cloud.aiplatform.v1.EndpointName) TabularRegressionPredictionResult(com.google.cloud.aiplatform.v1.schema.predict.prediction.TabularRegressionPredictionResult) ListValue(com.google.protobuf.ListValue) ListValue(com.google.protobuf.ListValue) Value(com.google.protobuf.Value) PredictResponse(com.google.cloud.aiplatform.v1.PredictResponse) PredictionServiceClient(com.google.cloud.aiplatform.v1.PredictionServiceClient)

Aggregations

EndpointName (com.google.cloud.aiplatform.v1.EndpointName)1 PredictResponse (com.google.cloud.aiplatform.v1.PredictResponse)1 PredictionServiceClient (com.google.cloud.aiplatform.v1.PredictionServiceClient)1 PredictionServiceSettings (com.google.cloud.aiplatform.v1.PredictionServiceSettings)1 TabularRegressionPredictionResult (com.google.cloud.aiplatform.v1.schema.predict.prediction.TabularRegressionPredictionResult)1 ListValue (com.google.protobuf.ListValue)1 Value (com.google.protobuf.Value)1