简体   繁体   English

降维后在子空间中绘制新点

[英]Plotting new points in a subspace after dimensionality reduction

I would like to plot points with 100 parameters each with values between 0-99 on a 2 dimensional plot.我想在二维图上绘制具有 100 个参数的点,每个参数的值在 0-99 之间。 This should be straightforward with normal methods of dimensionality reduction (PCA/tSNE/UMAP etc) but I need to be able to add subsequent points to the plot without it needing to recalculate and therefore change使用常规的降维方法(PCA/tSNE/UMAP 等),这应该很简单,但我需要能够将后续点添加到绘图中,而无需重新计算并因此更改

I am picturing an algorithm that takes a data-point with it's 100 values and converts it to X,Y coordinates that can then be plotted.我正在描绘一种算法,它采用 100 个值的数据点并将其转换为可以绘制的 X、Y 坐标。 Points proximal in the 2D projection are proximal in the original 100D space. 2D 投影中的邻近点在原始 100D 空间中是邻近的。 Does such an algorithm exist?这样的算法存在吗? If not, any alternative approaches?如果没有,还有其他方法吗?

Thanks谢谢

I am not sure I understood the question correctly but with an initial set X , we can fit a PCA to compute the principal components.我不确定我是否正确理解了这个问题,但是使用初始集合X ,我们可以拟合 PCA 来计算主成分。 Then, we can use these principal components to transform new samples.然后,我们可以使用这些主成分来转换新的样本。

from sklearn.decomposition import PCA
import numpy as np
import matplotlib.pyplot as plt

n_samples, n_feats = 50, 100
X = np.random.randint(0, 99, size=n_samples * n_feats).reshape(n_samples, n_feats)

pca = PCA(n_components=2).fit(X)
X_reduced = pca.transform(X)

plt.scatter(X[:, 0], X[:, 1])

This plots,这个情节,

X 的绘图

Then, when a new sample comes in然后,当一个新样本进来时

new_sample = np.random.randint(0, 99, size=100).reshape(1, 100)
new_sample_reduced = pca.transform(new_sample)
plt.scatter(new_sample_reduced[:, 0], new_sample_reduced[:, 1], color="red")

We can plot it我们可以绘制它

绘制新样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM