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


Python mlflow.sklearn方法代码示例

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


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

示例1: fit

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def fit(self):
        """
        Gets data and preprocess by prepare_data() function
        Trains with the selected parameters from grid search and saves the model
        """
        data = self.get_input()
        df_train, df_test = self.prepare_data(data)
        xtr, ytr = df_train.drop(['Value'], axis=1), df_train['Value'].values

        xgbtrain = xgb.DMatrix(xtr, ytr)
        reg_cv = self.grid_search(xtr, ytr)
        param = reg_cv.best_params_
        bst = xgb.train(dtrain=xgbtrain, params=param)

        # save model to file
        mlflow.sklearn.save_model(bst, "model")
        return df_test 
开发者ID:produvia,项目名称:ai-platform,代码行数:19,代码来源:runner.py

示例2: predict

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [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

示例3: get_default_conda_env

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def get_default_conda_env(include_cloudpickle=False):
    """
    :return: The default Conda environment for MLflow Models produced by calls to
             :func:`save_model()` and :func:`log_model()`.
    """
    import sklearn
    pip_deps = None
    if include_cloudpickle:
        import cloudpickle
        pip_deps = ["cloudpickle=={}".format(cloudpickle.__version__)]
    return _mlflow_conda_env(
        additional_conda_deps=[
            "scikit-learn={}".format(sklearn.__version__),
        ],
        additional_pip_deps=pip_deps,
        additional_conda_channels=None
    ) 
开发者ID:mlflow,项目名称:mlflow,代码行数:19,代码来源:sklearn.py

示例4: _save_model

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def _save_model(sk_model, output_path, serialization_format):
    """
    :param sk_model: The scikit-learn model to serialize.
    :param output_path: The file path to which to write the serialized model.
    :param serialization_format: The format in which to serialize the model. This should be one of
                                 the following: ``mlflow.sklearn.SERIALIZATION_FORMAT_PICKLE`` or
                                 ``mlflow.sklearn.SERIALIZATION_FORMAT_CLOUDPICKLE``.
    """
    with open(output_path, "wb") as out:
        if serialization_format == SERIALIZATION_FORMAT_PICKLE:
            pickle.dump(sk_model, out)
        elif serialization_format == SERIALIZATION_FORMAT_CLOUDPICKLE:
            import cloudpickle
            cloudpickle.dump(sk_model, out)
        else:
            raise MlflowException(
                    message="Unrecognized serialization format: {serialization_format}".format(
                        serialization_format=serialization_format),
                    error_code=INTERNAL_ERROR) 
开发者ID:mlflow,项目名称:mlflow,代码行数:21,代码来源:sklearn.py

示例5: test_build_image_registers_model_and_creates_image_with_specified_names

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_build_image_registers_model_and_creates_image_with_specified_names(
        sklearn_model, model_path):
    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        workspace = get_azure_workspace()
        model_name = "MODEL_NAME_1"
        image_name = "IMAGE_NAME_1"
        mlflow.azureml.build_image(
            model_uri=model_path, workspace=workspace, model_name=model_name,
            image_name=image_name)

        register_model_call_args = aml_mocks["register_model"].call_args_list
        assert len(register_model_call_args) == 1
        _, register_model_call_kwargs = register_model_call_args[0]
        assert register_model_call_kwargs["model_name"] == model_name

        create_image_call_args = aml_mocks["create_image"].call_args_list
        assert len(create_image_call_args) == 1
        _, create_image_call_kwargs = create_image_call_args[0]
        assert create_image_call_kwargs["name"] == image_name 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_image_creation.py

示例6: test_build_image_generates_model_and_image_names_meeting_azureml_resource_naming_requirements

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_build_image_generates_model_and_image_names_meeting_azureml_resource_naming_requirements(
        sklearn_model, model_path):
    aml_resource_name_max_length = 32

    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        workspace = get_azure_workspace()
        mlflow.azureml.build_image(model_uri=model_path, workspace=workspace)

        register_model_call_args = aml_mocks["register_model"].call_args_list
        assert len(register_model_call_args) == 1
        _, register_model_call_kwargs = register_model_call_args[0]
        called_model_name = register_model_call_kwargs["model_name"]
        assert len(called_model_name) <= aml_resource_name_max_length

        create_image_call_args = aml_mocks["create_image"].call_args_list
        assert len(create_image_call_args) == 1
        _, create_image_call_kwargs = create_image_call_args[0]
        called_image_name = create_image_call_kwargs["name"]
        assert len(called_image_name) <= aml_resource_name_max_length 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_image_creation.py

示例7: test_build_image_includes_user_specified_tags_in_azure_image_and_model_tags

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_build_image_includes_user_specified_tags_in_azure_image_and_model_tags(
        sklearn_model, model_path):
    custom_tags = {
        "User": "Corey",
        "Date": "Today",
        "Other": "Entry",
    }

    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        workspace = get_azure_workspace()
        mlflow.azureml.build_image(model_uri=model_path, workspace=workspace, tags=custom_tags)

        register_model_call_args = aml_mocks["register_model"].call_args_list
        assert len(register_model_call_args) == 1
        _, register_model_call_kwargs = register_model_call_args[0]
        called_tags = register_model_call_kwargs["tags"]
        assert custom_tags.items() <= called_tags.items()

        create_image_call_args = aml_mocks["create_image"].call_args_list
        assert len(create_image_call_args) == 1
        _, create_image_call_kwargs = create_image_call_args[0]
        image_config = create_image_call_kwargs["image_config"]
        assert custom_tags.items() <= image_config.tags.items() 
开发者ID:mlflow,项目名称:mlflow,代码行数:26,代码来源:test_image_creation.py

示例8: test_build_image_includes_user_specified_description_in_azure_image_and_model_tags

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_build_image_includes_user_specified_description_in_azure_image_and_model_tags(
        sklearn_model, model_path):
    custom_description = "a custom description"

    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        workspace = get_azure_workspace()
        mlflow.azureml.build_image(
            model_uri=model_path, workspace=workspace, description=custom_description)

        register_model_call_args = aml_mocks["register_model"].call_args_list
        assert len(register_model_call_args) == 1
        _, register_model_call_kwargs = register_model_call_args[0]
        assert register_model_call_kwargs["description"] == custom_description

        create_image_call_args = aml_mocks["create_image"].call_args_list
        assert len(create_image_call_args) == 1
        _, create_image_call_kwargs = create_image_call_args[0]
        image_config = create_image_call_kwargs["image_config"]
        assert image_config.description == custom_description 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_image_creation.py

示例9: test_cli_build_image_with_absolute_model_path_calls_expected_azure_routines

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_cli_build_image_with_absolute_model_path_calls_expected_azure_routines(
        sklearn_model, model_path):
    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        result = CliRunner(env={"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"}).invoke(
            mlflow.azureml.cli.commands,
            [
                'build-image',
                '-m', model_path,
                '-w', "test_workspace",
                '-i', "image_name",
                '-n', "model_name",
            ])
        assert result.exit_code == 0

        assert aml_mocks["register_model"].call_count == 1
        assert aml_mocks["create_image"].call_count == 1
        assert aml_mocks["load_workspace"].call_count == 1 
开发者ID:mlflow,项目名称:mlflow,代码行数:20,代码来源:test_image_creation.py

示例10: test_cli_build_image_with_relative_model_path_calls_expected_azure_routines

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_cli_build_image_with_relative_model_path_calls_expected_azure_routines(sklearn_model):
    with TempDir(chdr=True):
        model_path = "model"
        mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)

        with AzureMLMocks() as aml_mocks:
            result = CliRunner(env={"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"}).invoke(
                mlflow.azureml.cli.commands,
                [
                    'build-image',
                    '-m', model_path,
                    '-w', 'test_workspace',
                    '-i', 'image_name',
                    '-n', 'model_name',
                ])
            assert result.exit_code == 0

            assert aml_mocks["register_model"].call_count == 1
            assert aml_mocks["create_image"].call_count == 1
            assert aml_mocks["load_workspace"].call_count == 1 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_image_creation.py

