How to change Sklearn flavors version in mlflow on azure machine learning?

Saeid Hedayati 11 Reputation points
2022-06-20T11:51:46.71+00:00

I need to change the flavors "sklearn_version" in mlflow from "0.22.1" to "1.0.0" on azure machine learning when I log my trained model, since this model will be incompatible with the sklearn version that I am using for deployment during inference. I could change the version of conda by setting "conda_env" in

   mlflow.sklearn.log_model(conda_env= 'my_env')  

212868-conda-yml.png

in the conda.yaml file, however it still remains unchanged in flavors in MLmodel file

212869-mlmodel.png

and here is script that I use to create this mlflow experiment in azure machine learning notebooks.

import mlflow  
from sklearn.tree import DecisionTreeRegressor  
  
from azureml.core import Workspace  
from azureml.core.model import Model  
from azureml.mlflow import register_model  
  
  
def run_model(ws, experiment_name, run_name, x_train, y_train):  
      
    # set up MLflow to track the metrics  
    mlflow.set_tracking_uri(ws.get_mlflow_tracking_uri())  
    mlflow.set_experiment(experiment_name)    
      
    with mlflow.start_run(run_name=run_name) as run:  
          
        # fit model  
        regression_model = DecisionTreeRegressor()  
        regression_model.fit(x_train, y_train)  
	  
	    # log training score   
        training_score = regression_model.score(x_train, y_train)  
        mlflow.log_metric("Training score", training_score)  
  
        my_conda_env = {  
                    "name": "mlflow-env",  
                    "channels": ["conda-forge"],  
                    "dependencies": [  
                        "python=3.8.5",  
                        {  
                            "pip": [  
                                "pip",  
                                "scikit-learn~=1.0.0",  
                                "uuid==1.30",  
                                "lz4==4.0.0",  
                                "psutil==5.9.0",  
                                "cloudpickle==1.6.0",  
                                "mlflow",  
                            ],  
                        },  
                    ],  
                }  
  
          
        # register the model  
        mlflow.sklearn.log_model(regression_model, "model", conda_env=my_conda_env)  
  
    model_uri = f"runs:/{run.info.run_id}/model"  
    model = mlflow.register_model(model_uri, "sklearn_regression_model")  
  
if __name__ == '__main__':  
  
    # connect to your workspace  
    ws = Workspace.from_config()  
  
    # create experiment and start logging to a new run in the experiment  
    experiment_name = "exp_name"  
  
    # mlflow run name  
    run_name= '1234'  
  
    
    # get train data  
    x_train, y_train  = get_train_data()  
      
    run_model(ws, experiment_name, run_name, x_train, y_train)  
  

Any idea how can change the flavor sklearn version in "MLmodel" file in my script?

With many thanks in advance!

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
1,649 questions
No comments
1 vote

2 answers

Sort by: Most helpful
  1. Saeid Hedayati 11 Reputation points
    2022-06-21T16:26:59.363+00:00

    Thanks for your response!! I was able to solve this issue by updating scikit-learn within my workspace. Mlflow MLmodel takes that version of scikit-learn to generate flavors. But I think your solution is also correct.


  2. Ramr-msft 10,376 Reputation points Microsoft Employee
    2022-06-21T10:43:01.38+00:00

    @Saeid Hedayati Thanks for the question. Which version of Azure ML SDK are you using?. Here is the sample that could help to custom MLmodel.

    No comments