def visualize_data(data, labels):
pca = RandomizedPCA(n_components=2)
reshaped = pca.fit_transform(data)
df = pd.DataFrame({'x': reshaped[:,0], 'y': reshaped[:, 1],
'label': np.where(labels == 1, 'Positive',
np.where(labels == 0, 'Neutral',
'Negative'))})
colors = ['yellow', 'red', 'blue']
for label, color in zip(df['label'].unique(), colors):
mask = df['label'] == label
plt.scatter(df[mask]['x'], df[mask]['y'], c=color, label=label)
plt.legend()
plt.title('PCA Decomposition of Image Data')
plt.xlabel('PCA 1')
plt.ylabel('PCA 2')
plt.show()
# plt.savefig('PCA_plot.png')
评论列表
文章目录