Input/Output
Comparison of two embeddings.
Description
Quantification of local similarity across two maps or embeddings, such as PCA and t-SNE. To compare the embedding of samples in two different maps using a scale dependent similarity measure. For a pair of maps X and Y, we compare the sets of the, respectively, kx and ky nearest neighbours of each sample.
- param mapX:
Mapping of first embedding.
- type mapX:
numpy array
- param data2:
Mapping of second embedding.
- type data2:
numpy array
- param nn:
number of neirest neighbor to compare between the two maps. This can be set based on the smalles class size or the aveage class size. The default is 250.
- type nn:
integer, optional
- param n_steps:
The number of evaluation steps until reaching nn, optional. If higher, the resolution becomes lower and vice versa. The default is 5.
- type n_steps:
integer
- param verbose:
print messages. The default is 3.
- type verbose:
integer, optional
- returns:
scores : array with the scores across various nearest neighbors (nn).
nn : nearest neighbors
n_steps : The number of evaluation steps until reaching nn.
- rtype:
dict()
Examples
>>> # Load data
>>> X, y = KNRscore.import_example()
>>>
>>> # Compute embeddings
>>> embed_pca = decomposition.TruncatedSVD(n_components=50).fit_transform(X)
>>> embed_tsne = manifold.TSNE(n_components=2, init='pca').fit_transform(X)
>>>
>>> # Compare PCA vs. tSNE
>>> scores = KNRscore.compare(embed_pca, embed_tsne, n_steps=10)
>>>
>>> # plot PCA vs. tSNE
>>> fig, ax = knrs.scatter(embed_tsne[:, 0], embed_tsne[:, 1], labels=y, cmap='Set1', title='tSNE Scatter Plot')
>>> fig, ax = knrs.scatter(embed_pca[:, 0], embed_pca[:, 1], labels=y, cmap='Set1', title='PCA Scatter Plot')
>>>
References
Plot
Make plot.
- param out:
output of the compare() function.
- type out:
dict
- param cmap:
colormap. The default is ‘jet’.
- type cmap:
string, optional
- param xlabel:
Label for x-axis. The default is None.
- type xlabel:
str, optional
- param ylabel:
Label for y-axis. The default is None.
- type ylabel:
str, optional
- param reverse_cmap:
Reverse the colormap. The default is False.
- type reverse_cmap:
bool, optional
- returns:
Figure and axes objects.
- rtype:
fig, ax
Examples
>>> # Load data
>>> X, y = KNRscore.import_example()
>>>
>>> # Compute embeddings
>>> embed_pca = decomposition.TruncatedSVD(n_components=50).fit_transform(X)
>>> embed_tsne = manifold.TSNE(n_components=2, init='pca').fit_transform(X)
>>>
>>> # Create comparison scores
>>> scores = KNRscore.compare(embed_pca, embed_tsne)
>>>
>>> # Create plot with custom labels
>>> fig, ax = KNRscore.plot(scores, cmap='viridis', xlabel='PCA', ylabel='tSNE')
>>>
>>> # Create plot with reversed colormap
>>> fig, ax = KNRscore.plot(scores, cmap='viridis', reverse_cmap=True)
>>>