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


Python mlflow.create_experiment方法代码示例

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


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

示例1: _retrieve_mlflow_experiment_id

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def _retrieve_mlflow_experiment_id(name, create=False):
        experiment_id = None
        if name:
            existing_experiment = MlflowClient().get_experiment_by_name(name)
            if existing_experiment:
                experiment_id = existing_experiment.experiment_id
            else:
                if create:
                    experiment_id = mlflow.create_experiment(name)
                else:
                    raise Exception(
                        'Experiment "{}" not found in {}'.format(
                            name, mlflow.get_tracking_uri()
                        )
                    )
        return experiment_id 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:18,代码来源:loggers.py

示例2: test_model_log

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_model_log():
    with TempDir(chdr=True) as tmp:
        experiment_id = mlflow.create_experiment("test")
        sig = ModelSignature(inputs=Schema([ColSpec("integer", "x"), ColSpec("integer", "y")]),
                             outputs=Schema([ColSpec(name=None, type="double")]))
        input_example = {"x": 1, "y": 2}
        with mlflow.start_run(experiment_id=experiment_id) as r:
            Model.log("some/path", TestFlavor,
                      signature=sig,
                      input_example=input_example)

        local_path = _download_artifact_from_uri("runs:/{}/some/path".format(r.info.run_id),
                                                 output_path=tmp.path(""))
        loaded_model = Model.load(os.path.join(local_path, "MLmodel"))
        assert loaded_model.run_id == r.info.run_id
        assert loaded_model.artifact_path == "some/path"
        assert loaded_model.flavors == {
            "flavor1": {"a": 1, "b": 2},
            "flavor2": {"x": 1, "y": 2},
        }
        assert loaded_model.signature == sig
        path = os.path.join(local_path, loaded_model.saved_input_example_info["artifact_path"])
        x = _dataframe_from_json(path)
        assert x.to_dict(orient="records")[0] == input_example 
开发者ID:mlflow,项目名称:mlflow,代码行数:26,代码来源:test_model.py

示例3: test_set_experiment

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_set_experiment():
    with pytest.raises(TypeError):
        mlflow.set_experiment()  # pylint: disable=no-value-for-parameter

    with pytest.raises(Exception):
        mlflow.set_experiment(None)

    with pytest.raises(Exception):
        mlflow.set_experiment("")

    name = "random_exp"
    exp_id = mlflow.create_experiment(name)
    mlflow.set_experiment(name)
    with start_run() as run:
        assert run.info.experiment_id == exp_id

    another_name = "another_experiment"
    mlflow.set_experiment(another_name)
    exp_id2 = mlflow.tracking.MlflowClient().get_experiment_by_name(another_name)
    with start_run() as another_run:
        assert another_run.info.experiment_id == exp_id2.experiment_id 
开发者ID:mlflow,项目名称:mlflow,代码行数:23,代码来源:test_tracking.py

示例4: configure

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def configure(
        self,
        run_uuid,
        experiment_name,
        tracking_uri,
        run_name=None,
        always_log_artifacts=False,
        create_run=True,
        create_experiment=True,
        nest_run=True,
    ):
        if mlflow.active_run() and not nest_run:
            logger.info('Ending previous MLFlow run: {}.'.format(self.run_uuid))
            mlflow.end_run()

        self.always_log_artifacts = always_log_artifacts
        self._experiment_name = experiment_name
        self._run_name = run_name

        # MLflow specific
        if tracking_uri:
            mlflow.set_tracking_uri(tracking_uri)

        if run_uuid:
            existing_run = MlflowClient().get_run(run_uuid)
            if not existing_run and not create_run:
                raise FileNotFoundError(
                    'Run ID {} not found under {}'.format(
                        run_uuid, mlflow.get_tracking_uri()
                    )
                )

        experiment_id = self._retrieve_mlflow_experiment_id(
            experiment_name, create=create_experiment
        )
        return mlflow.start_run(
            run_uuid,
            experiment_id=experiment_id,
            run_name=run_name,
            nested=nest_run,
        ) 
开发者ID:Unbabel,项目名称:OpenKiwi,代码行数:43,代码来源:loggers.py

