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 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:
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.
Metadata
Release files for autoclass-lite 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| autoclass_lite-0.1.2.tar.gz | 19.2 kB | Without provenance | Details for autoclass_lite-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autoclass_lite-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for autoclass_lite-0.1.2-py3-none-any.whl |
Total release size: 36.7 kB
Release files / autoclass_lite-0.1.2.tar.gz
| Download URL | autoclass_lite-0.1.2.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d43ad974e8668f2b2694fb86ef49a49ca98fd334fa822c235d3d4c91c05c66e4
|
|
BLAKE2b-256 checksum How to use checksums |
0c8aa497d6f81ffdb514b43164c1a946d128b2e17ff3e2da0e2fcb7cbf165857
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / autoclass_lite-0.1.2-py3-none-any.whl
| Download URL | autoclass_lite-0.1.2-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
840389430f1fe0bef9da6a1b783e9259510562d7ae8219ea95c324bdc8949f7f
|
|
BLAKE2b-256 checksum How to use checksums |
d9745daf3dd08879c5cb99636bfe9ca64e9a264703c20fa5f10bfd81531d525d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for autoclass-lite 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.