Install and load
Run these commands in a Haybarn SQL session. The extension is available from the community repository.
INSTALL mlpack FROM community;
LOAD mlpack FROM community;
Using upstream DuckDB? Follow the maintainer’s installation instructions.
Usage example
Perform adaBoost (using weak learner 'Perceptron' by default)
-- Perform adaBoost (using weak learner 'Perceptron' by default)
-- Read 'features' into 'X', 'labels' into 'Y', use optional parameters
-- from 'Z', and prepare model storage in 'M'
CREATE TABLE X AS SELECT * FROM read_csv("https://eddelbuettel.github.io/duckdb-mlpack/data/iris.csv");
CREATE TABLE Y AS SELECT * FROM read_csv("https://eddelbuettel.github.io/duckdb-mlpack/data/iris_labels.csv");
CREATE TABLE Z (name VARCHAR, value VARCHAR);
INSERT INTO Z VALUES ('iterations', '50'), ('tolerance', '1e-7');
CREATE TABLE M (key VARCHAR, json VARCHAR);
-- Train model for 'Y' on 'X' using parameters 'Z', store in 'M'
CREATE TEMP TABLE A AS SELECT * FROM mlpack_adaboost_train("X", "Y", "Z", "M");
-- Count by predicted group
SELECT COUNT(*) as n, predicted FROM A GROUP BY predicted;
-- Model 'M' can be used to predict
CREATE TABLE N (x1 DOUBLE, x2 DOUBLE, x3 DOUBLE, x4 DOUBLE);
-- inserting approximate column mean values
INSERT INTO N VALUES (5.843, 3.054, 3.759, 1.199);
-- inserting approximate column mean values, min values, max values
INSERT INTO N VALUES (5.843, 3.054, 3.759, 1.199), (4.3, 2.0, 1.0, 0.1), (7.9, 4.4, 6.9, 2.5);
-- and this predict one element each
SELECT * FROM mlpack_adaboost_pred("N", "M");
Provided by eddelbuettel. Not yet verified on Haybarn 2.0.0.
Sample data & setupAbout this extension
The mlpack extension allows to fit (or train) and predict (or classify) from the models implemented, currently adaBoost, Bayesian linear regression, decision tree, LARS, linear regression, logistic regression, naive Bayes, random forests as well as softmax regression. The format is the same for these methods: four tables, say, "X", "Y", "Z" and "M" provide input for, respectively, features "X", labels "Y", optional parameters varying by model in "Z" as well as an output table "M" for the JSON-serialized model. For all methods, following a model fit (or training), a prediction (or classification) can be made using "M" and new predictor values "N" as shown in the example. All these "fit" (or "train") methods take four parameter tables, all "predict" methods take two.
A kMeans clustering method is also available. It uses three tables for data, parameters and results.
Project overview from the community descriptor.
Documentation and resources
Project and build details
- Repository
- eddelbuettel/duckdb-mlpack
- License
- MIT
- Maintainers
- eddelbuettel
- Written in
- C++
- Build source
ed1891ddf415- Build definition
- Community descriptor