Metadata-Version: 2.1
Name: mlModelSaver
Version: 1.0.22
Summary: Make life easier for saving and serving ML models
Home-page: https://github.com/smartdev-ca/mlModelSaver
Author: Jason Jafari
Author-email: me@jasonjafari.com
Project-URL: Documentation, https://github.com/smartdev-ca/mlModelSaver/blob/main/DOCS.md
Project-URL: Source, https://github.com/smartdev-ca/mlModelSaver
Project-URL: Tracker, https://github.com/smartdev-ca/mlModelSaver/issues
Keywords: machine learning model saving serving
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy >=1.26.4
Requires-Dist: pandas >=2.2.2
Requires-Dist: scikit-learn >=1.5.0
Requires-Dist: statsmodels >=0.14.2
Requires-Dist: matplotlib >=3.9.0
Requires-Dist: dill >=0.3.8

# mlModelSaver documentation


Introducing **[mlModelSaver](https://pypi.org/project/mlModelSaver/)** – a streamlined Python module designed for data scientists and developers who seek a straightforward solution for model saving and serving.

While numerous tools are available for training machine learning models, many lightweight statistical models lack simple, efficient saving mechanisms. Existing enterprise solutions like MLflow are robust but come with considerable complexity. Based on my experience, I saw the need for an abstract model registry concept that simplifies this process.

**[mlModelSaver](https://github.com/smartdev-ca/mlModelSaver)** fills this gap, offering an intuitive way to save machine learning models and transformers. It facilitates seamless integration with frameworks like FastAPI ([Examples](https://github.com/jafarijason/ml_models_deployments)), Flask, and Django, enabling easy deployment and serving of models in production environments. Empower your machine learning workflow with **mlModelSaver** – the easy and efficient tool for model management.

## Installation

You can install **mlModelSaver** via pip:

```bash
pip install mlModelSaver
```


# mlModelSaver Example: Simple Linear Regression

In this example, we demonstrate how to use **mlModelSaver** to export a simple linear regression model based on a notebook from [ml_models_deployments](https://github.com/jafarijason/ml_models_deployments/blob/master/notebooks/001.ipynb).

### Example Description

This example builds a simple linear regression model to predict sales based on temperature, advertising, and discount factors. Once the model is fitted and satisfactory, **mlModelSaver** allows you to easily save and deploy the model for use in production environments.

### Example Code - notebook available [here](https://github.com/jafarijason/ml_models_deployments/blob/master/notebooks/001.ipynb)


```python
def add_constant_columnTransformer(df):
    # example transformer
    df_with_const = df.copy()
    df_with_const.insert(0, 'const', 1)
    return df_with_const

# Export the model using MlModelSaver
loadedModel = mlModelSaverInstance.exportModel(
    simpleLinearRegressionFittedModel, # the models is fitted and ready for usage
    {
        "modelName": "modelPredictSaleByTemperatureAdvertisingDiscountFit",
        "description": "Example model predicting sales based on temperature, advertising, and discount.",
        "modelType": "sm.OLS",  # Example model type (replace with actual type)
        "inputs": [
            {"name": "Temperature", "type": "float"},
            {"name": "Advertising", "type": "float"},
            {"name": "Discount", "type": "float"}
        ],
        "transformer": add_constant_columnTransformer,  # Use your transformation function here
        "outputs": [
            {
                "name": "Sales",
                "type": "float"
            }
        ]
    }
)
```
