Skip to main content

A lightweight AutoML library for classification, built from scratch.

Project description

autoclass-lite

PyPI version Python

A lightweight AutoML library for classification, built from scratch using only NumPy. Trains multiple models with cross-validation, ranks them by performance, and returns the best one — all in a single fit() call.

Installation

pip install autoclass-lite

Quick Start

from autoclass_lite import SimpleAutoML, GridAutoML

# Train all models and get a ranked leaderboard
automl = SimpleAutoML()
automl.fit(X_train, y_train)
automl.summary()

# Predict using the best model
predictions = automl.predict(X_test)

# Grid search over hyperparameters
grid = GridAutoML()
grid.fit(X_train, y_train)
grid.summary()

Features

  • 4 classifiers implemented from scratch: KNN, Naive Bayes, Logistic Regression, Decision Tree
  • K-Fold cross-validation with parallel fold evaluation
  • Hyperparameter grid search with memoization cache (dynamic programming)
  • Observer-based progress reporting
  • Accepts NumPy arrays, Python lists, and Pandas DataFrames

Usage Examples

SimpleAutoML

from autoclass_lite import SimpleAutoML

automl = SimpleAutoML(
    cv_splits=5,        # number of cross-validation folds
    metric="accuracy",  # metric used to rank models
    random_state=42
)
automl.fit(X_train, y_train)
automl.summary()
preds = automl.predict(X_test)

GridAutoML

from autoclass_lite import GridAutoML

param_grid = {
    "logistic_regression": [
        {"learning_rate": 0.01},
        {"learning_rate": 0.1},
    ],
    "knn": [{"k": 3}, {"k": 5}, {"k": 7}],
    "decision_tree": [{"max_depth": 3}, {"max_depth": 5}],
}

grid = GridAutoML(param_grid=param_grid, metric="f1_score")
grid.fit(X_train, y_train)
grid.summary()

Logistic Regression

from autoclass_lite.models.logistic import LogisticRegression

model = LogisticRegression(learning_rate=0.01, n_iterations=1000)
model.fit(X_train, y_train)
predictions = model.predict(X_test)

Metrics

from autoclass_lite.metrics.classification import accuracy, precision, recall, f1_score, evaluate

acc = accuracy(y_true, y_pred)

results = evaluate(y_true, y_pred, metrics=[accuracy, precision, recall, f1_score])

Observer (progress reporting)

from autoclass_lite.automl.observers import ConsoleObserver

automl = SimpleAutoML()
automl.add_observer(ConsoleObserver())
automl.fit(X_train, y_train)

Project Structure

autoclass_lite/
├── __init__.py               # Public API: SimpleAutoML, GridAutoML
├── automl/
│   ├── orchestrator.py       # SimpleAutoML, GridAutoML (Facade pattern)
│   ├── factory.py            # ModelFactory (Factory pattern)
│   └── observers.py          # Observer, ConsoleObserver (Observer pattern)
├── models/
│   ├── base.py               # BaseModel ABC (Strategy + Template Method)
│   ├── logistic.py           # LogisticRegression
│   ├── knn.py                # KNNClassifier
│   ├── naive_bayes.py        # GaussianNaiveBayes
│   └── tree.py               # DecisionTreeClassifier (recursive)
├── cv/
│   ├── splitter.py           # KFoldSplitter
│   └── validator.py          # CrossValidator (ThreadPoolExecutor)
└── metrics/
    └── classification.py     # Pure functions + evaluate() HOF
tests/                        # pytest test suite
pyproject.toml
README.md

Learning Outcomes

1. Object-Oriented Programming (OOP)

  • Encapsulation: All internal state uses private attributes (_weights, _biases, _cache, etc.). Users interact only through the public API.
  • Abstract Base Class: BaseModel in autoclass_lite/models/base.py defines the interface all classifiers must implement.
  • Inheritance: KNNClassifier, GaussianNaiveBayes, LogisticRegression, DecisionTreeClassifier all extend BaseModel. GridAutoML extends SimpleAutoML.
  • Polymorphism: CrossValidator calls .fit() and .predict() on any BaseModel subclass without knowing its concrete type.

