extorch.utils.visual
¶
- extorch.utils.visual.tsne_fit(feature: numpy.ndarray, n_components: int = 2, init: str = 'pca', **kwargs)[source]¶
Fit input features into an embedded space and return that transformed output.
- Parameters
feature (np.ndarray) – The features to be embedded.
n_components (int) – Dimension of the embedded space. Default: 2.
init (str) – Initialization of embedding. Possible options are “random”, “pca”, and a numpy array of shape (n_samples, n_components). PCA initialization cannot be used with precomputed distances and is usually more globally stable than random initialization. Default: “pca”.
kwargs – Other configurations for TSNE model construction.
- Returns
The representation in the embedding space.
- Return type
node_pos (np.ndarray)
- Examples::
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> features = np.random.randn(50, 10) >>> labels = np.random.randint(0, 2, (50, 1)) >>> node_pos = tsne_fit(features, 2, "pca") >>> plt.figure() >>> plt.scatter(node_pos[:, 0], node_pos[:, 1], c = labels) >>> plt.show()