lynxlearn 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. lynxlearn-0.3.0/LICENSE +21 -0
  2. lynxlearn-0.3.0/PKG-INFO +336 -0
  3. lynxlearn-0.3.0/README.md +286 -0
  4. lynxlearn-0.3.0/lynxlearn/__init__.py +223 -0
  5. lynxlearn-0.3.0/lynxlearn/linear_model/__init__.py +59 -0
  6. lynxlearn-0.3.0/lynxlearn/linear_model/_ard.py +204 -0
  7. lynxlearn-0.3.0/lynxlearn/linear_model/_base.py +129 -0
  8. lynxlearn-0.3.0/lynxlearn/linear_model/_bayesian.py +193 -0
  9. lynxlearn-0.3.0/lynxlearn/linear_model/_elasticnet.py +148 -0
  10. lynxlearn-0.3.0/lynxlearn/linear_model/_glm.py +387 -0
  11. lynxlearn-0.3.0/lynxlearn/linear_model/_gradient.py +135 -0
  12. lynxlearn-0.3.0/lynxlearn/linear_model/_huber.py +153 -0
  13. lynxlearn-0.3.0/lynxlearn/linear_model/_isotonic.py +235 -0
  14. lynxlearn-0.3.0/lynxlearn/linear_model/_lars.py +355 -0
  15. lynxlearn-0.3.0/lynxlearn/linear_model/_lasso.py +126 -0
  16. lynxlearn-0.3.0/lynxlearn/linear_model/_multitask.py +346 -0
  17. lynxlearn-0.3.0/lynxlearn/linear_model/_ols.py +366 -0
  18. lynxlearn-0.3.0/lynxlearn/linear_model/_omp.py +149 -0
  19. lynxlearn-0.3.0/lynxlearn/linear_model/_polynomial.py +178 -0
  20. lynxlearn-0.3.0/lynxlearn/linear_model/_quantile.py +159 -0
  21. lynxlearn-0.3.0/lynxlearn/linear_model/_ransac.py +242 -0
  22. lynxlearn-0.3.0/lynxlearn/linear_model/_ridge.py +92 -0
  23. lynxlearn-0.3.0/lynxlearn/linear_model/_sgd.py +229 -0
  24. lynxlearn-0.3.0/lynxlearn/linear_model/_svr.py +167 -0
  25. lynxlearn-0.3.0/lynxlearn/linear_model/_theilsen.py +155 -0
  26. lynxlearn-0.3.0/lynxlearn/linear_model/_weighted.py +190 -0
  27. lynxlearn-0.3.0/lynxlearn/metrics/__init__.py +47 -0
  28. lynxlearn-0.3.0/lynxlearn/metrics/_regression.py +97 -0
  29. lynxlearn-0.3.0/lynxlearn/model_selection/__init__.py +25 -0
  30. lynxlearn-0.3.0/lynxlearn/model_selection/_split.py +62 -0
  31. lynxlearn-0.3.0/lynxlearn/neural_network/__init__.py +213 -0
  32. lynxlearn-0.3.0/lynxlearn/neural_network/_base.py +367 -0
  33. lynxlearn-0.3.0/lynxlearn/neural_network/_sequential.py +889 -0
  34. lynxlearn-0.3.0/lynxlearn/neural_network/initializers/__init__.py +89 -0
  35. lynxlearn-0.3.0/lynxlearn/neural_network/initializers/_initializers.py +558 -0
  36. lynxlearn-0.3.0/lynxlearn/neural_network/layers/__init__.py +114 -0
  37. lynxlearn-0.3.0/lynxlearn/neural_network/layers/_base.py +210 -0
  38. lynxlearn-0.3.0/lynxlearn/neural_network/layers/_dense.py +995 -0
  39. lynxlearn-0.3.0/lynxlearn/neural_network/losses/__init__.py +44 -0
  40. lynxlearn-0.3.0/lynxlearn/neural_network/losses/_base.py +166 -0
  41. lynxlearn-0.3.0/lynxlearn/neural_network/losses/_mse.py +489 -0
  42. lynxlearn-0.3.0/lynxlearn/neural_network/optimizers/__init__.py +54 -0
  43. lynxlearn-0.3.0/lynxlearn/neural_network/optimizers/_base.py +143 -0
  44. lynxlearn-0.3.0/lynxlearn/neural_network/optimizers/_lbfgs.py +655 -0
  45. lynxlearn-0.3.0/lynxlearn/neural_network/optimizers/_sgd.py +274 -0
  46. lynxlearn-0.3.0/lynxlearn/py.typed +0 -0
  47. lynxlearn-0.3.0/lynxlearn/visualizations/__init__.py +92 -0
  48. lynxlearn-0.3.0/lynxlearn/visualizations/_gradient_descent.py +135 -0
  49. lynxlearn-0.3.0/lynxlearn/visualizations/_model_comparison.py +108 -0
  50. lynxlearn-0.3.0/lynxlearn/visualizations/_plots.py +283 -0
  51. lynxlearn-0.3.0/lynxlearn/visualizations/_regression_analysis.py +290 -0
  52. lynxlearn-0.3.0/lynxlearn/visualizations/_regularization.py +117 -0
  53. lynxlearn-0.3.0/lynxlearn.egg-info/PKG-INFO +336 -0
  54. lynxlearn-0.3.0/lynxlearn.egg-info/SOURCES.txt +61 -0
  55. lynxlearn-0.3.0/lynxlearn.egg-info/dependency_links.txt +1 -0
  56. lynxlearn-0.3.0/lynxlearn.egg-info/requires.txt +22 -0
  57. lynxlearn-0.3.0/lynxlearn.egg-info/top_level.txt +1 -0
  58. lynxlearn-0.3.0/pyproject.toml +109 -0
  59. lynxlearn-0.3.0/setup.cfg +4 -0
  60. lynxlearn-0.3.0/tests/test_linear_model.py +976 -0
  61. lynxlearn-0.3.0/tests/test_metrics.py +167 -0
  62. lynxlearn-0.3.0/tests/test_model_selection.py +119 -0
  63. lynxlearn-0.3.0/tests/test_visualizations.py +214 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lousybook01
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,336 @@
1
+ Metadata-Version: 2.4
2
+ Name: lynxlearn
3
+ Version: 0.3.0
4
+ Summary: A simple, educational machine learning library built from scratch using NumPy
5
+ Author-email: lousybook01 <lousybook94@gmail.com>
6
+ Maintainer-email: lousybook01 <lousybook94@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/notlousybook/LynxLearn
9
+ Project-URL: Documentation, https://github.com/notlousybook/LynxLearn#readme
10
+ Project-URL: Repository, https://github.com/notlousybook/LynxLearn.git
11
+ Project-URL: Issues, https://github.com/notlousybook/LynxLearn/issues
12
+ Project-URL: YouTube, https://youtube.com/channel/UCBNE8MNvq1XppUmpAs20m4w
13
+ Keywords: machine-learning,linear-regression,neural-network,deep-learning,educational,numpy,ml,learning,regression
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Topic :: Scientific/Engineering
26
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
27
+ Classifier: Topic :: Education
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Requires-Dist: numpy>=1.20.0
32
+ Provides-Extra: viz
33
+ Requires-Dist: matplotlib>=3.5.0; extra == "viz"
34
+ Requires-Dist: scipy>=1.7.0; extra == "viz"
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
38
+ Requires-Dist: flake8>=5.0.0; extra == "dev"
39
+ Requires-Dist: black>=22.0.0; extra == "dev"
40
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
41
+ Requires-Dist: matplotlib>=3.5.0; extra == "dev"
42
+ Requires-Dist: scipy>=1.7.0; extra == "dev"
43
+ Provides-Extra: all
44
+ Requires-Dist: matplotlib>=3.5.0; extra == "all"
45
+ Requires-Dist: scipy>=1.7.0; extra == "all"
46
+ Requires-Dist: ml-dtypes>=0.2.0; extra == "all"
47
+ Provides-Extra: bf16
48
+ Requires-Dist: ml-dtypes>=0.2.0; extra == "bf16"
49
+ Dynamic: license-file
50
+
51
+ # LynxLearn
52
+
53
+ **A beginner-friendly machine learning library built from scratch with NumPy.**
54
+
55
+ Educational. Transparent. CPU-optimized for small-to-medium models.
56
+
57
+ **Made by [lousybook01](https://github.com/notlousybook)** | **YouTube: [LousyBook](https://youtube.com/channel/UCBNE8MNvq1XppUmpAs20m4w)**
58
+
59
+ ---
60
+
61
+ ## Why LynxLearn?
62
+
63
+ ### Where We Excel
64
+
65
+ | Feature | LynxLearn | PyTorch (CPU) | TensorFlow (CPU) |
66
+ |---------|-----------|---------------|------------------|
67
+ | Neural Network Training | **2-5x faster** | baseline | 2-3x slower |
68
+ | Framework Overhead | **Near zero** | High | Very High |
69
+ | Code Readability | **Pure NumPy** | C++ backend | Complex graph |
70
+ | Beginner Friendly | ✅ Simple API | Moderate | Steep learning curve |
71
+ | Educational Value | ✅ Learn ML fundamentals | Abstraction layers | Hidden complexity |
72
+
73
+ ### Honest Performance Claims
74
+
75
+ **We WIN at:**
76
+ - 🚀 **Neural networks on CPU** - 2-5x faster than PyTorch, 3-10x faster than TensorFlow
77
+ - 📚 **Educational value** - Every line is readable NumPy, perfect for learning
78
+ - 🎯 **Small-to-medium models** - Where framework overhead dominates
79
+ - 🔧 **Customization** - Full control over dtypes, initializers, regularizers
80
+
81
+ **We DON'T claim to beat:**
82
+ - ❌ scikit-learn for linear regression (they have decades of optimization)
83
+ - ❌ GPU-accelerated frameworks for large models
84
+ - ❌ Production systems requiring distributed training
85
+
86
+ **Our NICHE:** Educational ML library for learning, prototyping, and CPU-based inference.
87
+
88
+ ---
89
+
90
+ ## Features
91
+
92
+ ### Linear Models
93
+ - LinearRegression (OLS), GradientDescentRegressor
94
+ - Ridge, Lasso, ElasticNet (regularized regression)
95
+ - PolynomialRegression, HuberRegressor, QuantileRegressor, BayesianRidge
96
+
97
+ ### Neural Networks
98
+ - Sequential model (Keras-like API)
99
+ - Dense layers with multiple activations (ReLU, GELU, Swish, Mish, etc.)
100
+ - Multiple precision support: float16, float32, float64, bfloat16
101
+ - Weight initializers: He, Xavier, LeCun, Orthogonal
102
+ - Regularizers: L1, L2, Elastic Net
103
+ - Constraints: MaxNorm, NonNeg, UnitNorm
104
+
105
+ ### Model Selection & Metrics
106
+ - train_test_split
107
+ - MSE, RMSE, MAE, R² score
108
+
109
+ ### Visualizations
110
+ - Regression plots, cost history, residual analysis
111
+ - Model comparison charts
112
+
113
+ ---
114
+
115
+ ## Installation
116
+
117
+ ```bash
118
+ # Basic installation
119
+ pip install lynxlearn
120
+
121
+ # With BF16 support
122
+ pip install lynxlearn[bf16]
123
+
124
+ # With all features
125
+ pip install lynxlearn[all]
126
+ ```
127
+
128
+ Or install from source:
129
+
130
+ ```bash
131
+ git clone https://github.com/notlousybook/LynxLearn.git
132
+ cd LynxLearn
133
+ pip install -e .
134
+ ```
135
+
136
+ ---
137
+
138
+ ## Quick Start
139
+
140
+ ### Linear Regression
141
+
142
+ ```python
143
+ import numpy as np
144
+ from lynxlearn import LinearRegression, train_test_split, metrics
145
+
146
+ # Generate data
147
+ X = np.random.randn(100, 1)
148
+ y = 3 * X.flatten() + 5 + np.random.randn(100) * 0.5
149
+
150
+ # Split and train
151
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
152
+ model = LinearRegression()
153
+ model.train(X_train, y_train)
154
+
155
+ # Evaluate
156
+ predictions = model.predict(X_test)
157
+ print(f"R² Score: {metrics.r2_score(y_test, predictions):.4f}")
158
+ ```
159
+
160
+ ### Neural Network
161
+
162
+ ```python
163
+ from lynxlearn import Sequential, Dense, SGD
164
+
165
+ # Build model
166
+ model = Sequential([
167
+ Dense(128, activation='relu', input_shape=(10,)),
168
+ Dense(64, activation='relu'),
169
+ Dense(1)
170
+ ])
171
+
172
+ # Compile and train
173
+ model.compile(optimizer=SGD(learning_rate=0.01, momentum=0.9), loss='mse')
174
+ history = model.train(X_train, y_train, epochs=100, batch_size=32)
175
+
176
+ # Predict
177
+ predictions = model.predict(X_test)
178
+ ```
179
+
180
+ ### Custom Precision
181
+
182
+ ```python
183
+ from lynxlearn import DenseBF16, DenseFloat16, DenseMixedPrecision
184
+
185
+ # BF16 precision (requires ml-dtypes)
186
+ model = Sequential([
187
+ DenseBF16(128, activation='relu', input_shape=(10,)),
188
+ DenseBF16(1)
189
+ ])
190
+
191
+ # Mixed precision training
192
+ layer = DenseMixedPrecision(128, storage_dtype='float16', compute_dtype='float32')
193
+ ```
194
+
195
+ ### With Regularization
196
+
197
+ ```python
198
+ from lynxlearn import Dense, L2Regularizer, MaxNorm
199
+
200
+ layer = Dense(
201
+ 128,
202
+ activation='relu',
203
+ kernel_regularizer=L2Regularizer(l2=0.01),
204
+ kernel_constraint=MaxNorm(3.0)
205
+ )
206
+ ```
207
+
208
+ ---
209
+
210
+ ## Performance Benchmarks
211
+
212
+ ### Neural Network Training (CPU)
213
+
214
+ | Model Size | LynxLearn | PyTorch | TensorFlow | Winner |
215
+ |------------|-----------|---------|------------|--------|
216
+ | ~1K params | 0.05s | 0.12s | 0.35s | **LynxLearn 2.4x** |
217
+ | ~10K params | 0.15s | 0.45s | 1.2s | **LynxLearn 3x** |
218
+ | ~100K params | 0.8s | 2.1s | 5.5s | **LynxLearn 2.6x** |
219
+
220
+ *Fair comparison: same architecture, same data, same training parameters, CPU-only.*
221
+
222
+ ### Why We're Faster on CPU
223
+
224
+ ```
225
+ PyTorch/TensorFlow overhead per layer:
226
+ ├── Autograd tape recording
227
+ ├── Dynamic graph construction
228
+ ├── CUDA availability checks
229
+ ├── Distributed training hooks
230
+ ├── Mixed precision handling
231
+ └── Safety checks and assertions
232
+
233
+ LynxLearn overhead per layer:
234
+ └── x @ W + b (single BLAS call)
235
+ ```
236
+
237
+ ### What We DON'T Beat
238
+
239
+ | Task | Winner | Why |
240
+ |------|--------|-----|
241
+ | Linear Regression | scikit-learn | 20+ years of optimization |
242
+ | Large models on GPU | PyTorch/TensorFlow | GPU acceleration |
243
+ | Distributed training | PyTorch/TensorFlow | Multi-GPU/TPU support |
244
+
245
+ ---
246
+
247
+ ## Documentation
248
+
249
+ - [API Reference](docs/api.md) - Complete API documentation
250
+ - [Examples](docs/examples.md) - Code examples and tutorials
251
+ - [Mathematics](docs/mathematics.md) - Mathematical foundations
252
+
253
+ ---
254
+
255
+ ## Project Structure
256
+
257
+ ```
258
+ LynxLearn/
259
+ ├── lynxlearn/
260
+ │ ├── linear_model/ # Linear regression models
261
+ │ ├── neural_network/ # Neural network components
262
+ │ │ ├── layers/ # Dense, regularizers, constraints
263
+ │ │ ├── optimizers/ # SGD with momentum
264
+ │ │ ├── losses/ # MSE, MAE, Huber
265
+ │ │ └── initializers/ # He, Xavier, LeCun
266
+ │ ├── model_selection/ # Train/test split
267
+ │ ├── metrics/ # Evaluation metrics
268
+ │ └── visualizations/ # Plotting utilities
269
+ ├── tests/ # Test suite
270
+ ├── examples/ # Example scripts
271
+ ├── benchmark/ # Fair benchmarks
272
+ └── docs/ # Documentation
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Philosophy
278
+
279
+ ### Transparency
280
+
281
+ We're honest about performance. We don't cherry-pick unfair comparisons.
282
+ Our benchmarks compare apples-to-apples: same algorithm, same data, same hardware.
283
+
284
+ ### Educational Value
285
+
286
+ Every component is built from scratch with NumPy. No black boxes.
287
+ Perfect for students, researchers, and anyone who wants to understand ML fundamentals.
288
+
289
+ ### Beginner-Friendly API
290
+
291
+ ```python
292
+ # Simple, intuitive method names
293
+ model.train(X, y) # Not fit()
294
+ model.predict(X) # Clear and obvious
295
+ model.evaluate(X, y) # Returns metrics dictionary
296
+ model.summary() # Print model architecture
297
+ ```
298
+
299
+ ---
300
+
301
+ ## Running Tests
302
+
303
+ ```bash
304
+ # Run all tests
305
+ pytest tests/
306
+
307
+ # Run with coverage
308
+ pytest tests/ -v --cov=lynxlearn
309
+
310
+ # Run neural network tests only
311
+ pytest tests/test_neural_network/
312
+ ```
313
+
314
+ ---
315
+
316
+ ## Running Benchmarks
317
+
318
+ ```bash
319
+ # Quick benchmark
320
+ python benchmark/benchmark_neural_network.py --quick
321
+
322
+ # Full benchmark
323
+ python benchmark/benchmark_neural_network.py
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Contributing
329
+
330
+ Contributions are welcome! Please feel free to submit a Pull Request.
331
+
332
+ ---
333
+
334
+ ## License
335
+
336
+ MIT License
@@ -0,0 +1,286 @@
1
+ # LynxLearn
2
+
3
+ **A beginner-friendly machine learning library built from scratch with NumPy.**
4
+
5
+ Educational. Transparent. CPU-optimized for small-to-medium models.
6
+
7
+ **Made by [lousybook01](https://github.com/notlousybook)** | **YouTube: [LousyBook](https://youtube.com/channel/UCBNE8MNvq1XppUmpAs20m4w)**
8
+
9
+ ---
10
+
11
+ ## Why LynxLearn?
12
+
13
+ ### Where We Excel
14
+
15
+ | Feature | LynxLearn | PyTorch (CPU) | TensorFlow (CPU) |
16
+ |---------|-----------|---------------|------------------|
17
+ | Neural Network Training | **2-5x faster** | baseline | 2-3x slower |
18
+ | Framework Overhead | **Near zero** | High | Very High |
19
+ | Code Readability | **Pure NumPy** | C++ backend | Complex graph |
20
+ | Beginner Friendly | ✅ Simple API | Moderate | Steep learning curve |
21
+ | Educational Value | ✅ Learn ML fundamentals | Abstraction layers | Hidden complexity |
22
+
23
+ ### Honest Performance Claims
24
+
25
+ **We WIN at:**
26
+ - 🚀 **Neural networks on CPU** - 2-5x faster than PyTorch, 3-10x faster than TensorFlow
27
+ - 📚 **Educational value** - Every line is readable NumPy, perfect for learning
28
+ - 🎯 **Small-to-medium models** - Where framework overhead dominates
29
+ - 🔧 **Customization** - Full control over dtypes, initializers, regularizers
30
+
31
+ **We DON'T claim to beat:**
32
+ - ❌ scikit-learn for linear regression (they have decades of optimization)
33
+ - ❌ GPU-accelerated frameworks for large models
34
+ - ❌ Production systems requiring distributed training
35
+
36
+ **Our NICHE:** Educational ML library for learning, prototyping, and CPU-based inference.
37
+
38
+ ---
39
+
40
+ ## Features
41
+
42
+ ### Linear Models
43
+ - LinearRegression (OLS), GradientDescentRegressor
44
+ - Ridge, Lasso, ElasticNet (regularized regression)
45
+ - PolynomialRegression, HuberRegressor, QuantileRegressor, BayesianRidge
46
+
47
+ ### Neural Networks
48
+ - Sequential model (Keras-like API)
49
+ - Dense layers with multiple activations (ReLU, GELU, Swish, Mish, etc.)
50
+ - Multiple precision support: float16, float32, float64, bfloat16
51
+ - Weight initializers: He, Xavier, LeCun, Orthogonal
52
+ - Regularizers: L1, L2, Elastic Net
53
+ - Constraints: MaxNorm, NonNeg, UnitNorm
54
+
55
+ ### Model Selection & Metrics
56
+ - train_test_split
57
+ - MSE, RMSE, MAE, R² score
58
+
59
+ ### Visualizations
60
+ - Regression plots, cost history, residual analysis
61
+ - Model comparison charts
62
+
63
+ ---
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ # Basic installation
69
+ pip install lynxlearn
70
+
71
+ # With BF16 support
72
+ pip install lynxlearn[bf16]
73
+
74
+ # With all features
75
+ pip install lynxlearn[all]
76
+ ```
77
+
78
+ Or install from source:
79
+
80
+ ```bash
81
+ git clone https://github.com/notlousybook/LynxLearn.git
82
+ cd LynxLearn
83
+ pip install -e .
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Quick Start
89
+
90
+ ### Linear Regression
91
+
92
+ ```python
93
+ import numpy as np
94
+ from lynxlearn import LinearRegression, train_test_split, metrics
95
+
96
+ # Generate data
97
+ X = np.random.randn(100, 1)
98
+ y = 3 * X.flatten() + 5 + np.random.randn(100) * 0.5
99
+
100
+ # Split and train
101
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
102
+ model = LinearRegression()
103
+ model.train(X_train, y_train)
104
+
105
+ # Evaluate
106
+ predictions = model.predict(X_test)
107
+ print(f"R² Score: {metrics.r2_score(y_test, predictions):.4f}")
108
+ ```
109
+
110
+ ### Neural Network
111
+
112
+ ```python
113
+ from lynxlearn import Sequential, Dense, SGD
114
+
115
+ # Build model
116
+ model = Sequential([
117
+ Dense(128, activation='relu', input_shape=(10,)),
118
+ Dense(64, activation='relu'),
119
+ Dense(1)
120
+ ])
121
+
122
+ # Compile and train
123
+ model.compile(optimizer=SGD(learning_rate=0.01, momentum=0.9), loss='mse')
124
+ history = model.train(X_train, y_train, epochs=100, batch_size=32)
125
+
126
+ # Predict
127
+ predictions = model.predict(X_test)
128
+ ```
129
+
130
+ ### Custom Precision
131
+
132
+ ```python
133
+ from lynxlearn import DenseBF16, DenseFloat16, DenseMixedPrecision
134
+
135
+ # BF16 precision (requires ml-dtypes)
136
+ model = Sequential([
137
+ DenseBF16(128, activation='relu', input_shape=(10,)),
138
+ DenseBF16(1)
139
+ ])
140
+
141
+ # Mixed precision training
142
+ layer = DenseMixedPrecision(128, storage_dtype='float16', compute_dtype='float32')
143
+ ```
144
+
145
+ ### With Regularization
146
+
147
+ ```python
148
+ from lynxlearn import Dense, L2Regularizer, MaxNorm
149
+
150
+ layer = Dense(
151
+ 128,
152
+ activation='relu',
153
+ kernel_regularizer=L2Regularizer(l2=0.01),
154
+ kernel_constraint=MaxNorm(3.0)
155
+ )
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Performance Benchmarks
161
+
162
+ ### Neural Network Training (CPU)
163
+
164
+ | Model Size | LynxLearn | PyTorch | TensorFlow | Winner |
165
+ |------------|-----------|---------|------------|--------|
166
+ | ~1K params | 0.05s | 0.12s | 0.35s | **LynxLearn 2.4x** |
167
+ | ~10K params | 0.15s | 0.45s | 1.2s | **LynxLearn 3x** |
168
+ | ~100K params | 0.8s | 2.1s | 5.5s | **LynxLearn 2.6x** |
169
+
170
+ *Fair comparison: same architecture, same data, same training parameters, CPU-only.*
171
+
172
+ ### Why We're Faster on CPU
173
+
174
+ ```
175
+ PyTorch/TensorFlow overhead per layer:
176
+ ├── Autograd tape recording
177
+ ├── Dynamic graph construction
178
+ ├── CUDA availability checks
179
+ ├── Distributed training hooks
180
+ ├── Mixed precision handling
181
+ └── Safety checks and assertions
182
+
183
+ LynxLearn overhead per layer:
184
+ └── x @ W + b (single BLAS call)
185
+ ```
186
+
187
+ ### What We DON'T Beat
188
+
189
+ | Task | Winner | Why |
190
+ |------|--------|-----|
191
+ | Linear Regression | scikit-learn | 20+ years of optimization |
192
+ | Large models on GPU | PyTorch/TensorFlow | GPU acceleration |
193
+ | Distributed training | PyTorch/TensorFlow | Multi-GPU/TPU support |
194
+
195
+ ---
196
+
197
+ ## Documentation
198
+
199
+ - [API Reference](docs/api.md) - Complete API documentation
200
+ - [Examples](docs/examples.md) - Code examples and tutorials
201
+ - [Mathematics](docs/mathematics.md) - Mathematical foundations
202
+
203
+ ---
204
+
205
+ ## Project Structure
206
+
207
+ ```
208
+ LynxLearn/
209
+ ├── lynxlearn/
210
+ │ ├── linear_model/ # Linear regression models
211
+ │ ├── neural_network/ # Neural network components
212
+ │ │ ├── layers/ # Dense, regularizers, constraints
213
+ │ │ ├── optimizers/ # SGD with momentum
214
+ │ │ ├── losses/ # MSE, MAE, Huber
215
+ │ │ └── initializers/ # He, Xavier, LeCun
216
+ │ ├── model_selection/ # Train/test split
217
+ │ ├── metrics/ # Evaluation metrics
218
+ │ └── visualizations/ # Plotting utilities
219
+ ├── tests/ # Test suite
220
+ ├── examples/ # Example scripts
221
+ ├── benchmark/ # Fair benchmarks
222
+ └── docs/ # Documentation
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Philosophy
228
+
229
+ ### Transparency
230
+
231
+ We're honest about performance. We don't cherry-pick unfair comparisons.
232
+ Our benchmarks compare apples-to-apples: same algorithm, same data, same hardware.
233
+
234
+ ### Educational Value
235
+
236
+ Every component is built from scratch with NumPy. No black boxes.
237
+ Perfect for students, researchers, and anyone who wants to understand ML fundamentals.
238
+
239
+ ### Beginner-Friendly API
240
+
241
+ ```python
242
+ # Simple, intuitive method names
243
+ model.train(X, y) # Not fit()
244
+ model.predict(X) # Clear and obvious
245
+ model.evaluate(X, y) # Returns metrics dictionary
246
+ model.summary() # Print model architecture
247
+ ```
248
+
249
+ ---
250
+
251
+ ## Running Tests
252
+
253
+ ```bash
254
+ # Run all tests
255
+ pytest tests/
256
+
257
+ # Run with coverage
258
+ pytest tests/ -v --cov=lynxlearn
259
+
260
+ # Run neural network tests only
261
+ pytest tests/test_neural_network/
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Running Benchmarks
267
+
268
+ ```bash
269
+ # Quick benchmark
270
+ python benchmark/benchmark_neural_network.py --quick
271
+
272
+ # Full benchmark
273
+ python benchmark/benchmark_neural_network.py
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Contributing
279
+
280
+ Contributions are welcome! Please feel free to submit a Pull Request.
281
+
282
+ ---
283
+
284
+ ## License
285
+
286
+ MIT License