Exemplo n.º 1
0
 def test_not_sklearn(self, model):
     msg_match = (
         r"^model must be a scikit-learn estimator with a predict\(\) method.*"
     )
     with pytest.raises(TypeError, match=msg_match):
         model_validator.must_sklearn(model)
Exemplo n.º 2
0
    def create_standard_model_from_sklearn(
        self,
        obj,
        environment,
        model_api=None,
        name=None,
        desc=None,
        labels=None,
        attrs=None,
        lock_level=None,
    ):
        """Create a Standard Verta Model version from a scikit-learn model.

        .. versionadded:: 0.18.2

        Parameters
        ----------
        obj : `sklearn.base.BaseEstimator <https://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html>`__
            scikit-learn model.
        environment : :class:`~verta.environment.Python`
            pip and apt dependencies.
        model_api : :class:`~verta.utils.ModelAPI`, optional
            Model API specifying the model's expected input and output
        name : str, optional
            Name of the model version. If no name is provided, one will be
            generated.
        desc : str, optional
            Description of the model version.
        labels : list of str, optional
            Labels of the model version.
        attrs : dict of str to {None, bool, float, int, str}, optional
            Attributes of the model version.
        lock_level : :mod:`~verta.registry.lock`, default :class:`~verta.registry.lock.Open`
            Lock level to set when creating this model version.

        Returns
        -------
        :class:`~verta.registry.entities.RegisteredModelVersion`

        Examples
        --------
        .. code-block:: python

            from sklearn.svm import LinearSVC
            from verta.environment import Python

            model = LinearSVC(**hyperparams)
            model.fit(X_train, y_train)

            model_ver = reg_model.create_standard_model_from_sklearn(
                model,
                Python(["scikit-learn"]),
            )
            endpoint.update(model_ver, wait=True)
            endpoint.get_deployed_model().predict(input)

        """
        model_validator.must_sklearn(obj)

        return self._create_standard_model_from_spec(
            model=obj,
            environment=environment,
            model_api=model_api,
            name=name,
            desc=desc,
            labels=labels,
            attrs=attrs,
            lock_level=lock_level,
        )
Exemplo n.º 3
0
 def test_sklearn(self, model):
     assert model_validator.must_sklearn(model)