Skip to main content

A simple machine learning package built from scratch

Project description

ml_package

A custom machine learning library built from scratch — no sklearn dependency for core algorithms.

Algorithms Included

Module Classes
linear_models LinearRegression (OLS), Ridge (L2), Lasso (L1), ForwardSelection, BackwardElimination
decomposition PCA
neighbors KNNClassifier (city-block distance)
neural_network NeuralNetwork, Perceptron
preprocessing StandardScaler, MinMaxScaler, SimpleImputer, OutlierHandler, LabelEncoder, OneHotEncoder, Normalizer
metrics r2_score, rmse, mae, accuracy_score, confusion_matrix, f1_score
model_selection train_test_split
pipeline Pipeline

Install

pip install -e .

Quick Start

import numpy as np
from ml_package.linear_models.linear_regression import LinearRegression
from ml_package.metrics.regression import r2_score

X = np.random.randn(100, 3)
y = 3*X[:,0] + 2*X[:,1] + np.random.randn(100)*0.5

model = LinearRegression()
model.fit(X, y)
print(r2_score(y, model.predict(X)))

# Check all assumptions
model.check_normality()
model.check_multicollinearity()
model.check_heteroscedasticity()
model.plot_diagnostics()
from ml_package.decomposition.pca import PCA

pca = PCA(n_components=2)
X_pca = pca.fit_transform(X)
pca.plot_components(X)
from ml_package.neighbors.knn_classifier import KNNClassifier

knn = KNNClassifier(k=3, metric="cityblock")
knn.fit(X_train, y_train)
preds = knn.predict(X_test)
from ml_package.neural_network.neural_network import NeuralNetwork
from ml_package.neural_network.perceptron import Perceptron

nn = NeuralNetwork(hidden_size=8, learning_rate=0.05, max_iter=1000)
nn.fit(X, y)

p = Perceptron(learning_rate=0.1, max_iter=200)
p.fit(X, y)

Run Tests

cd tests
python test_linear_regression.py
python test_pca.py
python test_knn.py
python test_neural_network.py

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

shilpa_j_ml_package-1.0.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

shilpa_j_ml_package-1.0.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for shilpa_j_ml_package-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0eeee1f0cd28826e1ac5b9434e1a8bd49425e430b38bad01be295d0bf3c77f2e
MD5 c5395cafbc7637e841a15864a8d2f2c8
BLAKE2b-256 f265b6392268a9e0a82c02c1ae2d5211df85123a6123e4504070d8d08dc4e448

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for shilpa_j_ml_package-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a495a41e0e3e8c4e57962d44dfaeeadde3d4f763baee79d4c6e811536bea644
MD5 a209b76035f0caa38486b0d6c2a76a51
BLAKE2b-256 7b0b7c3d4a73b27fa2547b6f3df4cfd1c61599dfeb771a4b83ccd067f8c33a62

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