当我记录经过训练的模型时,我需要将mlflow中的"sklearn_version“从"0.22.1”更改为"1.0.0“,这是因为这个模型将与我在推理期间用于部署的sklearn版本不兼容。我可以通过在conda.yml文件中设置"conda_env“
mlflow.sklearn.log_model(conda_env= 'my_env')

这是requirements.txt的屏幕截图

但是,在MLmodel文件中,sklearn下的版本保持不变,这是导致问题的文件:

下面是我用来在蓝色机器学习笔记本中创建这个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文件中的版本从"0.22.1"更改为"1.0.0"吗?
提前表示感谢!
发布于 2022-06-20 11:26:04
版本的修改必须来自"requirements.txt".。我们需要手动覆盖所需的版本,并将构建移动到管道中。
手动编辑以下代码
conda_env = {
'channels': ['conda-forge'],
'dependencies': [
'python=3.8.8',
'pip'],
'pip': [
'mlflow',
'scikit-learn==0.23.2',
'cloudpickle==1.6.0'
],
'name': 'mlflow-env'
}
mlflow.sklearn.log_model(model, "my_model", conda_env=conda_env)下面的代码应该在conda.yml中
name: mlflow-env
channels:
- conda-forge
dependencies:
- python=3.8.8
- pip
- pip:
- mlflow
- scikit-learn==0.23.2
- cloudpickle==1.6.0下面的代码块必须在python_env.yaml中
python: 3.8.8
build_dependencies:
- pip==21.1.3
- setuptools==57.4.0
- wheel==0.37.0
dependencies:
- -r requirements.txt在requirements.txt中必须有以下内容
mlflow
scikit-learn==0.23.2
cloudpickle==1.6.0发布于 2022-06-21 16:37:40
我终于解决了这个问题。显然,mlflow MLfile中的口味使用的版本是安装的scikit-在工作区中学习。我所需要做的就是升级scikit--从工作区内的cli中学习。
notebooks
pip install --upgrade scikit-learn==1.0.2通过再次运行培训脚本,

https://stackoverflow.com/questions/72684326
复制相似问题