当前位置: 首页 > news >正文

MLflow (机器学习/深度学习 mlops平台 kubeflow)

MLflow 是一个功能强大的ML生命周期管理平台,主要用于 ML/DL/LLM 实验管理、模型跟踪、模型部署等。

# 1.1 创建虚拟环境
conda create -n mlflow-env python=3.10
conda activate mlflow-env# 1.2 Install mlflow
pip install mlflow# 2.1 Run a local Tracking Server
mlflow server --host 127.0.0.1 --port 8080 # 默认5000# 3. 构建demo训练
mkdir /your/path/mlflow-demo
cd /your/path/mlflow-demo# 3.1 Train a model and prepare metadata for logging
vi train.py========================================================
# train.py
import mlflow
from mlflow.models import infer_signatureimport pandas as pd
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score# Load the Iris dataset
X, y = datasets.load_iris(return_X_y=True)# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42
)# Define the model hyperparameters
params = {"solver": "lbfgs","max_iter": 1000,"multi_class": "auto","random_state": 8888,
}# Train the model
lr = LogisticRegression(**params)
lr.fit(X_train, y_train)# Predict on the test set
y_pred = lr.predict(X_test)# Calculate metrics
accuracy = accuracy_score(y_test, y_pred)
========================================================# 3.2 Log the model and its metadata to MLflow
========================================================
# Set our tracking server uri for logging
mlflow.**set_tracking_uri**(uri="http://127.0.0.1:8080")# Create a new MLflow Experiment
mlflow.set_experiment("MLflow Quickstart")# Start an MLflow run
with mlflow.start_run():# Log the hyperparametersmlflow.log_params(params)# Log the loss metricmlflow.log_metric("accuracy", accuracy)# Infer the model signaturesignature = infer_signature(X_train, lr.predict(X_train))# Log the model, which inherits the parameters and metricmodel_info = mlflow.sklearn.log_model(sk_model=lr,name="iris_model",signature=signature,input_example=X_train,registered_model_name="tracking-quickstart",)# Set a tag that we can use to remind ourselves what this model was formlflow.set_logged_model_tags(model_info.model_id, {"Training Info": "Basic LR model for iris data"})
========================================================# 4. Load the model as a Python Function (pyfunc) and use it for inference
========================================================
# Load the model back for predictions as a generic Python Function model
loaded_model = mlflow.pyfunc.**load_model**(model_info.model_uri)predictions = loaded_model.predict(X_test)iris_feature_names = datasets.load_iris().feature_namesresult = pd.DataFrame(X_test, columns=iris_feature_names)
result["actual_class"] = y_test
result["predicted_class"] = predictionsresult[:4]
========================================================# 注意在启动训练前,需要保证mlflow server已经启动
# 5.1 View the Run and Model in the MLflow UI
python train.py# 5.1 启动ui,然后打开浏览器访问:http://127.0.0.1:8080 查看运行结果。
mlflow ui

 

http://www.jsqmd.com/news/66902/

相关文章:

  • 2025年GEO 服务商效果怎么样?:权威解析与精选推荐
  • 光纤通信系统:技术原理与实现路径
  • 2025双铂金火花塞源头工厂TOP5推荐:知名厂家/制造商甄
  • 2025年GEO 服务商服务内容有哪些?:权威榜单与攻略揭秘
  • 手写RPC框架
  • 2025年高光谱视觉设备企业TOP5推荐:彩鸿芯宇产品性价比
  • 2025年公园游船电动船厂家推荐:科普型观光船厂家怎么选
  • 2025年值得合作的 GEO 服务商推荐:独家测评深度指南
  • Java 8 函数式编程详解:从思想到实战
  • 2025年GEO 服务商收费标准是多少?:最新深度解析推荐
  • win10 nodejs 升级/安装
  • 2025年宝宝红屁屁选什么纸尿裤排行榜:准爸妈必看的权威选购指南
  • 2025年上海柔性夹爪优选指南:为何苏州柔触值得推荐
  • 2025年全国 GEO 服务商有哪些推荐?:官方报告与攻略必
  • 2025年市场活动策划推荐及选择参考
  • 2025柔性夹爪选哪家?苏州柔触机器人的技术突破与行业实践
  • 2025年专业 GEO 服务商排名:独家TOP10深度揭秘
  • 保姆级教程:将N8N升级为“全模态”神器,看图、听音样样行!
  • 2025耳机抓取机械手品牌推荐:苏州柔触柔性夹爪的技术突破与应用
  • 2025年抽检验货企业权威推荐榜单:工艺品验货‌/产品检验‌/验货监装‌‌源头企业精选
  • 基于TI F28027 DSP实现光伏MPPT闭环控制
  • Shell脚本实用技巧|运维必备的10个脚本
  • 2025年性价比高的 GEO 服务商有哪些?:权威精选测评推
  • 盘点2025年楼板搭建优质公司,口碑与实力并存,别墅现浇/现浇楼梯/现浇钢筋混凝土楼板/阁楼现浇/现浇搭建楼板搭建公司哪个好选哪家
  • 2025年铱金火花塞供应商推荐、火花塞源头工厂排名全解析
  • 2025年度英国移民实力强的机构TOP5权威推荐:甄选企业助
  • 贝力达光电缆有限公司的产品质量怎样?产品价格合理不?
  • 2025年靠谱的打包机供应商推荐:五大实力强的纤维与油压打包
  • 哈尔滨律师事务所选哪家
  • 深度剖析闸机租赁领域三大常见陷阱,揭示闸机租赁源头厂商的服务模式与产品优势。