A simple library to train, manage, and use multiple ML models easily.
Project description
ml_model_handler
A lightweight Python package for training, managing, and predicting with multiple machine learning models.
Supports classical ML algorithms, pipelines, ensemble learning (Voting), and user-defined custom estimators.
Features
- Preconfigured ML models: Logistic Regression, KNN, Naive Bayes, Decision Tree, Random Forest, Gradient Boosting, XGBoost, SVM, SGD.
- Voting Classifier support (soft/hard voting).
- Plug-and-play with custom estimators.
- Built-in pipelines with
StandardScalerwhere useful. - Easy single prediction and batch predictions.
- Probability predictions (
predict_proba) when available.
Installation
pip install ml-model-handler
Quick Start
import pandas as pd
from ml_model_handler import MLModelHandler
# Example dataset
X = pd.DataFrame({
"feature1": [1, 2, 3, 4],
"feature2": [10, 20, 30, 40]
})
y = [0, 1, 0, 1]
# Initialize handler
model_handler = MLModelHandler()
# Train default models
model_handler.train_models(X, y)
# Single prediction
print(model_handler.predict("logistic", [5, 50]))
# Batch prediction
batch_features = [
[6, 60],
[7, 70]
]
model_handler.batch_predict("knn", batch_features)
# Probability prediction
print(model_handler.predict_proba("logistic", [5, 50]))
Voting Classifier
The voting estimator combines predictions from multiple trained models (soft or hard voting).
# Use Logistic, KNN and Voting
model_handler.train_models(X, y, estimators=["logistic", "knn"], voting_type="soft")
print(model_handler.predict("voting", [7, 70]))
⚠️ If fewer than 2 base models are given with voting, it falls back to all trained models with a warning.
Custom Estimators
You can extend with your own models:
from sklearn.linear_model import RidgeClassifier
custom = {
"ridge": RidgeClassifier()
}
model_handler.train_models(X, y, estimators=["ridge"])
print(model_handler.predict("ridge", [8, 80]))
Project Structure
ml_model_handler/
├── __init__.py
└── main.py # MLModelHandler class
README.md
setup.py
Contributing
Contributions are welcome!
- Fork the repo
- Create a feature branch
- Submit a pull request
License
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 ml_model_handler-0.1.0.tar.gz.
File metadata
- Download URL: ml_model_handler-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d528ce28c3d6370e6d3f983c8ee3a4ae844ee28a1474fd6766b13007ae2e5563
|
|
| MD5 |
b6649025b3aa613823bf4ac3e48627db
|
|
| BLAKE2b-256 |
b564b3a40bd9e47b2517ec6e539b947eb1041a1f5edbcb6d4fa6db4ddf6c2162
|
File details
Details for the file ml_model_handler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ml_model_handler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d464f731259b16f56b62fad6071dff40bec5e37382badd5fd068178108a4127d
|
|
| MD5 |
b2ca6885aa67e67e38b126965519d1e3
|
|
| BLAKE2b-256 |
d3aa82c5226771e04993afdecd4abec71e9710edae41a954ba5fe451ee6494f7
|