当前位置: 首页>>代码示例>>Python>>正文


Python mlflow.log_metrics方法代码示例

本文整理汇总了Python中mlflow.log_metrics方法的典型用法代码示例。如果您正苦于以下问题:Python mlflow.log_metrics方法的具体用法?Python mlflow.log_metrics怎么用?Python mlflow.log_metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mlflow的用法示例。


在下文中一共展示了mlflow.log_metrics方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_epoch_end

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def on_epoch_end(self, epoch, logs=None):
        """
        Log Keras metrics with MLflow. If model improved on the validation data, evaluate it on
        a test set and store it as the best model.
        """
        if not logs:
            return
        self._next_step = epoch + 1
        train_loss = logs["loss"]
        val_loss = logs["val_loss"]
        mlflow.log_metrics({
            self.train_loss: train_loss,
            self.val_loss: val_loss
        }, step=epoch)

        if val_loss < self._best_val_loss:
            # The result improved in the validation set.
            # Log the model with mlflow and also evaluate and log on test set.
            self._best_train_loss = train_loss
            self._best_val_loss = val_loss
            self._best_model = keras.models.clone_model(self.model)
            self._best_model.set_weights([x.copy() for x in self.model.get_weights()])
            preds = self._best_model.predict(self._test_x)
            eval_and_log_metrics("test", self._test_y, preds, epoch) 
开发者ID:mlflow,项目名称:mlflow,代码行数:26,代码来源:train.py

示例2: log_metrics

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def log_metrics(metrics: Dict[str, Any], step: int = None):
    mlflow.log_metrics(metrics, step) 
开发者ID:criteo,项目名称:tf-yarn,代码行数:4,代码来源:mlflow.py

示例3: log_metrics

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def log_metrics(cls, metrics, step):
        raise NotImplementedError() 
开发者ID:deepset-ai,项目名称:FARM,代码行数:4,代码来源:utils.py

示例4: log

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def log(self, prefix, step=None, tensorboard=True, mlflow=False):
        step = step if step is not None else self.step

        if self.tensorboard_path and tensorboard:
            for key, value in self.get().items():
                self.writers[prefix].add_scalar('metrics/%s' % key, value, global_step=step)

        if mlflow:
            module_mlflow.log_metrics(self.get(prefix=prefix), step=step) 
开发者ID:wbaek,项目名称:theconf,代码行数:11,代码来源:meter.py

示例5: on_epoch_end

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def on_epoch_end(self, epoch, logs=None):
        if (epoch-1) % _LOG_EVERY_N_STEPS == 0:
            try_mlflow_log(mlflow.log_metrics, logs, step=epoch) 
开发者ID:mlflow,项目名称:mlflow,代码行数:5,代码来源:tensorflow.py

示例6: main

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def main():
    # parse command-line arguments
    args = parse_args()

    # prepare train and test data
    iris = datasets.load_iris()
    X = iris.data
    y = iris.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    train_set = lgb.Dataset(X_train, label=y_train)

    # enable auto logging
    mlflow.lightgbm.autolog()

    with mlflow.start_run():

        # train model
        params = {
            'objective': 'multiclass',
            'num_class': 3,
            'learning_rate': args.learning_rate,
            'metric': 'multi_logloss',
            'colsample_bytree': args.colsample_bytree,
            'subsample': args.subsample,
            'seed': 42,
        }
        model = lgb.train(params, train_set, num_boost_round=10,
                          valid_sets=[train_set], valid_names=['train'])

        # evaluate model
        y_proba = model.predict(X_test)
        y_pred = y_proba.argmax(axis=1)
        loss = log_loss(y_test, y_proba)
        acc = accuracy_score(y_test, y_pred)

        # log metrics
        mlflow.log_metrics({'log_loss': loss, 'accuracy': acc}) 
开发者ID:mlflow,项目名称:mlflow,代码行数:39,代码来源:train.py

示例7: main

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def main():
    # parse command-line arguments
    args = parse_args()

    # prepare train and test data
    iris = datasets.load_iris()
    X = iris.data
    y = iris.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    dtrain = xgb.DMatrix(X_train, label=y_train)
    dtest = xgb.DMatrix(X_test, label=y_test)

    # enable auto logging
    mlflow.xgboost.autolog()

    with mlflow.start_run():

        # train model
        params = {
            'objective': 'multi:softprob',
            'num_class': 3,
            'learning_rate': args.learning_rate,
            'eval_metric': 'mlogloss',
            'colsample_bytree': args.colsample_bytree,
            'subsample': args.subsample,
            'seed': 42,
        }
        model = xgb.train(params, dtrain, evals=[(dtrain, 'train')])

        # evaluate model
        y_proba = model.predict(dtest)
        y_pred = y_proba.argmax(axis=1)
        loss = log_loss(y_test, y_proba)
        acc = accuracy_score(y_test, y_pred)

        # log metrics
        mlflow.log_metrics({'log_loss': loss, 'accuracy': acc}) 
开发者ID:mlflow,项目名称:mlflow,代码行数:39,代码来源:train.py

示例8: test_log_metrics_uses_millisecond_timestamp_resolution_fluent

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def test_log_metrics_uses_millisecond_timestamp_resolution_fluent():
    with start_run() as active_run, mock.patch("time.time") as time_mock:
        time_mock.side_effect = lambda: 123
        mlflow.log_metrics({
            "name_1": 25,
            "name_2": -3,
        })
        mlflow.log_metrics({
            "name_1": 30,
        })
        mlflow.log_metrics({
            "name_1": 40,
        })
        run_id = active_run.info.run_id

    client = tracking.MlflowClient()
    metric_history_name1 = client.get_metric_history(run_id, "name_1")
    assert set([(m.value, m.timestamp) for m in metric_history_name1]) == set([
        (25, 123 * 1000),
        (30, 123 * 1000),
        (40, 123 * 1000),
    ])
    metric_history_name2 = client.get_metric_history(run_id, "name_2")
    assert set([(m.value, m.timestamp) for m in metric_history_name2]) == set([
        (-3, 123 * 1000),
    ]) 
开发者ID:mlflow,项目名称:mlflow,代码行数:28,代码来源:test_tracking.py

示例9: mlflow_callback

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metrics [as 别名]
def mlflow_callback(study, trial):
    trial_value = trial.value if trial.value is not None else float("nan")
    with mlflow.start_run(run_name=study.study_name):
        mlflow.log_params(trial.params)
        mlflow.log_metrics({"mean_squared_error": trial_value}) 
开发者ID:optuna,项目名称:optuna,代码行数:7,代码来源:keras_mlflow.py


注:本文中的mlflow.log_metrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。