def _check_is_fitted(self): """Check if the estimator is fitted. Raises: NotFittedError: If the estimator is not fitted. """ sklearn_check_is_fitted(self, ['estimator_'])
def predict(self, X): """Predict the class labels for the provided data. Args: X (:class:`FDataGrid`): FDataGrid with the test samples. Returns: (np.array): y : array of shape [n_samples] or [n_samples, n_outputs] with class labels for each data sample. """ sklearn_check_is_fitted(self, 'centroids_') return self.classes_[self._pairwise_distance( X, self.centroids_).argmin(axis=1)]
def predict(self, X): """Predict the class labels for the provided data. Args: X (:class:`FDataGrid`): FDataGrid with the test samples. Returns: y (np.array): array of shape [n_samples] with class labels for each data sample. """ sklearn_check_is_fitted(self) depths = [ distribution.predict(X) for distribution in self.distributions_ ] return self.classes_[np.argmax(depths, axis=0)]
def check_is_fitted(estimator, attributes, msg=None, all_or_any=all): """Checks whether the net is initialized. Note: This calls ``sklearn.utils.validation.check_is_fitted`` under the hood, using exactly the same arguments and logic. The only difference is that this function has an adapted error message and raises a ``skorch.exception.NotInitializedError`` instead of an ``sklearn.exceptions.NotFittedError``. """ if msg is None: msg = ("This %(name)s instance is not initialized yet. Call " "'initialize' or 'fit' with appropriate arguments " "before using this method.") try: sklearn_check_is_fitted( estimator=estimator, attributes=attributes, msg=msg, all_or_any=all_or_any, ) except NotFittedError as e: raise NotInitializedError(str(e))