A lightweight AutoML library for classification, built from scratch.
Project description
autoclass-lite
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 -e .
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:
BaseModelin autoclass_lite/models/base.py defines the interface all classifiers must implement. - Inheritance:
KNNClassifier,GaussianNaiveBayes,LogisticRegression,DecisionTreeClassifierall extendBaseModel.GridAutoMLextendsSimpleAutoML. - Polymorphism:
CrossValidatorcalls.fit()and.predict()on anyBaseModelsubclass without knowing its concrete type.
2. Functional Programming
- Pure functions:
accuracy,precision,recall,f1_scorein 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._DISTANCESis 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:
DecisionTreeClassifierin autoclass_lite/models/tree.py uses_grow_tree()to recursively split nodes and_traverse()to recursively walk the tree during prediction. - Dynamic Programming (Memoization):
GridAutoMLin autoclass_lite/automl/orchestrator.py maintains a_cachedict. 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.
KFoldSplitteronly splits indices.CrossValidatoronly runs folds.ModelFactoryonly creates models. - Open/Closed: New models can be added by extending
BaseModeland registering inModelFactorywithout touching existing code.SimpleAutoML.DEFAULT_CONFIGSallows adding new default configurations without modifyingfit(). - Liskov Substitution: Any
BaseModelsubclass can replace another anywhere in the system. - Interface Segregation:
BaseModelonly requiresfitandpredict. Optionalget_paramshas a default implementation in the base class. - Dependency Inversion:
CrossValidatordepends onBaseModel(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 Pattern — autoclass_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 Pattern — autoclass_lite/models/base.py, autoclass_lite/models/knn.py
BaseModeldefines the classifier interface; each model is a concrete strategy swappable at runtime byModelFactory.KNNClassifier._DISTANCESselects the distance function at construction time —euclideanormanhattan— without anyif/elsein the prediction loop.
Observer Pattern — autoclass_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 Pattern — autoclass_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 Pattern — autoclass_lite/automl/orchestrator.py
SimpleAutoML exposes a single fit() / predict() / summary() interface that internally coordinates model creation, cross-validation, and ranking.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autoclass_lite-0.1.0.tar.gz.
File metadata
- Download URL: autoclass_lite-0.1.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8813a6a5c599c5c9694893968be79c701cdde09b2fc1653e65a95a1fbf9111f4
|
|
| MD5 |
43ce55f733444141be4aae4d74bca1bd
|
|
| BLAKE2b-256 |
66fafe338fec6cdd66a4320b9a80c1254716b15bf6946a3bf95aefd5fef366b3
|
File details
Details for the file autoclass_lite-0.1.0-py3-none-any.whl.
File metadata
- Download URL: autoclass_lite-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0e752c44d46e0f7e15746ecfb65bc2faa7e6f212b8f3fa2a06e6486c3c879e0
|
|
| MD5 |
9c40b944a3c002269836d46301441743
|
|
| BLAKE2b-256 |
c28b136ecbb612a8c0d45847252775816966c6e2a354316c93aab1dfe3629671
|