mlflow训练机器学习模板

1 安装mlflow

pip install  mlflow

2.测试

import mlflow
import mlflow.sklearn

# 设置mlflow的地址

mlflow.set_tracking_uri("http://192.**.**.***:10000/")

# 创建实验(如果第一次创建了,需要从新启动)

mlflow.create_experiment("test")

# 加载实验

mlflow.set_experiment("test")# 逻辑回归模型
with mlflow.start_run():
    mlflow.log_param("model", "logisticregression")
    mlflow.log_param("max_iter", "5")
    ts = time.time()
    clf = LogisticRegression(verbose=1, max_iter=1)
    clf.fit(train_x, train_y)
    score = clf.score(train_x, train_y)
    mlflow.log_metric("train_acc", score)
    te = time.time()
    print("LogisticRegression train use time:", te-ts)
    print("LogisticRegression train set accuracy:", score)
#      测试集测试
    test_score = clf.score(test_x, test_y)
    print("LogisticRegression test set accuracy:", test_score )
    mlflow.log_metric("test_acc", test_score)

等模型训练完就可以在浏览器中查看自己的训练结果了

你可能感兴趣的:(mac)