示例11: test_cli_build_image_with_runs_uri_calls_expected_azure_routines

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_cli_build_image_with_runs_uri_calls_expected_azure_routines(sklearn_model):
    artifact_path = "model"
    with mlflow.start_run():
        mlflow.sklearn.log_model(sk_model=sklearn_model, artifact_path=artifact_path)
        run_id = mlflow.active_run().info.run_id
    model_uri = "runs:/{run_id}/{artifact_path}".format(
        run_id=run_id, artifact_path=artifact_path)

    with AzureMLMocks() as aml_mocks:
        result = CliRunner(env={"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"}).invoke(
            mlflow.azureml.cli.commands,
            [
                'build-image',
                '-m', model_uri,
                '-w', 'test_workspace',
                '-i', 'image_name',
                '-n', 'model_name',
            ])
        assert result.exit_code == 0

        assert aml_mocks["register_model"].call_count == 1
        assert aml_mocks["create_image"].call_count == 1
        assert aml_mocks["load_workspace"].call_count == 1 
开发者ID:mlflow,项目名称:mlflow,代码行数:25,代码来源:test_image_creation.py

示例12: test_cli_build_image_with_remote_uri_calls_expected_azure_routines

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_cli_build_image_with_remote_uri_calls_expected_azure_routines(
        sklearn_model, model_path, mock_s3_bucket):
    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    artifact_path = "model"
    artifact_root = "s3://{bucket_name}".format(bucket_name=mock_s3_bucket)
    s3_artifact_repo = S3ArtifactRepository(artifact_root)
    s3_artifact_repo.log_artifacts(model_path, artifact_path=artifact_path)
    model_uri = artifact_root + "/" + artifact_path

    with AzureMLMocks() as aml_mocks:
        result = CliRunner(env={"LC_ALL": "en_US.UTF-8", "LANG": "en_US.UTF-8"}).invoke(
            mlflow.azureml.cli.commands,
            [
                'build-image',
                '-m', model_uri,
                '-w', 'test_workspace',
                '-i', 'image_name',
                '-n', 'model_name',
            ])
        assert result.exit_code == 0

        assert aml_mocks["register_model"].call_count == 1
        assert aml_mocks["create_image"].call_count == 1
        assert aml_mocks["load_workspace"].call_count == 1 
