Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/openscilab/pymilo

PyMilo: Python for ML I/O
https://github.com/openscilab/pymilo

artificial-intelligence artificial-intelligence-algorithms artificial-neural-networks deep-learning deserialization devops devops-tools machine-learning machine-learning-algorithms ml ml-models-export ml-models-import mlops scikit-learn serialization

Last synced: 3 months ago
JSON representation

PyMilo: Python for ML I/O

Awesome Lists containing this project

README

        







Codecov
PyPI version

built with Python3
Discord Channel

----------

## Overview


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
CodeFactor

codebeat badge

## Installation

### PyPI

- Check [Python Packaging User Guide](https://packaging.python.org/installing/)
- Run `pip install pymilo==0.9`
### Source code
- Download [Version 0.9](https://github.com/openscilab/pymilo/archive/v0.9.zip) or [Latest Source](https://github.com/openscilab/pymilo/archive/dev.zip)
- Run `pip install .`

### Conda

- Check [Conda Managing Package](https://conda.io/)
- Update Conda using `conda update conda`
- Run `conda install -c openscilab pymilo`

## Usage
Imagine you want to train a `LinearRegression` model representing this equation: $y = x_0 + 2x_1 + 3$. You will create data points (`X`, `y`) and train your model as follows.
```pycon
>>> 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.
```pycon
>>> from pymilo import Export
>>> Export(model).save("model.json")
```

You can check out your model as a JSON file now.
```json
{
"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.
```pycon
>>> 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.

## Supported ML models
| 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](https://github.com/openscilab/pymilo/blob/main/SUPPORTED_MODELS.md).

## Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP! or send an email to [[email protected]](mailto:[email protected] "[email protected]").

- Please complete the issue template

You can also join our discord server


Discord Channel

## Show your support

### Star this repo

Give a ⭐️ if this project helped you!

### Donate to our project
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 ;-) .

PyMilo Donation