A simple, educational machine learning library built from scratch using NumPy
Project description
LynxLearn
A beginner-friendly machine learning library built from scratch with NumPy.
Educational. Transparent. CPU-optimized for small-to-medium models.
Made by lousybook01 | YouTube: LousyBook
Why LynxLearn?
Where We Excel
| Feature | LynxLearn | PyTorch (CPU) | TensorFlow (CPU) |
|---|---|---|---|
| Neural Network Training | 2-5x faster | baseline | 2-3x slower |
| Framework Overhead | Near zero | High | Very High |
| Code Readability | Pure NumPy | C++ backend | Complex graph |
| Beginner Friendly | โ Simple API | Moderate | Steep learning curve |
| Educational Value | โ Learn ML fundamentals | Abstraction layers | Hidden complexity |
Honest Performance Claims
We WIN at:
- ๐ Neural networks on CPU - 2-5x faster than PyTorch, 3-10x faster than TensorFlow
- ๐ Educational value - Every line is readable NumPy, perfect for learning
- ๐ฏ Small-to-medium models - Where framework overhead dominates
- ๐ง Customization - Full control over dtypes, initializers, regularizers
We DON'T claim to beat:
- โ scikit-learn for linear regression (they have decades of optimization)
- โ GPU-accelerated frameworks for large models
- โ Production systems requiring distributed training
Our NICHE: Educational ML library for learning, prototyping, and CPU-based inference.
Features
Linear Models
- LinearRegression (OLS), GradientDescentRegressor
- Ridge, Lasso, ElasticNet (regularized regression)
- PolynomialRegression, HuberRegressor, QuantileRegressor, BayesianRidge
Neural Networks
- Sequential model (Keras-like API)
- Dense layers with multiple activations (ReLU, GELU, Swish, Mish, etc.)
- Multiple precision support: float16, float32, float64, bfloat16
- Weight initializers: He, Xavier, LeCun, Orthogonal
- Regularizers: L1, L2, Elastic Net
- Constraints: MaxNorm, NonNeg, UnitNorm
Model Selection & Metrics
- train_test_split
- MSE, RMSE, MAE, Rยฒ score
Visualizations
- Regression plots, cost history, residual analysis
- Model comparison charts
Installation
# Basic installation
pip install lynxlearn
# With BF16 support
pip install lynxlearn[bf16]
# With all features
pip install lynxlearn[all]
Or install from source:
git clone https://github.com/notlousybook/LynxLearn.git
cd LynxLearn
pip install -e .
Quick Start
Linear Regression
import numpy as np
from lynxlearn import LinearRegression, train_test_split, metrics
# Generate data
X = np.random.randn(100, 1)
y = 3 * X.flatten() + 5 + np.random.randn(100) * 0.5
# Split and train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = LinearRegression()
model.train(X_train, y_train)
# Evaluate
predictions = model.predict(X_test)
print(f"Rยฒ Score: {metrics.r2_score(y_test, predictions):.4f}")
Neural Network
from lynxlearn import Sequential, Dense, SGD
# Build model
model = Sequential([
Dense(128, activation='relu', input_shape=(10,)),
Dense(64, activation='relu'),
Dense(1)
])
# Compile and train
model.compile(optimizer=SGD(learning_rate=0.01, momentum=0.9), loss='mse')
history = model.train(X_train, y_train, epochs=100, batch_size=32)
# Predict
predictions = model.predict(X_test)
Custom Precision
from lynxlearn import DenseBF16, DenseFloat16, DenseMixedPrecision
# BF16 precision (requires ml-dtypes)
model = Sequential([
DenseBF16(128, activation='relu', input_shape=(10,)),
DenseBF16(1)
])
# Mixed precision training
layer = DenseMixedPrecision(128, storage_dtype='float16', compute_dtype='float32')
With Regularization
from lynxlearn import Dense, L2Regularizer, MaxNorm
layer = Dense(
128,
activation='relu',
kernel_regularizer=L2Regularizer(l2=0.01),
kernel_constraint=MaxNorm(3.0)
)
Performance Benchmarks
Neural Network Training (CPU)
| Model Size | LynxLearn | PyTorch | TensorFlow | Winner |
|---|---|---|---|---|
| ~1K params | 0.05s | 0.12s | 0.35s | LynxLearn 2.4x |
| ~10K params | 0.15s | 0.45s | 1.2s | LynxLearn 3x |
| ~100K params | 0.8s | 2.1s | 5.5s | LynxLearn 2.6x |
Fair comparison: same architecture, same data, same training parameters, CPU-only.
Why We're Faster on CPU
PyTorch/TensorFlow overhead per layer:
โโโ Autograd tape recording
โโโ Dynamic graph construction
โโโ CUDA availability checks
โโโ Distributed training hooks
โโโ Mixed precision handling
โโโ Safety checks and assertions
LynxLearn overhead per layer:
โโโ x @ W + b (single BLAS call)
What We DON'T Beat
| Task | Winner | Why |
|---|---|---|
| Linear Regression | scikit-learn | 20+ years of optimization |
| Large models on GPU | PyTorch/TensorFlow | GPU acceleration |
| Distributed training | PyTorch/TensorFlow | Multi-GPU/TPU support |
Documentation
- API Reference - Complete API documentation
- Examples - Code examples and tutorials
- Mathematics - Mathematical foundations
Project Structure
LynxLearn/
โโโ lynxlearn/
โ โโโ linear_model/ # Linear regression models
โ โโโ neural_network/ # Neural network components
โ โ โโโ layers/ # Dense, regularizers, constraints
โ โ โโโ optimizers/ # SGD with momentum
โ โ โโโ losses/ # MSE, MAE, Huber
โ โ โโโ initializers/ # He, Xavier, LeCun
โ โโโ model_selection/ # Train/test split
โ โโโ metrics/ # Evaluation metrics
โ โโโ visualizations/ # Plotting utilities
โโโ tests/ # Test suite
โโโ examples/ # Example scripts
โโโ benchmark/ # Fair benchmarks
โโโ docs/ # Documentation
Philosophy
Transparency
We're honest about performance. We don't cherry-pick unfair comparisons. Our benchmarks compare apples-to-apples: same algorithm, same data, same hardware.
Educational Value
Every component is built from scratch with NumPy. No black boxes. Perfect for students, researchers, and anyone who wants to understand ML fundamentals.
Beginner-Friendly API
# Simple, intuitive method names
model.train(X, y) # Not fit()
model.predict(X) # Clear and obvious
model.evaluate(X, y) # Returns metrics dictionary
model.summary() # Print model architecture
Running Tests
# Run all tests
pytest tests/
# Run with coverage
pytest tests/ -v --cov=lynxlearn
# Run neural network tests only
pytest tests/test_neural_network/
Running Benchmarks
# Quick benchmark
python benchmark/benchmark_neural_network.py --quick
# Full benchmark
python benchmark/benchmark_neural_network.py
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lynxlearn-0.3.0.tar.gz.
File metadata
- Download URL: lynxlearn-0.3.0.tar.gz
- Upload date:
- Size: 82.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aa580428adf989af52c36a94579060f8bb1215e1d1d71d467454a5e1492e657
|
|
| MD5 |
2ceab73605a6db0da660d9b102379251
|
|
| BLAKE2b-256 |
2ad855c99902adbc8520ab24d5406f0fae12536301a95e5ed87f555c6bfd67bb
|
File details
Details for the file lynxlearn-0.3.0-py3-none-any.whl.
File metadata
- Download URL: lynxlearn-0.3.0-py3-none-any.whl
- Upload date:
- Size: 103.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8036826c6c458ac8f2e918fb97c25e77d706c7e3d6c809ba0d96789568c2683f
|
|
| MD5 |
894d8bd7804faede610902672eac189c
|
|
| BLAKE2b-256 |
d5b3d4aa6bf06b628b543a1daf48a78aa1b6c95e83d7149621c802016229b17a
|