Skip to content

Strata — Native Machine Learning in Pure Mojo

v0.2.2 · Mojo ≥ 1.0 · 17 modules · 171 symbols · MIT

Machine learning in pure Mojo.

Scikit-learn-compatible estimators, SIMD-vectorized matrices, sparse algebra, and zero-copy binary persistence compiled directly to native code.

$ pixi add strata -c https://repo.prefix.dev/modular-community
from strata.core import Matrix
from strata.base import PipelineClassifier
from strata.preprocessing import StandardScaler
from strata.ensemble import RandomForestClassifier
var scaler = StandardScaler[DType.float64]()
var rf = RandomForestClassifier[DType.float64](
n_estimators=50, random_state=42
)
var pipe = PipelineClassifier(scaler^, rf^)
pipe.fit(X_train, y_train)
var preds = pipe.predict(X_test)

Benchmarks vs. scikit-learn

Full 53-benchmark report →

Across 53 single-threaded routines on synthetic workloads: 1.79× overall geometric mean speedup (2.15× inference, 1.91× training) with verified numerical parity.

Routine Phase Strata scikit-learn Speedup Parity
PolynomialFeatures (d=2) fit 82.4 µs 602.4 µs 7.31× Exact match
SGDRegressor predict 35.2 µs 225.3 µs 6.40× R² = 1.0000
LogisticRegression predict 90.3 µs 524.8 µs 5.81× Accuracy 1.0000
DecisionTreeClassifier predict 53.9 µs 296.6 µs 5.50× Accuracy 1.0000
KMeans fit 778.8 µs 2.49 ms 3.19× Exact inertia
LinearRegression fit 428.0 µs 1.04 ms 2.44× R² = 1.0000

Design

Contiguous SIMD Matrices

Row-major Matrix[dtype] and lifetime-checked MatrixView slices vectorize inner loops without GC or interpreter dispatch.

Compile-Time Traits

Transformer, Regressor, Classifier, and Clusterer traits inline pipeline stages without virtual tables.

Zero-Copy Binary IO

Persist fitted estimators, scalers, and tree ensembles to disk or byte buffers with versioned header checks via strata.io.

Dense & Sparse Solvers

Pure-Mojo trees, SVMs, GMM, and CSRMatrix SpMM kernels alongside BLAS/LAPACK SVD, QR, and Cholesky routines.

Modules

Browse API reference →
strata.core 32
Core Matrix & Linear Algebra
Fundamental 2D dense Matrix, MatrixView, CSRMatrix, CSCMatrix sparse representations, Dataset containers, and hardware-accelerated BLAS/LAPACK solvers.
strata.preprocessing 10
Feature Preprocessing
StandardScaler, MinMaxScaler, RobustScaler, Normalizer, Binarizer, OneHotEncoder, OrdinalEncoder, LabelEncoder, SimpleImputer, and PolynomialFeatures with streaming SIMD statistics.
strata.linear_model 7
Linear & Generalized Linear Models
LinearRegression via OLS SVD, Ridge Regression via L2 regularization, and LogisticRegression with L-BFGS and SGD optimizers.
strata.svm 4
Support Vector Machines
Linear and kernel Support Vector Classification (LinearSVC, SVC) and Regression (LinearSVR, SVR) with dual coordinate descent, Sequential Minimal Optimization (SMO), and kernel evaluation routines (Linear, RBF, Polynomial, Sigmoid).
strata.tree 17
Decision Trees
Fast recursive classification (Gini, Entropy, Log-Loss) and regression (MSE, Friedman MSE, MAE) trees with streaming histogram split calculations.
strata.ensemble 4
Ensemble Methods
Random Forest Regressors/Classifiers with bootstrap aggregation, and Histogram-based Gradient Tree Boosting (HistGradientBoostingRegressor & HistGradientBoostingClassifier) with fast binning and regularized leaf steps.
strata.naive_bayes 5
Naive Bayes Classifiers
GaussianNB for continuous features, MultinomialNB for discrete counts, BernoulliNB for multivariate binary/boolean features, ComplementNB for imbalanced text classification, and CategoricalNB for integer-coded categorical features.
strata.compose 1
Composite Feature Pipelines
ColumnTransformer for routing heterogeneous feature column subsets to distinct transformers and horizontal concatenation.
strata.cluster 3
Clustering Algorithms
Geometric partitioning K-Means with k-means++ initialization, streaming MiniBatchKMeans, and non-parametric density-based DBSCAN spatial clustering.
strata.mixture 2
Gaussian Mixture Models
Probabilistic density estimation and soft clustering via Expectation-Maximization (GaussianMixture with full, tied, diag, and spherical covariances).
strata.decomposition 2
Matrix Decomposition & Dimensionality Reduction
Principal Component Analysis (PCA) via exact SVD and TruncatedSVD with dense and sparse SpMM linear projection.
strata.neighbors 14
Nearest Neighbors
Distance metrics (Euclidean, Manhattan, Chebyshev, Minkowski, Cosine), nearest neighbors search, and k-NN classification and regression.
strata.model_selection 17
Model Selection & Validation
Cross-validation splitters (K-Fold, Stratified, TimeSeries, Shuffle), cross_val_score, cross_validate, and Grid/Randomized hyperparameter search.
strata.metrics 13
Evaluation Metrics
Regression metrics (MSE, RMSE, MAE, R²), classification metrics (Accuracy, Precision, Recall, F1, Confusion Matrix, Log Loss, ROC AUC), and clustering metrics (Silhouette Score).
strata.base 13
Base Traits & Pipelines
Unified estimator traits (Transformer, Regressor, Classifier, Clusterer) and sequential Pipeline composition wrappers.
strata.utils 18
Utilities & Random
64-bit SplitMix64 PRNG with Lemire unbiased sampling, mathematical activations (softmax, sigmoid, log_sum_exp), and validation helpers.
strata.io 9
Model Persistence & Serialization
Zero-copy, endian-safe binary serialization engine (dump, load, dumps, loads) for fitted estimators, transformers, trees, and ensembles.

Documentation