Overview • Installation • Structure • API • Benchmarking • Tests
Watch the full explanation here!
NumCompute is the core package which is a lightweight machine learning framework built using NumPy and can function on libraries such as scikit-learn.
NumCompute-Stream It extends numcompute with an additionally python library which includes numpy and also matplotlib.
There are numerous usages of this library but some listed below:
- It is a perfect tool for real-time and incremental learning where data arrives in chunks rather than all at once.
- We can learn how ensemble methods like Bagging and Random Forest work from scratch using only NumPy.
- Lastly, the most important usage is streaming pipelines where we can chain transformers and estimators and watch model performance evolve chunk by chunk.
We can install the projec from my repository through github commands in the terminal in visual studio code.
git clone https://github.com/2100031988/numcompute-stream.git
cd numcompute-stream
pip install numpy matplotlibnumcompute-stream/
├── numcompute/
│ ├── __init__.py
│ ├── io.py
│ ├── preprocessing.py
│ ├── sort_search.py
│ ├── rank.py
│ ├── stats.py
│ ├── metrics.py
│ ├── optim.py
│ ├── pipeline.py
│ └── utils.py
│
├── numcompute_stream/
│ ├── __init__.py
│ ├── trees.py
│ ├── ensemble.py
│ ├── streaming.py
│ ├── metrics.py
│ ├── pipeline.py
│ └── visualise.py
│
├── tests/
│ ├── test_numcompute.py
│ └── test_numcompute_stream.py
│
├── demo/
│ ├── quickstart.ipynb
│ └── stream_demo.ipynb
│
├── benchmark/
│ ├── benchmarking.py
│ └── benchmark_streaming.py
│
├── pyproject.toml
├── README.md
└── LICENSE
| Module | Function | Description |
|---|---|---|
stats |
mean(data) |
Arithmetic mean |
stats |
median(data) |
Median value |
stats |
std(data) |
Standard deviation |
preprocessing |
normalize(data) |
Min-max normalisation |
preprocessing |
StandardScaler() |
Zero-mean, unit-variance scaling |
preprocessing |
LabelEncoder() |
Encodes categorical labels |
sort_search |
sort(data) |
Sorts an array |
sort_search |
binary_search(data, target) |
Binary search on sorted array |
metrics |
mse(y_true, y_pred) |
Mean Squared Error |
pipeline |
Pipeline(steps) |
Chains transformers sequentially |
pipeline |
.fit(X) |
Fits the pipeline to data |
pipeline |
.transform(X) |
Applies transformations to data |
| Class | Description |
|---|---|
DecisionTreeClassifier |
Depth-limited tree with Gini/entropy, partial_fit() |
| Class | Description |
|---|---|
BaggingClassifier |
Bootstrap aggregation of decision trees |
RandomForestClassifier |
Bagging + random feature subsampling |
EnsembleClassifier |
Alias for RandomForestClassifier |
| Name | Description |
|---|---|
StreamTrainer |
Manages chunk-wise training, logging, scoring |
chunk_data(X, y, chunk_size) |
Splits arrays into chunks for streaming |
| Class / Function | Description |
|---|---|
StreamingAccuracy |
Cumulative accuracy with .update() / .result() |
StreamingPrecisionRecallF1 |
Macro/binary PRF1 over streaming data |
StreamingConfusionMatrix |
Accumulating confusion matrix |
RollingAccuracy |
Sliding-window accuracy |
accuracy(y_true, y_pred) |
Stateless batch accuracy |
| Function | Description |
|---|---|
plot_metric_over_time(values, title, ylabel) |
Metric vs chunk index |
compare_models(m1, m2, labels) |
Two-model metric comparison |
plot_predictions_vs_ground_truth(y_true, y_pred) |
Correct/wrong scatter |
plot_confusion_matrix(y_true, y_pred) |
Heatmap confusion matrix |
plot_memory_over_time(logs) |
Memory footprint per chunk |
plot_feature_importances(importances) |
Feature importance bar chart |
# Core benchmarks
python benchmark/benchmarking.py
# Streaming benchmarks
python benchmark/benchmark_streaming.pyThe core benchmarks show vectorised NumPy is approximately 80× faster than loop-based operations with identical accuracy:
| Method | Mean | Time (seconds) |
|---|---|---|
| Vectorised | 0.5001100158230776 | 0.001165 |
| Loop-based | 0.5001100158230763 | 0.093470 |
Results across 10 streaming chunks (150 samples, 4 features):
| Model | Accuracy | Avg per chunk | Total time |
|---|---|---|---|
| Decision Tree (depth=3) | 0.8600 | 9.79 ms | 0.098 s |
| Decision Tree (depth=5) | 0.8600 | 9.20 ms | 0.092 s |
| Bagging (n=5, depth=3) | 0.8267 | 34.16 ms | 0.342 s |
| Random Forest (n=5, depth=3) | 0.8000 | 18.85 ms | 0.188 s |
| Random Forest (n=10, depth=5) | 0.8133 | 51.97 ms | 0.520 s |
Plots generated automatically: tree_accuracy.png, model_comparison.png, predictions_vs_truth.png, streaming_metrics.png,
confusion_matrix.png, feature_importances.png, benchmark.png
pytest tests/ -vWith coverage:
pytest tests/ --cov=numcompute_stream -vSabyasachi Kumar
This project is licensed under the GPL License.
