Search in sources :

Example 1 with DefaultDataFrame

use of org.opensearch.ml.common.dataframe.DefaultDataFrame in project ml-commons by opensearch-project.

the class MLPredictionOutputTest method setUp.

@Before
public void setUp() {
    ColumnMeta[] columnMetas = new ColumnMeta[] { new ColumnMeta("test", ColumnType.INTEGER) };
    List<Row> rows = new ArrayList<>();
    rows.add(new Row(new ColumnValue[] { new IntValue(1) }));
    rows.add(new Row(new ColumnValue[] { new IntValue(2) }));
    DataFrame dataFrame = new DefaultDataFrame(columnMetas, rows);
    output = MLPredictionOutput.builder().taskId("test_task_id").status("test_status").predictionResult(dataFrame).build();
}
Also used : ColumnMeta(org.opensearch.ml.common.dataframe.ColumnMeta) ArrayList(java.util.ArrayList) ColumnValue(org.opensearch.ml.common.dataframe.ColumnValue) Row(org.opensearch.ml.common.dataframe.Row) DataFrame(org.opensearch.ml.common.dataframe.DataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) IntValue(org.opensearch.ml.common.dataframe.IntValue) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) Before(org.junit.Before)

Example 2 with DefaultDataFrame

use of org.opensearch.ml.common.dataframe.DefaultDataFrame in project ml-commons by opensearch-project.

the class FixedInTimeRandomCutForestTest method constructRCFDataFrame.

private DataFrame constructRCFDataFrame(boolean predict) {
    ColumnMeta[] columnMetas = new ColumnMeta[] { new ColumnMeta("timestamp", ColumnType.LONG), new ColumnMeta("value", ColumnType.INTEGER) };
    DataFrame dataFrame = new DefaultDataFrame(columnMetas);
    long startTime = 1643677200000l;
    for (int i = 0; i < dataSize; i++) {
        // 1 minute interval
        long time = startTime + i * 1000 * 60;
        if (predict && i % 100 == 0) {
            dataFrame.appendRow(new Object[] { time, ThreadLocalRandom.current().nextInt(100, 1000) });
        } else {
            dataFrame.appendRow(new Object[] { time, ThreadLocalRandom.current().nextInt(1, 10) });
        }
    }
    return dataFrame;
}
Also used : ColumnMeta(org.opensearch.ml.common.dataframe.ColumnMeta) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) DataFrame(org.opensearch.ml.common.dataframe.DataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame)

Example 3 with DefaultDataFrame

use of org.opensearch.ml.common.dataframe.DefaultDataFrame in project ml-commons by opensearch-project.

the class AnomalyDetectionLibSVMTest method constructDataFrame.

private DataFrame constructDataFrame(Dataset<Event> data, boolean training, List<Event.EventType> labels) {
    Iterator<Example<Event>> iterator = data.iterator();
    List<ColumnMeta> columns = null;
    DataFrame dataFrame = null;
    while (iterator.hasNext()) {
        Example<Event> example = iterator.next();
        if (columns == null) {
            columns = new ArrayList<>();
            List<ColumnValue> columnValues = new ArrayList<>();
            for (Feature feature : example) {
                columns.add(new ColumnMeta(feature.getName(), ColumnType.DOUBLE));
                columnValues.add(new DoubleValue(feature.getValue()));
            }
            ColumnMeta[] columnMetas = columns.toArray(new ColumnMeta[columns.size()]);
            dataFrame = new DefaultDataFrame(columnMetas);
            addRow(columnValues, training, example, dataFrame, labels);
        } else {
            List<ColumnValue> columnValues = new ArrayList<>();
            for (Feature feature : example) {
                columnValues.add(new DoubleValue(feature.getValue()));
            }
            addRow(columnValues, training, example, dataFrame, labels);
        }
    }
    return dataFrame;
}
Also used : ArrayList(java.util.ArrayList) DataFrame(org.opensearch.ml.common.dataframe.DataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) Feature(org.tribuo.Feature) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) ColumnMeta(org.opensearch.ml.common.dataframe.ColumnMeta) DoubleValue(org.opensearch.ml.common.dataframe.DoubleValue) Example(org.tribuo.Example) Event(org.tribuo.anomaly.Event) ColumnValue(org.opensearch.ml.common.dataframe.ColumnValue)

Example 4 with DefaultDataFrame

use of org.opensearch.ml.common.dataframe.DefaultDataFrame in project ml-commons by opensearch-project.

the class MLInputTest method setUp.

@Before
public void setUp() throws Exception {
    final ColumnMeta[] columnMetas = new ColumnMeta[] { new ColumnMeta("test", ColumnType.DOUBLE) };
    List<Row> rows = new ArrayList<>();
    rows.add(new Row(new ColumnValue[] { new DoubleValue(1.0) }));
    rows.add(new Row(new ColumnValue[] { new DoubleValue(2.0) }));
    rows.add(new Row(new ColumnValue[] { new DoubleValue(3.0) }));
    DataFrame dataFrame = new DefaultDataFrame(columnMetas, rows);
    input = MLInput.builder().algorithm(algorithm).parameters(LinearRegressionParams.builder().learningRate(0.1).build()).inputDataset(DataFrameInputDataset.builder().dataFrame(dataFrame).build()).build();
}
Also used : ColumnMeta(org.opensearch.ml.common.dataframe.ColumnMeta) DoubleValue(org.opensearch.ml.common.dataframe.DoubleValue) ArrayList(java.util.ArrayList) ColumnValue(org.opensearch.ml.common.dataframe.ColumnValue) Row(org.opensearch.ml.common.dataframe.Row) DataFrame(org.opensearch.ml.common.dataframe.DataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) Before(org.junit.Before)

Example 5 with DefaultDataFrame

use of org.opensearch.ml.common.dataframe.DefaultDataFrame in project ml-commons by opensearch-project.

the class BatchRandomCutForestTest method constructRCFDataFrame.

private DataFrame constructRCFDataFrame(boolean predict) {
    ColumnMeta[] columnMetas = new ColumnMeta[] { new ColumnMeta("value", ColumnType.INTEGER) };
    DataFrame dataFrame = new DefaultDataFrame(columnMetas);
    for (int i = 0; i < dataSize; i++) {
        if (predict && i % 100 == 0) {
            dataFrame.appendRow(new Object[] { ThreadLocalRandom.current().nextInt(100, 1000) });
        } else {
            dataFrame.appendRow(new Object[] { ThreadLocalRandom.current().nextInt(1, 10) });
        }
    }
    return dataFrame;
}
Also used : ColumnMeta(org.opensearch.ml.common.dataframe.ColumnMeta) DataFrame(org.opensearch.ml.common.dataframe.DataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame) DefaultDataFrame(org.opensearch.ml.common.dataframe.DefaultDataFrame)

Aggregations

ColumnMeta (org.opensearch.ml.common.dataframe.ColumnMeta)6 DataFrame (org.opensearch.ml.common.dataframe.DataFrame)6 DefaultDataFrame (org.opensearch.ml.common.dataframe.DefaultDataFrame)6 ArrayList (java.util.ArrayList)3 ColumnValue (org.opensearch.ml.common.dataframe.ColumnValue)3 Before (org.junit.Before)2 DoubleValue (org.opensearch.ml.common.dataframe.DoubleValue)2 Row (org.opensearch.ml.common.dataframe.Row)2 IntValue (org.opensearch.ml.common.dataframe.IntValue)1 Example (org.tribuo.Example)1 Feature (org.tribuo.Feature)1 Event (org.tribuo.anomaly.Event)1