Skip to content
puchkovsPublic

About

An independent machine learning library built from scratch with NumPy, featuring classical ML algorithms, numerical optimization, and reproducible evaluation.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ML Core

A dense CPU machine learning library with independently written algorithms, explicit numerical contracts and reproducible evaluation. NumPy is the only direct runtime dependency. MIT licensed. Version 0.1.0.

Algorithms

Family Implementation
LinearRegression Rank-aware OLS with explicit singular cutoff and minimum-norm slopes
Ridge Centered SVD shrinkage, mean-loss L2 penalty, unpenalized intercept
LogisticRegression Binary and multinomial stable losses, full-batch Armijo descent
KMeans Vanilla K-Means++, independent restarts, Lloyd updates, bounded distance buffers
PCA Centered thin SVD, held-out transforms and reconstruction

Supporting tools: StandardScaler, mean/median SimpleImputer, transactional Pipeline, seeded/stratified splits, KFold/StratifiedKFold, fresh-clone CV, bounded grid search, regression/classification metrics and adjusted Rand index.

Install

Python 3.12/Linux is the verified environment. Python >=3.12 and NumPy >=2.0 are required by package metadata; broader compatibility has not been independently verified. Download the wheel and checksums from the v0.1.0 GitHub Release. This release is not published to PyPI.

uv sync --locked
uv build
# Install a built wheel in another environment:
pip install dist/puchkovs_ml_core-0.1.0-py3-none-any.whl

The distribution name is puchkovs-ml-core; the Python import is ml_core. The registry name was checked during release preparation; availability is not a reservation. See docs/verification/distribution-name.json.

Quick start

import numpy as np
from ml_core import Pipeline, Ridge, SimpleImputer, StandardScaler
from ml_core.evaluation import KFold, grid_search, train_test_split
from ml_core.metrics import root_mean_squared_error

rng = np.random.default_rng(42)
X = rng.normal(size=(120, 4))
y = X @ np.array([2.0, -1.0, 0.0, 0.5]) + rng.normal(scale=0.1, size=120)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
model = Pipeline(
    [
        ("impute", SimpleImputer(strategy="median")),
        ("scale", StandardScaler()),
        ("regression", Ridge()),
    ]
)
result = grid_search(
    model,
    X_train,
    y_train,
    {"regression__alpha": [0.0, 0.01, 0.1]},
    cv=KFold(5, shuffle=True, random_state=42),
    scoring=lambda model, X, y: root_mean_squared_error(y, model.predict(X)),
    greater_is_better=False,
)
print(result["best_params"])
print(root_mean_squared_error(y_test, result["best_estimator"].predict(X_test)))

Preprocessing fits only on each training fold. Keep test data outside selection. fit returns self; failed refits preserve valid state. Use get_params, set_params and clone for configuration. Inference before successful fit raises NotFittedError. Iterative models expose convergence and warn on exhaustion.

from ml_core import LogisticRegression, KMeans, PCA

classifier = LogisticRegression().fit(X_train, (y_train > 0).astype(int))
probabilities = classifier.predict_proba(X_test)  # columns follow classes_
clusters = KMeans(n_clusters=3, random_state=42).fit_predict(X_train)
projection = PCA(n_components=2).fit(X_train).transform(X_test)

See public API and runnable examples.

Executed experiments

Seed 42; 80/20 holdouts; five training folds for model selection. Checksums, indices, configurations, warnings and versions are saved with measurements.

Dataset/task Held-out result
Auto MPG, OLS RMSE 3.291430, R² 0.781909; mean baseline RMSE 7.111973
Auto MPG, selected Ridge alpha .001, RMSE 3.291918, R² 0.781845
Wisconsin, binary logistic ROC-AUC .996693, F1 .976190, log loss .087911
Wine, multinomial logistic Macro F1 1.000000, log loss .056784; 36 held-out rows
Wine, 2-component PCA Held-out standardized reconstruction RMSE .680198; training variance fraction .542071

Penguins descriptive clustering (all rows, k=3, seed 11): inertia 383.324455, silhouette .444287, post-fit species ARI .780276. Species is excluded from fitting. Synthetic known-cluster ARI is 1.0. All real iterative fits converged in this run. Wisconsin is a numerical teaching benchmark, with no medical or diagnostic claim. A perfect small Wine holdout score is not a generalization guarantee.

Experiment report · Raw results

Verified release checks

114 tests pass with 99.27% core statement coverage; validation and metrics each have 100% coverage. All 126 benchmark cases succeeded with no timeouts, warnings, memory-budget excesses or unconverged ML Core fits. Maximum observed ML Core process RSS was 96.54 MiB in the latest complete run. Measurements describe the recorded environment; timings and RSS vary by platform and machine load.

Reproduce

uv sync --locked
uv run ruff check .
uv run ruff format --check .
OPENBLAS_NUM_THREADS=1 LOKY_MAX_CPU_COUNT=1 \
  uv run pytest --cov=ml_core --cov-report=term-missing --cov-fail-under=85
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 \
  uv run python experiments/run.py --download
uv run python benchmarks/run.py --pilot
uv run python benchmarks/run.py
uv run python scripts/report.py
uv build

Data are downloaded on demand, checked against fixed SHA-256 and never included in the distribution. Preserve dataset attribution.

The benchmark covers n=500/2500/10000 and p=8/32/128, two/four classes and three/ten clusters. Two warmups, seven repetitions, medians/IQR, single-thread workers, 60-second timeouts and isolated process RSS are recorded. Compare time together with objective quality and convergence, especially when initialization differs. See measured benchmarks and protocol.

Architecture and limits

src/ml_core contains cohesive numerical modules, shared validation/contracts, metrics, composition and evaluation. Pipeline/CV depend on estimator methods, not concrete implementations. tests separates unit, integration and reference checks. Experiments/benchmarks are development programs outside the runtime wheel.

Dense float64 CPU arrays only. No sparse/categorical encoding, multi-output regression, sample weights, persistence, GPU or deployment. Extreme finite values can overflow intermediate arithmetic. Logistic descent depends on scaling and can reach a finite-precision plateau; check converged_. KMeans is a local optimizer; PCA bases inside tied subspaces are nonunique. Fixed seeds do not promise bitwise portability across BLAS/platform changes.

Architecture · Mathematics · Numerical stability · Limitations · Testing · Roadmap · Contributing

Future work may add safe persistence, sparse/categorical processing and additional estimators after separate specifications and quality gates. Current release scope remains the five families above. See changelog and release instructions. Code license: MIT.

About

An independent machine learning library built from scratch with NumPy, featuring classical ML algorithms, numerical optimization, and reproducible evaluation.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages