Strata — Native Machine Learning in Pure Mojo
Machine learning in pure Mojo.
Scikit-learn-compatible estimators, SIMD-vectorized matrices, sparse algebra, and zero-copy binary persistence compiled directly to native code.
from strata.core import Matrixfrom strata.base import PipelineClassifierfrom strata.preprocessing import StandardScalerfrom 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)from strata.mixture import GaussianMixturefrom strata.cluster import KMeans
var gmm = GaussianMixture( n_components=3, covariance_type="full", random_state=42,)gmm.fit(X)var probs = gmm.predict_proba(X)
var labels = KMeans(n_clusters=3).fit_predict(X)from strata.linear_model import Ridgefrom strata.io import dump, load
var model = Ridge[DType.float64](alpha=0.5)model.fit(X_train, y_train)
# Endian-safe binary serializationdump(model, "ridge.strata")var restored = load[Ridge[DType.float64]]( "ridge.strata")var preds = restored.predict(X_test)Benchmarks vs. scikit-learn
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
Documentation
Tutorials
Installation with Pixi, LAPACK setup, and composable ML pipelines.
How-To Guides
Serialization, hyperparameter search, OOB validation, and sparse ops.
Concepts
Memory layouts, trait composition, streaming histograms, and benchmarks.
Editing Docs
Guide for contributors adding tutorials, guides, or Mojo docstrings.