PyMilo is an open source Python package that provides a simple, efficient, and safe way for users to export pre-trained machine learning models in a transparent way. By this, the exported model can be used in other environments, transferred across different platforms, and shared with others. PyMilo allows the users to export the models that are trained using popular Python libraries like scikit-learn, and then use them in deployment environments, or share them without exposing the underlying code or dependencies. The transparency of the exported models ensures reliability and safety for the end users, as it eliminates the risks of binary or pickle formats.
PyPI Counter |
|
Github Stars |
|
Branch | main | dev |
CI |
|
|
Code Quality |
- Check Python Packaging User Guide
- Run
pip install pymilo==0.9
- Download Version 0.9 or Latest Source
- Run
pip install .
- Check Conda Managing Package
- Update Conda using
conda update conda
- Run
conda install -c openscilab pymilo
Imagine you want to train a LinearRegression
model representing this equation: X
, y
) and train your model as follows.
>>> import numpy as np
>>> from sklearn.linear_model import LinearRegression
>>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
>>> y = np.dot(X, np.array([1, 2])) + 3
# y = 1 * x_0 + 2 * x_1 + 3
>>> model = LinearRegression().fit(X, y)
>>> pred = model.predict(np.array([[3, 5]]))
# pred = [16.] (=1 * 3 + 2 * 5 + 3)
Using PyMilo Export
class you can easily serialize and export your trained model into a JSON file.
>>> from pymilo import Export
>>> Export(model).save("model.json")
You can check out your model as a JSON file now.
{
"data": {
"fit_intercept": true,
"copy_X": true,
"n_jobs": null,
"positive": false,
"n_features_in_": 2,
"coef_": {
"pymiloed-ndarray-list": [
1.0000000000000002,
1.9999999999999991
],
"pymiloed-ndarray-dtype": "float64",
"pymiloed-ndarray-shape": [
2
],
"pymiloed-data-structure": "numpy.ndarray"
},
"rank_": 2,
"singular_": {
"pymiloed-ndarray-list": [
1.618033988749895,
0.6180339887498948
],
"pymiloed-ndarray-dtype": "float64",
"pymiloed-ndarray-shape": [
2
],
"pymiloed-data-structure": "numpy.ndarray"
},
"intercept_": {
"value": 3.0000000000000018,
"np-type": "numpy.float64"
}
},
"sklearn_version": "1.4.2",
"pymilo_version": "0.8",
"model_type": "LinearRegression"
}
You can see all the learned parameters of the model in this file and change them if you want. This JSON representation is a transparent version of your model.
Now let's load it back. You can do it easily by using PyMilo Import
class.
>>> from pymilo import Import
>>> model = Import("model.json").to_model()
>>> pred = model.predict(np.array([[3, 5]]))
# pred = [16.] (=1 * 3 + 2 * 5 + 3)
This loaded model is exactly the same as the original trained model.
scikit-learn | PyTorch |
---|---|
Linear Models ✅ | - |
Neural networks ✅ | - |
Trees ✅ | - |
Clustering ✅ | - |
Naïve Bayes ✅ | - |
Support vector machines (SVMs) ✅ | - |
Nearest Neighbors ✅ | - |
Ensemble Models ✅ | - |
Pipeline Model ✅ | - |
Preprocessing Models ✅ | - |
Details are available in Supported Models.
Just fill an issue and describe it. We'll check it ASAP! or send an email to [email protected].
- Please complete the issue template
You can also join our discord server
Give a ⭐️ if this project helped you!
If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) .