示例5: test_fetch_create_and_log

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_fetch_create_and_log(tmpdir):
    entry_point_name = "entry_point"
    parameters = {
        "method_name": "string",
    }
    entry_point = _project_spec.EntryPoint(entry_point_name, parameters, "run_model.sh")
    mock_fetched_project = _project_spec.Project(None,
                                                 {entry_point_name: entry_point},
                                                 None, "my_project")
    experiment_id = mlflow.create_experiment("test_fetch_project")
    expected_dir = tmpdir
    project_uri = "http://someuri/myproject.git"
    user_param = {"method_name": "newton"}
    with mock.patch("mlflow.projects.utils._fetch_project", return_value=expected_dir):
        with mock.patch("mlflow.projects._project_spec.load_project",
                        return_value=mock_fetched_project):
            work_dir = fetch_and_validate_project(
                "", "", entry_point_name, user_param)
            project = load_project(work_dir)
            assert mock_fetched_project == project
            assert expected_dir == work_dir
            # Create a run
            active_run = get_or_create_run(
                run_id=None, uri=project_uri, experiment_id=experiment_id, work_dir=work_dir,
                version=None, entry_point=entry_point_name, parameters=user_param)

            # check tags
            run = mlflow.get_run(active_run.info.run_id)
            assert MLFLOW_PROJECT_ENTRY_POINT in run.data.tags
            assert MLFLOW_SOURCE_NAME in run.data.tags
            assert entry_point_name == run.data.tags[MLFLOW_PROJECT_ENTRY_POINT]
            assert project_uri == run.data.tags[MLFLOW_SOURCE_NAME]
            assert user_param == run.data.params 
开发者ID:mlflow,项目名称:mlflow,代码行数:35,代码来源:test_utils.py

示例6: test_create_experiment

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_create_experiment():
    with pytest.raises(TypeError):
        mlflow.create_experiment()  # pylint: disable=no-value-for-parameter

    with pytest.raises(Exception):
        mlflow.create_experiment(None)

    with pytest.raises(Exception):
        mlflow.create_experiment("")

    exp_id = mlflow.create_experiment(
        "Some random experiment name %d" % random.randint(1, 1e6))
    assert exp_id is not None 
开发者ID:mlflow,项目名称:mlflow,代码行数:15,代码来源:test_tracking.py

示例7: test_create_experiment_with_duplicate_name

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_create_experiment_with_duplicate_name():
    name = "popular_name"
    exp_id = mlflow.create_experiment(name)

    with pytest.raises(MlflowException):
        mlflow.create_experiment(name)

    tracking.MlflowClient().delete_experiment(exp_id)
    with pytest.raises(MlflowException):
        mlflow.create_experiment(name) 
开发者ID:mlflow,项目名称:mlflow,代码行数:12,代码来源:test_tracking.py

示例8: test_create_experiments_with_bad_names

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_create_experiments_with_bad_names():
    # None for name
    with pytest.raises(MlflowException) as e:
        mlflow.create_experiment(None)
        assert e.message.contains("Invalid experiment name: 'None'")

    # empty string name
    with pytest.raises(MlflowException) as e:
        mlflow.create_experiment("")
        assert e.message.contains("Invalid experiment name: ''") 
开发者ID:mlflow,项目名称:mlflow,代码行数:12,代码来源:test_tracking.py

示例9: test_list_experiments

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_list_experiments():
    def _assert_exps(ids_to_lifecycle_stage, view_type_arg):
        result = set([(exp.experiment_id, exp.lifecycle_stage)
                      for exp in client.list_experiments(view_type=view_type_arg)])
        assert result == set([(exp_id, stage) for exp_id, stage in ids_to_lifecycle_stage.items()])
    experiment_id = mlflow.create_experiment("exp_1")
    assert experiment_id == '1'
    client = tracking.MlflowClient()
    _assert_exps({'0': LifecycleStage.ACTIVE, '1': LifecycleStage.ACTIVE}, ViewType.ACTIVE_ONLY)
    _assert_exps({'0': LifecycleStage.ACTIVE, '1': LifecycleStage.ACTIVE}, ViewType.ALL)
    _assert_exps({}, ViewType.DELETED_ONLY)
    client.delete_experiment(experiment_id)
    _assert_exps({'0': LifecycleStage.ACTIVE}, ViewType.ACTIVE_ONLY)
    _assert_exps({'0': LifecycleStage.ACTIVE, '1': LifecycleStage.DELETED}, ViewType.ALL)
    _assert_exps({'1': LifecycleStage.DELETED}, ViewType.DELETED_ONLY) 
开发者ID:mlflow,项目名称:mlflow,代码行数:17,代码来源:test_tracking.py

示例10: test_set_experiment_with_zero_id

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_set_experiment_with_zero_id(reset_mock):
    reset_mock(MlflowClient, "get_experiment_by_name",
               mock.Mock(return_value=attrdict.AttrDict(
                   experiment_id=0,
                   lifecycle_stage=LifecycleStage.ACTIVE)))
    reset_mock(MlflowClient, "create_experiment", mock.Mock())

    mlflow.set_experiment("my_exp")

    MlflowClient.get_experiment_by_name.assert_called_once()
    MlflowClient.create_experiment.assert_not_called() 
