def kneighbors(self, X=None, n_neighbors=None, return_distance=True): daal_model = getattr(self, '_daal_model', None) if X is not None: X = check_array(X, accept_sparse='csr', dtype=[np.float64, np.float32]) x = self._fit_X if X is None else X try: fptype = getFPType(x) except ValueError: fptype = None if daal_model is not None and fptype is not None and not sp.issparse( X): logging.info("sklearn.neighbors.KNeighborsMixin." "kneighbors: " + get_patch_message("daal")) result = daal4py_kneighbors(self, X, n_neighbors, return_distance) else: logging.info("sklearn.neighbors.KNeighborsMixin." "kneighbors:" + get_patch_message("sklearn")) if daal_model is not None or getattr(self, '_tree', 0) is None and \ self._fit_method == 'kd_tree': if sklearn_check_version("0.24"): BaseNeighborsBase._fit(self, self._fit_X, getattr(self, '_y', None)) else: BaseNeighborsBase._fit(self, self._fit_X) result = super(KNeighborsMixin, self).kneighbors(X, n_neighbors, return_distance) return result
def kneighbors(self, X=None, n_neighbors=None, return_distance=True): daal_model = getattr(self, '_daal_model', None) if X is not None and self.metric != "precomputed": X = check_array( X, accept_sparse='csr', dtype=[ np.float64, np.float32]) x = self._fit_X if X is None else X try: fptype = getFPType(x) except ValueError: fptype = None _patching_status = PatchingConditionsChain( "sklearn.neighbors.KNeighborsMixin.kneighbors") _dal_ready = _patching_status.and_conditions([ (daal_model is not None, "oneDAL model was not trained."), (fptype is not None, "Unable to get dtype."), (not sp.issparse(X), "X is sparse. Sparse input is not supported.")]) _patching_status.write_log() if _dal_ready: result = daal4py_kneighbors(self, X, n_neighbors, return_distance) else: if daal_model is not None or getattr(self, '_tree', 0) is None and \ self._fit_method == 'kd_tree': if sklearn_check_version("0.24"): BaseNeighborsBase._fit(self, self._fit_X, getattr(self, '_y', None)) else: BaseNeighborsBase._fit(self, self._fit_X) result = super(KNeighborsMixin, self).kneighbors( X, n_neighbors, return_distance) return result
def radius_neighbors(self, X=None, radius=None, return_distance=True, sort_results=False): daal_model = getattr(self, '_daal_model', None) if daal_model is not None \ or getattr(self, '_tree', 0) is None and self._fit_method == 'kd_tree': if sklearn_check_version("0.24"): BaseNeighborsBase._fit(self, self._fit_X, self._y) else: BaseNeighborsBase._fit(self, self._fit_X) if sklearn_check_version("0.22"): result = BaseRadiusNeighborsMixin.radius_neighbors(self, X, radius, return_distance, sort_results) else: result = BaseRadiusNeighborsMixin.radius_neighbors(self, X, radius, return_distance) return result