@saltcorn/smartcore-js
v0.2.20
Published
Template project for writing node package with napi-rs
Downloads
67
Readme
SmartCore-JS Documentation
Welcome to the comprehensive documentation for SmartCore-JS, a powerful machine learning library for Node.js that brings the performance of Rust's SmartCore to the JavaScript ecosystem.
Table of Contents
Getting Started
User Guide
Supervised Learning
Unsupervised Learning
Data Preprocessing
Model Evaluation
Advanced Topics
API Reference
Examples
Tutorials
What is SmartCore-JS?
SmartCore-JS is a Node.js machine learning library that provides:
- High Performance: Built on top of Rust's SmartCore using NAPI-RS for native performance
- Scikit-learn Compatible API: Familiar interface for data scientists and ML engineers
- TypeScript Support: Full type definitions for better developer experience
- Comprehensive Algorithms: Wide range of supervised and unsupervised learning algorithms
- DataFrame Support: Flexible data handling with built-in DataFrame functionality
- Pipeline System: Chain transformers and estimators for efficient workflows
Key Features
🚀 Performance
Native Rust implementation ensures fast computation for large datasets.
🔧 Easy to Use
Scikit-learn inspired API makes it simple to get started:
import { linearModel, dataset } from '@saltcorn/smartcore-js'
const { LinearRegression } = linearModel
const { loadIris } = dataset
// Load data
const [x, y] = loadIris({ returnXY: true })
// Create and train model
const model = new LinearRegression()
model.fit(x, y)
// Make predictions
const predictions = model.predict(x)🎯 Comprehensive
Wide range of algorithms covering:
- Regression: Linear, Ridge, Lasso, ElasticNet, SVR, Decision Trees, Random Forests
- Classification: Logistic Regression, SVC, Decision Trees, Random Forests, Naive Bayes, KNN
- Clustering: K-Means, DBSCAN
- Dimensionality Reduction: PCA, SVD
- Preprocessing: StandardScaler, OneHotEncoder
🔄 Pipelines
Chain multiple operations together:
import { pipeline, preprocessing, linearModel } from '@saltcorn/smartcore-js'
const pipe = pipeline.makePipeline([new preprocessing.StandardScaler(), new linearModel.LogisticRegression()])
pipe.fit(x, y)
const predictions = pipe.predict(x)💾 Model Persistence
Save and load trained models:
// Save model
const serialized = model.serialize()
// Load model
const loadedModel = LinearRegression.deserialize(serialized)Installation
npm install @saltcorn/smartcore-jsOr with yarn:
yarn add @saltcorn/smartcore-jsQuick Example
Here's a complete example of training a Random Forest Classifier:
import { ensemble, dataset, modelSelection, metrics } from '@saltcorn/smartcore-js'
// Load dataset
const [x, y] = dataset.loadIris({ returnXY: true })
// Split into train and test sets
const [xTrain, xTest, yTrain, yTest] = modelSelection.trainTestSplit(x, y, { testSize: 0.3, randomState: 42 })
// Create and train model
const model = new ensemble.RandomForestClassifier({
nTrees: 100,
maxDepth: 10,
})
model.fit(xTrain, yTrain)
// Make predictions
const predictions = model.predict(xTest)
// Evaluate
const accuracy = metrics.accuracyScore(yTest, predictions)
console.log(`Accuracy: ${accuracy}`)System Requirements
- Node.js: >= 10.0.0
- Supported Platforms:
- Windows (x64, ia32, arm64)
- macOS (x64, arm64/Apple Silicon)
- Linux (x64, arm64, armv7, musl)
- FreeBSD (x64)
- Android (arm64, armv7)
- WebAssembly (wasm32-wasip1-threads)
Contributing
SmartCore-JS is an open-source project. Contributions are welcome!
License
This project is licensed under the MIT License.
Support
- Issues: GitHub Issues
- Documentation: You're reading it!
Next Steps
Built with ❤️ using Rust's SmartCore and NAPI-RS
