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();
}
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;
}
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;
}
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();
}
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;
}
Aggregations