开发者ID:mlflow,项目名称:mlflow,代码行数:26,代码来源:test_image_creation.py

示例13: test_deploy_registers_model_and_creates_service_with_specified_names

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_deploy_registers_model_and_creates_service_with_specified_names(
        sklearn_model, model_path):
    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        workspace = get_azure_workspace()
        model_name = "MODEL_NAME_1"
        service_name = "service_name_1"
        mlflow.azureml.deploy(
            model_uri=model_path, workspace=workspace, model_name=model_name,
            service_name=service_name)

        register_model_call_args = aml_mocks["register_model"].call_args_list
        assert len(register_model_call_args) == 1
        _, register_model_call_kwargs = register_model_call_args[0]
        assert register_model_call_kwargs["model_name"] == model_name

        model_deploy_call_args = aml_mocks["model_deploy"].call_args_list
        assert len(model_deploy_call_args) == 1
        _, model_deploy_call_kwargs = model_deploy_call_args[0]
        assert model_deploy_call_kwargs["name"] == service_name 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_deploy.py

示例14: test_deploy_generates_model_and_service_names_meeting_azureml_resource_naming_requirements

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_deploy_generates_model_and_service_names_meeting_azureml_resource_naming_requirements(
        sklearn_model, model_path):
    aml_resource_name_max_length = 32

    mlflow.sklearn.save_model(sk_model=sklearn_model, path=model_path)
    with AzureMLMocks() as aml_mocks:
        workspace = get_azure_workspace()
        mlflow.azureml.deploy(model_uri=model_path, workspace=workspace)

        register_model_call_args = aml_mocks["register_model"].call_args_list
        assert len(register_model_call_args) == 1
        _, register_model_call_kwargs = register_model_call_args[0]
        called_model_name = register_model_call_kwargs["model_name"]
        assert len(called_model_name) <= aml_resource_name_max_length

        model_deploy_call_args = aml_mocks["model_deploy"].call_args_list
        assert len(model_deploy_call_args) == 1
        _, model_deploy_call_kwargs = model_deploy_call_args[0]
        called_service_name = model_deploy_call_kwargs["name"]
        assert len(called_service_name) <= aml_resource_name_max_length 
开发者ID:mlflow,项目名称:mlflow,代码行数:22,代码来源:test_deploy.py

示例15: test_prepare_env_fails

# 需要导入模块: import mlflow [as 别名]
# 或者: from mlflow import sklearn [as 别名]
def test_prepare_env_fails(sk_model):
    if no_conda:
        pytest.skip("This test requires conda.")

    with TempDir(chdr=True):
        with mlflow.start_run() as active_run:
            mlflow.sklearn.log_model(sk_model, "model",
                                     conda_env={"dependencies": ["mlflow-does-not-exist-dep==abc"]})
            model_uri = "runs:/{run_id}/model".format(run_id=active_run.info.run_id)

        # Test with no conda
        p = subprocess.Popen(["mlflow", "models", "prepare-env", "-m", model_uri,
                              "--no-conda"])
        assert p.wait() == 0

        # With conda - should fail due to bad conda environment.
        p = subprocess.Popen(["mlflow", "models", "prepare-env", "-m", model_uri])
        assert p.wait() != 0 
开发者ID:mlflow,项目名称:mlflow,代码行数:20,代码来源:test_cli.py


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