Node.js bindings for XGBoost (Linux only)
npm install xgboost_node```
██╗ ██╗ ██████╗ ██████╗ ██████╗ ██████╗ ███████╗████████╗ ███╗ ██╗ ██████╗ ██████╗ ███████╗
╚██╗██╔╝██╔════╝ ██╔══██╗██╔═══██╗██╔═══██╗██╔════╝╚══██╔══╝ ████╗ ██║██╔═══██╗██╔══██╗██╔════╝
╚███╔╝ ██║ ███╗██████╔╝██║ ██║██║ ██║███████╗ ██║ ██╔██╗ ██║██║ ██║██║ ██║█████╗
██╔██╗ ██║ ██║██╔══██╗██║ ██║██║ ██║╚════██║ ██║ ██║╚██╗██║██║ ██║██║ ██║██╔══╝
██╔╝ ██╗╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝███████║ ██║ ██║ ╚████║╚██████╔╝██████╔╝███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝
Fast, native Node.js bindings for XGBoost (Linux & MAC)
Sometimes you will need to install these python packages if not present on you system.
- setuptools -- Builds/install Python packages, especially ones with C extensions
- distutils -- Legacy build helper, still assumed by some packages
- libomp -- Enables OpenMP support for multithreaded C++ libraries like XGBoost
bash
npm install xgboost_node
`Quick Start
`typescript
import xgboost from 'xgboost_node';// Training example
const features = [
[1200, 8, 10, 0, 1, 1], // example data could be housing or flight
[800, 14, 15, 1, 2, 0],
[950, 10, 12, 1, 1, 0],
[1000, 9, 11, 0, 0, 1],
[1100, 13, 14, 0, 2, 1],
];
const labels = [250, 180]; // Prices
const params = {
max_depth: 3,
eta: 0.1,
objective: 'reg:squarederror',
eval_metric: 'rmse'
};
async function main() {
// Train model
await xgboost.train(features, labels, params);
// Save the trained model
await xgboost.saveModel('model.xgb');
// Load model for predictions
await xgboost.loadModel('model.xgb');
// Make predictions
const predictions = await xgboost.predict([[1300, 9, 11, 0, 1, 1]]);
console.log('Predicted price:', predictions[0]);
}
main().catch(console.error);
`API Reference
$3
Trains an XGBoost model with the provided features and labels.Parameters:
-
features: 2D array of training features
- labels: Array of training labels
- params: XGBoost parameters object$3
Makes predictions using the trained model.Parameters:
-
features: 2D array of features to predictReturns:
- Array of predictions
$3
Saves the trained model to disk.Parameters:
-
path: File path to save the model$3
Loads a trained model from disk.Parameters:
-
path: Path to the saved model fileBuilding from Source
1. Clone the repository:
`bash
git clone https://github.com/yourusername/xgboost-node.git
`2. Install dependencies:
`bash
npm install
`3. Build the native module:
`bash
npm run build
``