|
1 | | -# automl-js |
| 1 | +# automl-js |
| 2 | + |
| 3 | +Automated Machine Learning, done locally in browser or on a server with nodejs. Ground up implementation of ML algorithms for both regression and classification, such as Decision Trees, Linear Models and Gradient Boosting with Decision Trees. The implementation is benchmarked against excellent `scikit-learn` library to give quite close, albeit somewhat smaller (at most 1 percent of classification accuracy on average) score. |
| 4 | + |
| 5 | +# Installation |
| 6 | + |
| 7 | +The code should be used in browser using standard script import: |
| 8 | + |
| 9 | +```html |
| 10 | +<script src="./dist/automljs.js"></script> |
| 11 | +``` |
| 12 | + |
| 13 | +This creates a global `aml` object, that can be used to instantiate the models, do data splitting and preprocessing, etc. If you wish to run it in nodejs, install the package with npm and import using `require`. |
| 14 | + |
| 15 | +# Docs and examples |
| 16 | + |
| 17 | +Below this section are two examples for how to use code in automl-js. Beyond this, see docs at [https://automl-js.github.io](https://automl-js.github.io) for description of objects and functions of automljs, and `tests` folder for example usage of functionality. |
| 18 | + |
| 19 | +# Example automl estimator |
| 20 | + |
| 21 | +```javascript |
| 22 | +// automl-js uses asynchronous functionality of JavaScript |
| 23 | +async function main(){ |
| 24 | + // Each row is an observation, each column is a feature (similar to numpy) |
| 25 | + // Mixed types: categorical and numerical, missing values are handled automatically |
| 26 | + var X = [ |
| 27 | + ['a', 0.6], |
| 28 | + ['b', -1.3], |
| 29 | + ['a', 1.1], |
| 30 | + ['b', -2], |
| 31 | + ['a', 0.5], |
| 32 | + ['b', ""], // missing value |
| 33 | + ['a', 0.4], |
| 34 | + ['', 1.1], // missing value |
| 35 | + ['b', -0.8], |
| 36 | + ['a', "1e-1"] // wrong type |
| 37 | + ] |
| 38 | + |
| 39 | + // Outputs are a vector / 1d array |
| 40 | + var y = ['pos', 'neg', 'pos', 'neg', 'neg', 'pos', 'neg', 'pos', 'neg', 'pos'] |
| 41 | + |
| 42 | + // Create a model instance |
| 43 | + var model = new aml.automl.AutoMLModel({ |
| 44 | + 'max_iter': 7 // specifies how many iterations you are willing to wait for result |
| 45 | + }) |
| 46 | + |
| 47 | + // Does internally data splitting into training and testing |
| 48 | + // Tries a bunch of ML models to see which one fits best |
| 49 | + await model.fit(X, y) |
| 50 | + |
| 51 | + // Evaluate the best found model |
| 52 | + var score = await model.score(X, y) |
| 53 | + |
| 54 | + // Get estimations by the model; Interface same as sklearn |
| 55 | + var y_pred = await model.predict(X) |
| 56 | +} |
| 57 | + |
| 58 | +// run the async function |
| 59 | +main() |
| 60 | +``` |
| 61 | + |
| 62 | +# Example learning with estimator |
| 63 | + |
| 64 | +The code should be run in browser. If you wish to run it in nodejs, install the package with npm and import using `require`. |
| 65 | + |
| 66 | +```html |
| 67 | +<script src="./dist/automljs.js"></script> |
| 68 | + |
| 69 | +<script> |
| 70 | + async function main(){ |
| 71 | + // Data needs to be of numeric type for regular estimators |
| 72 | + var X = [ |
| 73 | + [1, 0], |
| 74 | + [0, 1], |
| 75 | + [1, 1], |
| 76 | + [0, 0] |
| 77 | + ] |
| 78 | +
|
| 79 | + // Outputs are a vector / 1d array |
| 80 | + var y = [1, 2, 2, 0] |
| 81 | +
|
| 82 | + // Create a model instance; Names of parameters are mostly similar to sklearn |
| 83 | + var model = new aml.ensemble.GradientBoostingRegressor({'n_estimators':10, 'learning_rate': 1.0, 'loss': 'ls'}) |
| 84 | +
|
| 85 | + // Fit the model |
| 86 | + await model.fit(X, y) |
| 87 | +
|
| 88 | + // Evaluate the model |
| 89 | + var score = await model.score(X, y) |
| 90 | +
|
| 91 | + // Get estimations by the model; Interface same as sklearn |
| 92 | + var y_pred = await model.predict(X) |
| 93 | + } |
| 94 | +
|
| 95 | + main() |
| 96 | +</script> |
| 97 | +``` |
| 98 | + |
0 commit comments