# sklearn¶

class openTSNE.sklearn.TSNE(n_components=2, perplexity=30, learning_rate=200, early_exaggeration_iter=250, early_exaggeration=12, n_iter=750, exaggeration=None, theta=0.5, n_interpolation_points=3, min_num_intervals=50, ints_in_interval=1, initialization='pca', metric='euclidean', metric_params=None, initial_momentum=0.5, final_momentum=0.8, min_grad_norm=1e-08, max_grad_norm=None, n_jobs=1, neighbors='approx', negative_gradient_method='fft', callbacks=None, callbacks_every_iters=50, random_state=None)[source]

t-Distributed Stochastic Neighbor Embedding.

Parameters: n_components (int) – The dimension of the embedding space. This deafults to 2 for easy visualization, but sometimes 1 is used for t-SNE heatmaps. t-SNE is not designed to embed into higher dimension and please note that acceleration schemes break down and are not fully implemented. perplexity (float) – Perplexity can be thought of as the continuous $$k$$ number of nearest neighbors, for which t-SNE will attempt to preserve distances. learning_rate (float) – The learning rate for t-SNE optimization. Typical values range between 100 to 1000. Setting the learning rate too low or too high may result in the points forming a “ball”. This is also known as the crowding problem. early_exaggeration_iter (int) – The number of iterations to run in the early exaggeration phase. early_exaggeration (float) – The exaggeration factor to use during the early exaggeration phase. Typical values range from 12 to 32. n_iter (int) – The number of iterations to run in the normal optimization regime. exaggeration (float) – The exaggeration factor to use during the normal optimization phase. This can be used to form more densely packed clusters and is useful for large data sets. theta (float) – Only used when negative_gradient_method="bh" or its other aliases. This is the trade-off parameter between speed and accuracy of the tree approximation method. Typical values range from 0.2 to 0.8. The value 0 indicates that no approximation is to be made and produces exact results also producing longer runtime. n_interpolation_points (int) – Only used when negative_gradient_method="fft" or its other aliases. The number of interpolation points to use within each grid cell for interpolation based t-SNE. It is highly recommended leaving this value at the default 3. min_num_intervals (int) – Only used when negative_gradient_method="fft" or its other aliases. The minimum number of grid cells to use, regardless of the ints_in_interval parameter. Higher values provide more accurate gradient estimations. ints_in_interval (float) – Only used when negative_gradient_method="fft" or its other aliases. Indicates how large a grid cell should be e.g. a value of 3 indicates a grid side length of 3. Lower values provide more accurate gradient estimations. initialization (Union[np.ndarray, str]) – The initial point positions to be used in the embedding space. Can be a precomputed numpy array, pca or random. Please note that when passing in a precomputed positions, it is highly recommended that the point positions have small variance (var(Y) < 0.0001), otherwise you may get poor embeddings. metric (Union[str, Callable]) – The metric to be used to compute affinities between points in the original space. metric_params (dict) – Additional keyword arguments for the metric function. initial_momentum (float) – The momentum to use during the early exaggeration phase. final_momentum (float) – The momentum to use during the normal optimization phase. min_grad_norm (float) – If the gradient norm is below this threshold, the optimization will be stopped. max_grad_norm (float) – Maximum gradient norm. If the norm exceeds this value, it will be clipped. This is most beneficial when adding points into an existing embedding and the new points overlap with the reference points, leading to large gradients. This can make points “shoot off” from the embedding, causing the interpolation method to compute a very large grid, and leads to worse results. n_jobs (int) – The number of threads to use while running t-SNE. This follows the scikit-learn convention, -1 meaning all processors, -2 meaning all but one, etc. neighbors (str) – Specifies the nearest neighbor method to use. Can be either exact or approx. negative_gradient_method (str) – Specifies the negative gradient approximation method to use. For smaller data sets, the Barnes-Hut approximation is appropriate and can be set using one of the following aliases: bh, BH or barnes-hut. For larger data sets, the FFT accelerated interpolation method is more appropriate and can be set using one of the following aliases: fft, FFT or ìnterpolation. callbacks (Union[Callable, List[Callable]]) – Callbacks, which will be run every callbacks_every_iters iterations. callbacks_every_iters (int) – How many iterations should pass between each time the callbacks are invoked. random_state (Union[int, RandomState]) – If the value is an int, random_state is the seed used by the random number generator. If the value is a RandomState instance, then it will be used as the random number generator. If the value is None, the random number generator is the RandomState instance used by np.random.
fit(X, y=None)[source]

Fit X into an embedded space.

Parameters: X (np.ndarray) – The data matrix to be embedded. y (ignored) –
fit_transform(X, y=None)[source]

Fit X into an embedded space and return that transformed output.

Parameters: X (np.ndarray) – The data matrix to be embedded. y (ignored) – Embedding of the training data in low-dimensional space. np.ndarray
transform(X, *args, **kwargs)[source]

Apply dimensionality reduction to X.

See openTSNE.TSNEEmbedding.transform() for additional parameters.

Parameters: X (np.ndarray) – The data matrix to be embedded. Embedding of the training data in low-dimensional space. np.ndarray