use of org.opensearch.ml.common.parameter.MLPredictionOutput in project ml-commons by opensearch-project.
the class BatchRandomCutForestTest method predict.
@Test
public void predict() {
Model model = forest.train(trainDataFrame);
MLPredictionOutput output = (MLPredictionOutput) forest.predict(predictionDataFrame, model);
verifyPredictionResult(output);
}
use of org.opensearch.ml.common.parameter.MLPredictionOutput in project ml-commons by opensearch-project.
the class BatchRandomCutForestTest method trainAndPredict.
@Test
public void trainAndPredict() {
MLPredictionOutput output = (MLPredictionOutput) forest.trainAndPredict(trainDataFrame);
verifyPredictionResult(output);
}
use of org.opensearch.ml.common.parameter.MLPredictionOutput in project ml-commons by opensearch-project.
the class LinearRegressionTest method predict.
@Test
public void predict() {
LinearRegression regression = new LinearRegression(parameters);
Model model = regression.train(trainDataFrame);
MLPredictionOutput output = (MLPredictionOutput) regression.predict(predictionDataFrame, model);
DataFrame predictions = output.getPredictionResult();
Assert.assertEquals(2, predictions.size());
}
use of org.opensearch.ml.common.parameter.MLPredictionOutput in project ml-commons by opensearch-project.
the class IntegTestUtils method predictAndVerifyResult.
// Predict with the model generated, and verify the prediction result.
public static void predictAndVerifyResult(String taskId, MLInputDataset inputDataset) throws IOException {
MLInput mlInput = MLInput.builder().algorithm(FunctionName.KMEANS).inputDataset(inputDataset).build();
MLPredictionTaskRequest predictionRequest = new MLPredictionTaskRequest(taskId, mlInput);
ActionFuture<MLTaskResponse> predictionFuture = client().execute(MLPredictionTaskAction.INSTANCE, predictionRequest);
MLTaskResponse predictionResponse = predictionFuture.actionGet();
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.startObject();
MLPredictionOutput mlPredictionOutput = (MLPredictionOutput) predictionResponse.getOutput();
mlPredictionOutput.getPredictionResult().toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String jsonStr = Strings.toString(builder);
String expectedStr1 = "{\"column_metas\":[{\"name\":\"ClusterID\",\"column_type\":\"INTEGER\"}]," + "\"rows\":[{\"values\":[{\"column_type\":\"INTEGER\",\"value\":0}]}]}";
String expectedStr2 = "{\"column_metas\":[{\"name\":\"ClusterID\",\"column_type\":\"INTEGER\"}]," + "\"rows\":[{\"values\":[{\"column_type\":\"INTEGER\",\"value\":1}]}]}";
// The prediction result would not be a fixed value.
assertTrue(expectedStr1.equals(jsonStr) || expectedStr2.equals(jsonStr));
}
Aggregations