开发者ID:mlflow,项目名称:mlflow,代码行数:13,代码来源:test_tracking.py

示例11: test_get_artifact_uri_appends_to_uri_path_component_correctly

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_get_artifact_uri_appends_to_uri_path_component_correctly(
        artifact_location, expected_uri_format):
    client = MlflowClient()
    client.create_experiment("get-artifact-uri-test", artifact_location=artifact_location)
    mlflow.set_experiment("get-artifact-uri-test")
    with mlflow.start_run():
        run_id = mlflow.active_run().info.run_id
        for artifact_path in ["path/to/artifact", "/artifact/path", "arty.txt"]:
            artifact_uri = mlflow.get_artifact_uri(artifact_path)
            assert artifact_uri == tracking.artifact_utils.get_artifact_uri(run_id, artifact_path)
            assert artifact_uri == expected_uri_format.format(
                run_id=run_id, path=artifact_path.lstrip("/")) 
开发者ID:mlflow,项目名称:mlflow,代码行数:14,代码来源:test_tracking.py

示例12: test_search_runs_multiple_experiments

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_search_runs_multiple_experiments():
    experiment_ids = [mlflow.create_experiment("exp__{}".format(exp_id)) for exp_id in range(1, 4)]
    for eid in experiment_ids:
        with mlflow.start_run(experiment_id=eid):
            mlflow.log_metric("m0", 1)
            mlflow.log_metric("m_{}".format(eid), 2)

    assert len(MlflowClient().search_runs(experiment_ids, "metrics.m0 > 0", ViewType.ALL)) == 3

    assert len(MlflowClient().search_runs(experiment_ids, "metrics.m_1 > 0", ViewType.ALL)) == 1
    assert len(MlflowClient().search_runs(experiment_ids, "metrics.m_2 = 2", ViewType.ALL)) == 1
    assert len(MlflowClient().search_runs(experiment_ids, "metrics.m_3 < 4", ViewType.ALL)) == 1 
开发者ID:mlflow,项目名称:mlflow,代码行数:14,代码来源:test_tracking.py

示例13: test_get_experiment_id_with_active_experiment_returns_active_experiment_id

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_get_experiment_id_with_active_experiment_returns_active_experiment_id():
    # Create a new experiment and set that as active experiment
    with TempDir(chdr=True):
        name = "Random experiment %d" % random.randint(1, 1e6)
        exp_id = mlflow.create_experiment(name)
        assert exp_id is not None
        mlflow.set_experiment(name)
        assert _get_experiment_id() == exp_id 
开发者ID:mlflow,项目名称:mlflow,代码行数:10,代码来源:test_fluent.py

示例14: test_get_experiment_id_in_databricks_with_active_experiment_returns_active_experiment_id

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_get_experiment_id_in_databricks_with_active_experiment_returns_active_experiment_id():
    with TempDir(chdr=True):
        exp_name = "random experiment %d" % random.randint(1, 1e6)
        exp_id = mlflow.create_experiment(exp_name)
        mlflow.set_experiment(exp_name)
        notebook_id = str(int(exp_id) + 73)

    with mock.patch("mlflow.tracking.fluent.is_in_databricks_notebook") as notebook_detection_mock,\
            mock.patch("mlflow.tracking.fluent.get_notebook_id") as notebook_id_mock:
        notebook_detection_mock.return_value = True
        notebook_id_mock.return_value = notebook_id

        assert _get_experiment_id() != notebook_id
        assert _get_experiment_id() == exp_id 
开发者ID:mlflow,项目名称:mlflow,代码行数:16,代码来源:test_fluent.py

示例15: test_get_experiment_id_in_databricks_with_experiment_defined_in_env_returns_env_experiment_id

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import create_experiment [as 别名]
def test_get_experiment_id_in_databricks_with_experiment_defined_in_env_returns_env_experiment_id():
    with TempDir(chdr=True):
        exp_name = "random experiment %d" % random.randint(1, 1e6)
        exp_id = mlflow.create_experiment(exp_name)
        notebook_id = str(int(exp_id) + 73)
        HelperEnv.set_values(experiment_id=exp_id)

    with mock.patch("mlflow.tracking.fluent.is_in_databricks_notebook") as notebook_detection_mock,\
            mock.patch("mlflow.tracking.fluent.get_notebook_id") as notebook_id_mock:
        notebook_detection_mock.side_effect = lambda *args, **kwargs: True
        notebook_id_mock.side_effect = lambda *args, **kwargs: notebook_id

        assert _get_experiment_id() != notebook_id
        assert _get_experiment_id() == exp_id 
开发者ID:mlflow,项目名称:mlflow,代码行数:16,代码来源:test_fluent.py


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