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

Saeid Hedayati 11 Reputation points

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')  


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


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  
    with mlflow.start_run(run_name=run_name) as run:  
        # fit model  
        regression_model = DecisionTreeRegressor() , 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": [  
                            "pip": [  
        # register the model  
        mlflow.sklearn.log_model(regression_model, "model", conda_env=my_conda_env)  
    model_uri = f"runs:/{}/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

    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

    @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