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


Python mlflow.log_metric方法代码示例

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


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

示例1: predict

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def predict(self, df_test):
        """
         Makes prediction for the next 7 days electricity consumption.
        """
        # load model from file
        loaded_model = mlflow.sklearn.load_model("model")
        # make predictions for test data
        xts, yts = df_test.drop(['Value'], axis=1), df_test['Value'].values
        p = loaded_model.predict(xgb.DMatrix(xts))
        prediction = pd.DataFrame({'Prediction': p})

        mape, rmse, mae, r2 = ForecastRunner.evaluation_metrics(yts, p)
        print('MAPE: {}'.format(mape))
        print('RMSE: {}'.format(rmse))
        print('R2: {}'.format(r2))
        print('MAE: {}'.format(mae))
        mlflow.log_metric("MAPE", mape)
        mlflow.log_metric("RMSE", rmse)
        mlflow.log_metric("R2", r2)
        mlflow.log_metric("MAE", mae)
        ForecastRunner.plot_result(yts, p)
        self.save_output(df_test, prediction) 
开发者ID:produvia,项目名称:ai-platform,代码行数:24,代码来源:runner.py

示例2: log_metric

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def log_metric(self, name: str, score: float):
        """
        Log a metric under the logging directory.

        Args:
            name:
                Metric name.
            score:
                Metric value.
        """
        name = _sanitize(name)
        score = _sanitize(score)
        self.metrics[name] = score

        if self.with_mlflow:
            import mlflow
            from mlflow.exceptions import MlflowException

            try:
                mlflow.log_metric(name, score)
            except MlflowException as e:
                warnings.warn('Error in logging metric {} to mlflow. Skipped. {}'.format(name, e)) 
开发者ID:nyanp,项目名称:nyaggle,代码行数:24,代码来源:experiment.py

示例3: test_ignore_errors_in_mlflow_params

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def test_ignore_errors_in_mlflow_params(tmpdir_name):
    mlflow.start_run()
    mlflow.log_param('features', 'ABC')
    mlflow.log_metric('Overall', -99)

    params = {
        'objective': 'binary',
        'max_depth': 8
    }
    X, y = make_classification_df()

    result = run_experiment(params, X, y, with_mlflow=True, logging_directory=tmpdir_name, feature_list=[])

    client = mlflow.tracking.MlflowClient()
    data = client.get_run(mlflow.active_run().info.run_id).data

    assert data.metrics['Overall'] == result.metrics[-1]
    assert data.params['features'] == 'ABC'  # params cannot be overwritten

    mlflow.end_run() 
开发者ID:nyanp,项目名称:nyaggle,代码行数:22,代码来源:test_run.py

示例4: on_epoch_end

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def on_epoch_end(self, epoch, logs=None):
        """
        Log Keras metrics with MLflow. Update the best model if the model improved on the validation
        data.
        """
        if not logs:
            return
        for name, value in logs.items():
            if name.startswith("val_"):
                name = "valid_" + name[4:]
            else:
                name = "train_" + name
            mlflow.log_metric(name, value)
        val_loss = logs["val_loss"]
        if val_loss < self._best_val_loss:
            # Save the "best" weights
            self._best_val_loss = val_loss
            self._best_weights = [x.copy() for x in self._model.get_weights()] 
开发者ID:PipelineAI,项目名称:models,代码行数:20,代码来源:pipeline_train.py

示例5: test_log_metrics_uses_millisecond_timestamp_resolution_client

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def test_log_metrics_uses_millisecond_timestamp_resolution_client():
    with start_run() as active_run, mock.patch("time.time") as time_mock:
        time_mock.side_effect = lambda: 123
        mlflow_client = tracking.MlflowClient()
        run_id = active_run.info.run_id

        mlflow_client.log_metric(run_id=run_id, key="name_1", value=25)
        mlflow_client.log_metric(run_id=run_id, key="name_2", value=-3)
        mlflow_client.log_metric(run_id=run_id, key="name_1", value=30)
        mlflow_client.log_metric(run_id=run_id, key="name_1", value=40)

    metric_history_name1 = mlflow_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 = mlflow_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,代码行数:23,代码来源:test_tracking.py

示例6: log_metric

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

示例7: log_scalar

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def log_scalar(name, value, step):
    """Log a scalar value to both MLflow and TensorBoard"""
    writer.add_scalar(name, value, step)
    mlflow.log_metric(name, value) 
开发者ID:produvia,项目名称:ai-platform,代码行数:6,代码来源:main.py

示例8: log_metric

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def log_metric(key, value):
        pass 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:4,代码来源:loggers.py

示例9: log_metrics

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def log_metrics(self, metrics: Dict):
        """
        Log a batch of metrics under the logging directory.

        Args:
            metrics: dictionary of metrics.
        """
        for k, v in metrics.items():
            self.log_metric(k, v) 
