$ show elixir-nx/scholar
Scholar is a comprehensive machine learning library for Elixir, built directly on Nx (Numerical Elixir). It provides a scikit-learn-inspired API with fit/predict/transform patterns across supervised learning (linear/logistic/ridge/Bayesian ridge regression, SVM, naive Bayes variants, discriminant analysis), unsupervised learning (KMeans, DBSCAN, OPTICS, HDBSCAN, GMM, hierarchical clustering, PCA, KernelPCA, t-SNE, MDS, TriMap), preprocessing (scalers, encoders, imputers), metrics (classification, regression, clustering, ranking, distance), model selection (cross-validation, grid search), optimization (BFGS, Nelder-Mead, Brent), interpolation, and numerical integration. The library is designed for JIT/GPU execution via EXLA, with all numerical kernels written as Nx defn functions and models as Nx.Container structs. The included Livebook notebooks are educational demos, not the primary artifact, so the repository is fundamentally an application/library rather than a data-research project.
The LLM identified 5 files worth highlighting for reuse:
A self-contained KD-tree implementation for exact nearest-neighbor search in Nx tensors. It supports multiple distance metrics, leaf-size tuning, and query-time traversal. The module is isolated enough to be extracted into any Nx-based project needing efficient spatial indexing, and demonstrates careful numerical and recursive tree-building logic.
Implements the NN-descent algorithm for approximate nearest-neighbor search, a core building block for large-scale manifold learning and recommendation systems. It uses randomized projection forests and iterative graph refinement, all inside Nx defn loops for JIT compatibility. This is a non-trivial, reusable algorithm that would be difficult to reimplement correctly.
A full HDBSCAN implementation with mutual reachability, minimum spanning tree construction, cluster hierarchy extraction, and stability-based cluster selection. It handles numerical edge cases like infinities and overflow carefully. The module is a standalone clustering algorithm that can be reused in any Elixir/Nx data pipeline requiring robust density-based clustering.
A JIT-compatible BFGS quasi-Newton optimizer with line search, implemented as an Nx defn loop. It exposes a clean minimize/3 interface and is independent of any specific objective function, making it directly reusable for custom optimization problems in Elixir. The numerical care in handling gradients and step sizes demonstrates strong optimization craftsmanship.
Implements the Ledoit-Wolf shrinkage estimator for covariance matrices, a statistically sophisticated technique that improves conditioning when the number of samples is small relative to dimensions. The module is self-contained, exposes fit/transform-style APIs, and can be extracted for any statistical or financial application needing robust covariance estimation.