如何在Azure机器学习中更改MLFlow中的Sklearn Flavors版本?
当我记录训练有素的模型时在推理期间。 中设置conda.yml文件中的sklearn版本
我可以通过在mlflow.sklearn.log_model(conda_env ='my_env')
。 net/urygm.png“ rel =“ nofollow noreferrer”>
但是,mlModel文件中的口味下的Sklearn版本保持不变,这是引起问题的文件:
,我用这是我用来在Azure中创建此mlflow实验的脚本机器学习笔记本。
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)
任何想法如何将mlmodel文件中的风味sklearn版本从“ 0.22.1” “ ”更改为“ 1.0.0” 在我的脚本中?
预先感谢!
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 sklearn in conda.yml file by setting "conda_env" in
mlflow.sklearn.log_model(conda_env= 'my_env')
here is the screen shot of requirements.txt
however, sklearn version under flavors in MLmodel file remains unchanged and that is the file that causes problem:
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 from "0.22.1" to "1.0.0" in my script?
With many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
版本的修改必须来自
“ unignts.txt”
。我们需要手动覆盖所需的版本,并将构建移至管道。手动编辑以下
应在conda中
。
代码
The modifications of the versions must be from
"requirements.txt"
. We need to manually override the versions we need and move the build to the pipeline.Manually edit the following code
The below code should be in conda.yml
The following code block must be there in python_env.yaml
The following thing must be there in requirements.txt
我终于能够解决这个问题。显然,MLFLOW MLFILE中的口味使用工作空间中安装的Scikit-Learn版本。我需要做的就是从工作区内的CLI升级Scikit-Learn。
I was finally able to solve this issue. Apparently flavors within mlflow MLfile use the version of installed scikit-learn within the workspace. all I needed to to was to upgrade the scikit-learn from cli within workspace.