def partial_fit(self, X, y=None): """Extend the model by X as additional training data. Parameters ---------- X : {array-like, sparse matrix} Training data. Shape = [n_samples, n_features] y : list, optional (default = None) List of classes for the given input of X. Size have to be n_samples.""" if y is not None: if self._y_is_csr: self._y = vstack([self._y, y]) else: self._y = np.concatenate((self._y, y), axis=0) X_csr = csr_matrix(X) instances, features = X_csr.nonzero() data = X_csr.data for i in xrange(len(instances)): instances[i] += self._index_elements_count self._index_elements_count += X.shape[0] self._pointer_address_of_nearestNeighbors_object = _nearestNeighbors.fit(instances.tolist(), features.tolist(), data.tolist(), self._pointer_address_of_nearestNeighbors_object)
def partial_fit(self, X, y=None): """Extend the model by X as additional training data. Parameters ---------- X : {array-like, sparse matrix} Training data. Shape = [n_samples, n_features] y : list, optional (default = None) List of classes for the given input of X. Size have to be n_samples.""" if y is not None: if self._y_is_csr: self._y = vstack([self._y, y]) else: self._y = np.concatenate((self._y, y), axis=0) X_csr = csr_matrix(X) instances, features = X_csr.nonzero() data = X_csr.data for i in xrange(len(instances)): instances[i] += self._index_elements_count self._index_elements_count += X.shape[0] self._pointer_address_of_nearestNeighbors_object = _nearestNeighbors.fit( instances.tolist(), features.tolist(), data.tolist(), self._pointer_address_of_nearestNeighbors_object)
def fit(self, X, y=None): """Fit the model using X as training data. Parameters ---------- X : {array-like, sparse matrix}, optional Training data. If array or matrix, shape = [n_samples, n_features] If X is None, a "lazy fitting" is performed. If kneighbors is called, the fitting with with the data there is done. Also the caching of computed hash values is deactivated in this case. y : list, optional (default = None) List of classes for the given input of X. Size have to be n_samples.""" if y is not None: self._y_is_csr = True _, self._y = check_X_y(X, y, "csr", multi_output=True) if self._y.ndim == 1 or self._y.shape[1] == 1: self._y_is_csr = False else: self._y_is_csr = False X_csr = csr_matrix(X) self._index_elements_count = X_csr.shape[0] instances, features = X_csr.nonzero() maxFeatures = int(max(X_csr.getnnz(1))) data = X_csr.data # returns a pointer to the inverse index stored in c++ self._pointer_address_of_nearestNeighbors_object = _nearestNeighbors.fit(instances.tolist(), features.tolist(), data.tolist(), X_csr.shape[0], maxFeatures, self._pointer_address_of_nearestNeighbors_object)
def fit(self, X, y=None): """Fit the model using X as training data. Parameters ---------- X : {array-like, sparse matrix}, optional Training data. If array or matrix, shape = [n_samples, n_features] If X is None, a "lazy fitting" is performed. If kneighbors is called, the fitting with with the data there is done. Also the caching of computed hash values is deactivated in this case. y : list, optional (default = None) List of classes for the given input of X. Size have to be n_samples.""" if y is not None: self._y_is_csr = True _, self._y = check_X_y(X, y, "csr", multi_output=True) if self._y.ndim == 1 or self._y.shape[1] == 1: self._y_is_csr = False else: self._y_is_csr = False X_csr = csr_matrix(X) self._index_elements_count = X_csr.shape[0] instances, features = X_csr.nonzero() maxFeatures = int(max(X_csr.getnnz(1))) data = X_csr.data # returns a pointer to the inverse index stored in c++ self._pointer_address_of_nearestNeighbors_object = _nearestNeighbors.fit( instances.tolist(), features.tolist(), data.tolist(), X_csr.shape[0], maxFeatures, self._pointer_address_of_nearestNeighbors_object)