Search in sources :

Example 16 with MLInput

use of org.opensearch.ml.common.parameter.MLInput in project ml-commons by opensearch-project.

the class MachineLearningClientTest method predict_WithAlgoAndInputDataAndParametersAndListener.

@Test
public void predict_WithAlgoAndInputDataAndParametersAndListener() {
    MLInput mlInput = MLInput.builder().algorithm(FunctionName.KMEANS).parameters(mlParameters).inputDataset(new DataFrameInputDataset(input)).build();
    ArgumentCaptor<MLOutput> dataFrameArgumentCaptor = ArgumentCaptor.forClass(MLOutput.class);
    machineLearningClient.predict(null, mlInput, dataFrameActionListener);
    verify(dataFrameActionListener).onResponse(dataFrameArgumentCaptor.capture());
    assertEquals(output, dataFrameArgumentCaptor.getValue());
}
Also used : MLInput(org.opensearch.ml.common.parameter.MLInput) DataFrameInputDataset(org.opensearch.ml.common.dataset.DataFrameInputDataset) MLOutput(org.opensearch.ml.common.parameter.MLOutput) Test(org.junit.Test)

Example 17 with MLInput

use of org.opensearch.ml.common.parameter.MLInput in project ml-commons by opensearch-project.

the class MachineLearningClientTest method predict_WithAlgoAndParametersAndInputData.

@Test
public void predict_WithAlgoAndParametersAndInputData() {
    MLInput mlInput = MLInput.builder().algorithm(FunctionName.KMEANS).parameters(mlParameters).inputDataset(new DataFrameInputDataset(input)).build();
    assertEquals(output, machineLearningClient.predict(null, mlInput).actionGet());
}
Also used : MLInput(org.opensearch.ml.common.parameter.MLInput) DataFrameInputDataset(org.opensearch.ml.common.dataset.DataFrameInputDataset) Test(org.junit.Test)

Example 18 with MLInput

use of org.opensearch.ml.common.parameter.MLInput in project ml-commons by opensearch-project.

the class MLEngineTest method predictWithoutAlgoName.

@Test
public void predictWithoutAlgoName() {
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("algorithm can't be null");
    MLInputDataset inputDataset = DataFrameInputDataset.builder().dataFrame(constructKMeansDataFrame(10)).build();
    Input mlInput = MLInput.builder().inputDataset(inputDataset).build();
    MLEngine.predict(mlInput, null);
}
Also used : MLInput(org.opensearch.ml.common.parameter.MLInput) Input(org.opensearch.ml.common.parameter.Input) LocalSampleCalculatorInput(org.opensearch.ml.common.parameter.LocalSampleCalculatorInput) MLInputDataset(org.opensearch.ml.common.dataset.MLInputDataset) Test(org.junit.Test)

Example 19 with MLInput

use of org.opensearch.ml.common.parameter.MLInput in project ml-commons by opensearch-project.

the class MLEngineTest method predictUnsupportedAlgorithm.

@Test
public void predictUnsupportedAlgorithm() {
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("Unsupported algorithm: LINEAR_REGRESSION");
    FunctionName algoName = FunctionName.LINEAR_REGRESSION;
    try (MockedStatic<MLEngineClassLoader> loader = Mockito.mockStatic(MLEngineClassLoader.class)) {
        loader.when(() -> MLEngineClassLoader.initInstance(algoName, null, MLAlgoParams.class)).thenReturn(null);
        MLInputDataset inputDataset = DataFrameInputDataset.builder().dataFrame(constructLinearRegressionPredictionDataFrame()).build();
        Input mlInput = MLInput.builder().algorithm(algoName).inputDataset(inputDataset).build();
        MLEngine.predict(mlInput, null);
    }
}
Also used : FunctionName(org.opensearch.ml.common.parameter.FunctionName) MLInput(org.opensearch.ml.common.parameter.MLInput) Input(org.opensearch.ml.common.parameter.Input) LocalSampleCalculatorInput(org.opensearch.ml.common.parameter.LocalSampleCalculatorInput) MLInputDataset(org.opensearch.ml.common.dataset.MLInputDataset) Test(org.junit.Test)

Example 20 with MLInput

use of org.opensearch.ml.common.parameter.MLInput in project ml-commons by opensearch-project.

the class MLEngineTest method trainAndPredictWithInvalidInput.

@Test
public void trainAndPredictWithInvalidInput() {
    exceptionRule.expect(IllegalArgumentException.class);
    exceptionRule.expectMessage("Input should be MLInput");
    Input input = new LocalSampleCalculatorInput("sum", Arrays.asList(1.0, 2.0));
    MLEngine.trainAndPredict(input);
}
Also used : MLInput(org.opensearch.ml.common.parameter.MLInput) Input(org.opensearch.ml.common.parameter.Input) LocalSampleCalculatorInput(org.opensearch.ml.common.parameter.LocalSampleCalculatorInput) LocalSampleCalculatorInput(org.opensearch.ml.common.parameter.LocalSampleCalculatorInput) Test(org.junit.Test)

Aggregations

MLInput (org.opensearch.ml.common.parameter.MLInput)46 Test (org.junit.Test)18 MLInputDataset (org.opensearch.ml.common.dataset.MLInputDataset)13 MLTaskResponse (org.opensearch.ml.common.transport.MLTaskResponse)12 DataFrameInputDataset (org.opensearch.ml.common.dataset.DataFrameInputDataset)11 DataFrame (org.opensearch.ml.common.dataframe.DataFrame)10 Input (org.opensearch.ml.common.parameter.Input)9 LocalSampleCalculatorInput (org.opensearch.ml.common.parameter.LocalSampleCalculatorInput)9 MLPredictionOutput (org.opensearch.ml.common.parameter.MLPredictionOutput)7 MLPredictionTaskRequest (org.opensearch.ml.common.transport.prediction.MLPredictionTaskRequest)7 MLTrainingTaskRequest (org.opensearch.ml.common.transport.training.MLTrainingTaskRequest)7 MLOutput (org.opensearch.ml.common.parameter.MLOutput)6 XContentParser (org.opensearch.common.xcontent.XContentParser)5 Response (org.opensearch.client.Response)4 Model (org.opensearch.ml.common.parameter.Model)4 KMeansHelper.constructKMeansDataFrame (org.opensearch.ml.engine.helper.KMeansHelper.constructKMeansDataFrame)4 LinearRegressionHelper.constructLinearRegressionPredictionDataFrame (org.opensearch.ml.engine.helper.LinearRegressionHelper.constructLinearRegressionPredictionDataFrame)4 LinearRegressionHelper.constructLinearRegressionTrainDataFrame (org.opensearch.ml.engine.helper.LinearRegressionHelper.constructLinearRegressionTrainDataFrame)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Instant (java.time.Instant)3