2. Functional Programming

  • Pure functions: accuracy, precision, recall, f1_score in autoclass_lite/metrics/classification.py take arrays and return a value with no side effects.
  • Higher-order function: evaluate(y_true, y_pred, metrics: list) takes a list of metric functions and applies them, returning a results dict.
  • Lambdas as data: KNNClassifier._DISTANCES is a class-level dict mapping distance names to lambda functions, selected at runtime.

3. Concurrency

CrossValidator in autoclass_lite/cv/validator.py uses ThreadPoolExecutor to evaluate all K folds in parallel. Each fold gets a copy.deepcopy of the model to ensure thread safety.

with ThreadPoolExecutor() as executor:
    futures = [executor.submit(self._evaluate_fold, ...) for fold in folds]

4. Recursion / Dynamic Programming

  • Recursion: DecisionTreeClassifier in autoclass_lite/models/tree.py uses _grow_tree() to recursively split nodes and _traverse() to recursively walk the tree during prediction.
  • Dynamic Programming (Memoization): GridAutoML in autoclass_lite/automl/orchestrator.py maintains a _cache dict. Every (model_name, params) combination is evaluated at most once — repeated configurations are looked up from cache instead of re-running cross-validation.
cache_key = (name, frozenset(params.items()))
if cache_key in self._cache:
    scores = self._cache[cache_key]
else:
    scores = validator.validate(model, X, y)
    self._cache[cache_key] = scores

5. SOLID Principles

  • Single Responsibility: Each class does exactly one thing. KFoldSplitter only splits indices. CrossValidator only runs folds. ModelFactory only creates models.
  • Open/Closed: New models can be added by extending BaseModel and registering in ModelFactory without touching existing code. SimpleAutoML.DEFAULT_CONFIGS allows adding new default configurations without modifying fit().
  • Liskov Substitution: Any BaseModel subclass can replace another anywhere in the system.
  • Interface Segregation: BaseModel only requires fit and predict. Optional get_params has a default implementation in the base class.
  • Dependency Inversion: CrossValidator depends on BaseModel (abstraction), not any concrete classifier.

6. Architectural & Design Patterns

Architecture: Layered pipeline — models → cross-validation → metrics → AutoML orchestration. Each layer depends only on the layer below it.

Factory Patternautoclass_lite/automl/factory.py

ModelFactory.create(name, **kwargs) instantiates any registered model by name. Adding a new model requires only one line in the registry dict.

Strategy Patternautoclass_lite/models/base.py, autoclass_lite/models/knn.py

  • BaseModel defines the classifier interface; each model is a concrete strategy swappable at runtime by ModelFactory.
  • KNNClassifier._DISTANCES selects the distance function at construction time — euclidean or manhattan — without any if/else in the prediction loop.

Observer Patternautoclass_lite/automl/observers.py

SimpleAutoML notifies all registered observers on fit_start, model_done, and fit_done events without coupling to any specific logger or UI.

Template Method Patternautoclass_lite/models/base.py

BaseModel.fit_predict() defines the skeleton (fit then predict). Subclasses implement the steps; the sequence is inherited and never duplicated.

Facade Patternautoclass_lite/automl/orchestrator.py

SimpleAutoML exposes a single fit() / predict() / summary() interface that internally coordinates model creation, cross-validation, and ranking.

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

autoclass_lite-0.1.2.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

autoclass_lite-0.1.2-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file autoclass_lite-0.1.2.tar.gz.

File metadata

  • Download URL: autoclass_lite-0.1.2.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for autoclass_lite-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d43ad974e8668f2b2694fb86ef49a49ca98fd334fa822c235d3d4c91c05c66e4
MD5 bea3fdaeb9d060cf97b900841f335783
BLAKE2b-256 0c8aa497d6f81ffdb514b43164c1a946d128b2e17ff3e2da0e2fcb7cbf165857

See more details on using hashes here.

File details

Details for the file autoclass_lite-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: autoclass_lite-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for autoclass_lite-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 840389430f1fe0bef9da6a1b783e9259510562d7ae8219ea95c324bdc8949f7f
MD5 c0bb122776f758a92c1795e17f6a32fc
BLAKE2b-256 d9745daf3dd08879c5cb99636bfe9ca64e9a264703c20fa5f10bfd81531d525d

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