开发者ID:nyanp,项目名称:nyaggle,代码行数:11,代码来源:experiment.py

示例10: add_leaderboard_score

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def add_leaderboard_score(logging_directory: str, score: float):
    """
    Record leaderboard score to the existing experiment directory.

    Args:
        logging_directory:
            The directory to be added
        score:
            Leaderboard score
    """
    with Experiment.continue_from(logging_directory) as e:
        e.log_metric('LB', score) 
开发者ID:nyanp,项目名称:nyaggle,代码行数:14,代码来源:experiment.py

示例11: _update

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def _update(
        self,
        engine,                 # type: Engine
        attach_id,              # type: int
        prefix,                 # type: str
        update_period,          # type: int
        metric_names=None,      # type: List
        output_transform=None,  # type: Callable
        param_history=False     # type: bool
    ):
        step = self.metrics_step[attach_id]
        self.metrics_step[attach_id] += 1
        if step % update_period != 0:
            return

        #
        # Get all the metrics
        #
        metrics = []
        if metric_names is not None:
            if not all(metric in engine.state.metrics for metric in metric_names):
                raise KeyError("metrics not found in engine.state.metrics")

            metrics.extend([(name, engine.state.metrics[name]) for name in metric_names])

        if output_transform is not None:
            output_dict = output_transform(engine.state.output)

            if not isinstance(output_dict, dict):
                output_dict = {"output": output_dict}

            metrics.extend([(name, value) for name, value in output_dict.items()])

        if param_history:
            metrics.extend([(name, value[-1][0]) for name, value in engine.state.param_history.items()])

        if not metrics:
            return

        for metric_name, new_value in metrics:
            mlflow.log_metric(prefix + metric_name, new_value) 
开发者ID:leokarlin,项目名称:LaSO,代码行数:43,代码来源:mlflow_logger.py

示例12: _mlflow_log_metrics

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def _mlflow_log_metrics(metrics, metric_name):
    """Record metric value during each epoch using the step parameter in
    mlflow.log_metric.

    :param metrics:
    :param metric_name:
    :return:
    """
    for epoch, metric in enumerate(metrics[metric_name], 1): mlflow.log_metric(
        metric_name, metric,
        step=epoch) 
开发者ID:GoogleCloudPlatform,项目名称:ml-on-gcp,代码行数:13,代码来源:task.py

示例13: on_train_end

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def on_train_end(self, *args, **kwargs):
        """
        Log the best model with MLflow and evaluate it on the train and validation data so that the
        metrics stored with MLflow reflect the logged model.
        """
        self._model.set_weights(self._best_weights)
        x, y = self._train
        train_res = self._model.evaluate(x=x, y=y)
        for name, value in zip(self._model.metrics_names, train_res):
            mlflow.log_metric("train_{}".format(name), value)
        x, y = self._valid
        valid_res = self._model.evaluate(x=x, y=y)
        for name, value in zip(self._model.metrics_names, valid_res):
            mlflow.log_metric("valid_{}".format(name), value)
        log_model(keras_model=self._model, **self._pyfunc_params) 
开发者ID:PipelineAI,项目名称:models,代码行数:17,代码来源:pipeline_train.py

示例14: on_train_end

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def on_train_end(self, *args, **kwargs):
        """
        Log the best model with MLflow and evaluate it on the train and validation data so that the
        metrics stored with MLflow reflect the logged model.
        """
        self._model.set_weights(self._best_weights)
        x, y = self._train
        train_res = self._model.evaluate(x=x, y=y)
        for name, value in zip(self._model.metrics_names, train_res):
            mlflow.log_metric("train_{}".format(name), value)
        x, y = self._valid
        valid_res = self._model.evaluate(x=x, y=y)
        for name, value in zip(self._model.metrics_names, valid_res):
            mlflow.log_metric("valid_{}".format(name), value) 
开发者ID:PipelineAI,项目名称:models,代码行数:16,代码来源:pipeline_train.py

示例15: train_random_forest

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import log_metric [as 别名]
def train_random_forest(ntrees):
    with mlflow.start_run():
        rf = H2ORandomForestEstimator(ntrees=ntrees)
        train_cols = [n for n in wine.col_names if n != "quality"]
        rf.train(train_cols, "quality", training_frame=train, validation_frame=test)

        mlflow.log_param("ntrees", ntrees)

        mlflow.log_metric("rmse", rf.rmse())
        mlflow.log_metric("r2", rf.r2())
        mlflow.log_metric("mae", rf.mae())

        mlflow.h2o.log_model(rf, "model") 
开发者ID:mlflow,项目名称:mlflow,代码行数:15,代码来源:random_forest.py


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