mojolearn.LabelPropagation#

class mojolearn.LabelPropagation(kernel='rbf', *, gamma=20, n_neighbors=7, max_iter=1000, tol=0.001, n_jobs=None)[source]#

Bases: _LabelPropagationBase

Semi-supervised classification by label propagation.

Spreads the known labels over a similarity graph of all samples, keeping the labeled samples fixed (hard clamping), following scikit-learn’s LabelPropagation. Mark unlabeled samples with -1 in y. The graph is a dense RBF affinity matrix or a k-nearest-neighbor connectivity graph (each sample is its own first neighbor; distance ties go to the lower index). Iteration stops when the summed absolute change of the label distributions falls below tol or after max_iter steps. Computation is float32 (scikit-learn uses float64).

Parameters:
  • kernel ({‘rbf’, ‘knn’}, default ‘rbf’) – Graph kernel. Other values, including callables, raise NotImplementedError.

  • gamma (float, default 20) – Coefficient of the 'rbf' kernel.

  • n_neighbors (int, default 7) – Number of neighbors of the 'knn' kernel.

  • max_iter (int, default 1000) – Maximum number of iterations.

  • tol (float, default 1e-3) – Convergence tolerance.

  • n_jobs (int or None, default None) – Accepted for scikit-learn compatibility; unused.

  • numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode for this estimator ('fast' is Apple only). None uses the process default.

Variables:
  • X_ (Array of shape (n_samples, n_features)) – Training data.

  • classes_ (list) – Class labels (without the -1 marker).

  • label_distributions_ (Array of shape (n_samples, n_classes)) – Label distribution of each training sample.

  • transduction_ (Array or list of shape (n_samples,)) – Label assigned to each training sample.

  • n_iter_ (int) – Number of iterations run.

  • n_features_in_ (int) – Number of features seen in fit.

Examples

>>> import numpy as np, mojolearn
>>> rng = np.random.default_rng(0)
>>> X = rng.random((1000, 8), dtype=np.float32)
>>> y = (X[:, 0] > 0.5).astype(np.int64)
>>> y[100:] = -1
>>> model = mojolearn.LabelPropagation(kernel="knn").fit(X, y)
>>> labels = model.transduction_
__init__(kernel='rbf', *, gamma=20, n_neighbors=7, max_iter=1000, tol=0.001, n_jobs=None)[source]#

Methods

fit(X, y)

Fit the model and propagate labels to the unlabeled samples.

get_params([deep])

numeric_mode_used()

The numeric mode this estimator runs in.

predict(X)

Predict the class of new samples.

predict_proba(X)

Class probabilities of new samples from the fitted label distributions.

score(X, y[, sample_weight])

Mean accuracy of predict() on the given data.

set_params(**params)

Set constructor parameters.

vendor_used()

The GPU backend this estimator runs on.