@GedasZ It's possible using the following constructs, but there are some little issues that will be fixed in the next release of MLDB
var functionConfig = {
type: 'sql.query',
params: {
query: 'select horizontal_sum(value) as value, column FROM row_dataset($input)',
output: 'NAMED_COLUMNS'
}
};
var fn = mldb.put('/v1/functions/score_many', functionConfig);
mldb.log(fn);
var functionConfig2 = {
type: 'sql.expression',
params: {
expression: 'score_many({input: rowsToScore})[output] AS *',
prepared: true
}
};
var fn2 = mldb.put('/v1/functions/scorer', functionConfig2);
mldb.log(fn2);
var input = { rowsToScore: [ { x: 1, y: 2}, {a: 2, b: 3, c: 4} ] };
var res = mldb.get('/v1/functions/scorer/application',
{ input: input, outputFormat: 'json' });
mldb.log(res);
What this does is a) creates an sql.function object to actually perform the multi row classification (by using row_dataset to turn the input row, which is variable length, into a table). The horizontal_sum function is a placeholder; you would use whatever function implemented your logic eg a classifier, b) creates a prepared sql.expression as an interface (this avoids re-binding the expression on every call, which is expensive, although maybe it doesn't matter if you are calling with a payload of 1,000 values), and c) calls the endpoint with two rows. It produces a JSON output of [ 3, 9 ], which is the horizontal sum of elements of each of the input rows.
If you need to get going on this before the next release (next week), then we can show you how to set up an endpoint using a JS plugin that can perform arbitrary logic in response to an arbitrary route. There is slightly more code and it will be a little slower as it's implemented in JS, but it should work fine. Let us know.
`mldb.put("/v1/functions/eval_function1", {
"type": "sql.query",
"params": {
"query": "select horizontal_sum(value) as value, column FROM row_dataset($input)",
"output": "NAMED_COLUMNS"
}
})
mldb.put("/v1/functions/score_many1", {
"type": "sql.expression",
"params": {
"expression": "eval_function1({input: rowToScore})[output] AS *",
"prepared": True
}
})
mldb.get('/v1/functions/score_many1/application',{ "input": { "rowToScore":[{ "x": 1, "y": 2}, {"a": 2, "b": 3, "c": 4}] }})
`
COLUMN EXPR
you can implement quite sophisticated feature selection logic (for example, in https://github.com/mldbai/mldb/blob/master/testing/MLDB-498-svd-apply-function.js#L101 we have a feature selection select as select COLUMN EXPR (AS columnName() WHERE rowCount() > 100 ORDER BY rowCount() DESC, columnName() LIMIT 1000) from reddit_dataset
, which selects the 1,000 most frequent (sparse) features that occur more than 1,000 times. jseval
is a great escape hatch for when you need to do something that's not possible otherwise, and it is pretty fast, so that's another option. And you're certainly not bothering us, keep the questions coming!
mldb_data/plugins/autoload/<pluginname>
directory, and it will be loaded by MLDB on startup.
/v1/functions/<classifier>/details
although currently it's not possible to re-import that elsewhere.
SELECT [ classifier1(features), classifier2(features), classifier3(features) ]
to return a 3-element vector with the three models.