Skip to main content

Complete ML library from scratch: preprocessing, regression, KNN, PCA, Neural Network, Pipeline

Project description

ml_package 🧠

A complete machine learning library built from scratch using only NumPy. API follows scikit-learn conventions — fit(), transform(), predict().

Install

pip install veda_ml_package

Package Structure

ml_package/
├── preprocessing/     StandardScaler, MinMaxScaler, Imputers, Outlier, Encoder
├── linear_models/     LinearRegression (OLS), Ridge, Lasso, ForwardSelection, BackwardElimination
├── decomposition/     PCA
├── neighbors/         KNNRegressor, KNNClassifier (Manhattan distance)
├── neural_network/    NeuralNetwork (backpropagation from scratch)
├── metrics/           r2, rmse, mae, mape | accuracy, precision, recall, f1
├── model_selection/   train_test_split, KFoldCV
├── pipeline/          Pipeline (chain steps like sklearn)
└── visualization/     PCA plots, scree chart, biplot

Quick Start

from ml_package.preprocessing   import StandardScaler, MedianImputer
from ml_package.linear_models   import LinearRegression
from ml_package.model_selection import train_test_split
from ml_package.pipeline        import Pipeline
from ml_package                 import metrics

# Full pipeline
pipe = Pipeline([
    ("imputer", MedianImputer()),
    ("scaler",  StandardScaler()),
    ("model",   LinearRegression()),
])
pipe.fit(X_train, y_train)
preds = pipe.predict(X_test)
metrics.r2(y_test, preds)

All Models

LinearRegression — OLS Summary

from ml_package.linear_models import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
model.ols_summary(feature_names=["Area", "BHK", "Price/sqft"])
model.predict(X_test)

Ridge & Lasso

from ml_package.linear_models import Ridge, Lasso
Ridge(alpha=1.0).fit(X, y).predict(X_test)
Lasso(alpha=0.01).fit(X, y).predict(X_test)

Forward / Backward Feature Selection

from ml_package.linear_models import ForwardSelection, BackwardElimination
fs = ForwardSelection(); fs.fit(X, y); fs.summary()
be = BackwardElimination(threshold_p=0.05); be.fit(X, y); be.summary()

Check OLS Assumptions

from ml_package.linear_models import check_assumptions
check_assumptions(X, y, model.predict(X), feature_names=["A","B","C"])

KNN

from ml_package.neighbors import KNNRegressor, KNNClassifier
KNNRegressor(k=5, distance="manhattan").fit(X, y).predict(X_test)
KNNClassifier(k=5, weights="distance").fit(X, y).predict(X_test)

Neural Network

from ml_package.neural_network import NeuralNetwork
nn = NeuralNetwork(hidden_layers=(16, 8), learning_rate=0.01, epochs=2000)
nn.fit(X_train, y_train)
nn.predict(X_test)
nn.summary()
nn.plot_loss()

PCA

from ml_package.decomposition import PCA
pca = PCA(n_components=2)
X_reduced = pca.fit_transform(X)
pca.summary()
pca.plot_variance()

Pipeline

from ml_package.pipeline import Pipeline
pipe = Pipeline([
    ("imputer", MedianImputer()),
    ("scaler",  StandardScaler()),
    ("model",   NeuralNetwork(hidden_layers=(16, 8)))
])
pipe.fit(X_train, y_train)
pipe.predict(X_test)
pipe.summary()

Cross-Validation

from ml_package.model_selection import KFoldCV
from ml_package.metrics         import r2
kf = KFoldCV(n_splits=5, random_state=42)
kf.cross_val_score(LinearRegression(), X, y, metric_fn=r2)

Run Tests

pip install pytest
pytest tests/ -v

Upload to PyPI

pip install build twine
python -m build
twine upload dist/*

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

veda_ml_package-1.0.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

veda_ml_package-1.0.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file veda_ml_package-1.0.0.tar.gz.

File metadata

  • Download URL: veda_ml_package-1.0.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for veda_ml_package-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f6eca5a2ef18518d48409eb2876942a5b932ad45ef7d5c0364ac3e7e8c2f1e7a
MD5 c88fa791ec14e463cff7e78de1e30f61
BLAKE2b-256 7792be1ecb8927572180e7104eaf31428a8d5a9494553799994292b1408db4ab

See more details on using hashes here.

File details

Details for the file veda_ml_package-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for veda_ml_package-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 190409918d5fe8888ea8ecc5cf0edf4171b7f7dbca003b7eae7caa34c3729f1b
MD5 980ce8abff29a5ead18a4878209adb11
BLAKE2b-256 9085bbbd19d84823005e0737b4eb2129bbbcf05d23dc8e1b59a16f2df5899fc2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page