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 aishwarya_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

aishwarya_ml_package-1.0.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

aishwarya_ml_package-1.0.0-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aishwarya_ml_package-1.0.0.tar.gz
Algorithm Hash digest
SHA256 75061116df2229c12f45f8b3bb0d4f88fdae9ea8f03e3c495e42dbd676c4f22d
MD5 871f5a01e67f6b86940cc984bd767ae9
BLAKE2b-256 2e0d73c7b00f9fdedf0b1524229b5ddcca007aa6902976cb524847524568ec73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aishwarya_ml_package-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fe5c1bcc3a7f032afacc0ce5da9c74b55899b0ebc84193141852276b9304545
MD5 6e004dfc0016287da898494a9043b834
BLAKE2b-256 a10e75410a59f0e7e46613f2699bba7eaa67b5f4dfce672f36a7c4545d7c7c42

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