# -*- coding: utf-8 -*-
# Program Name: simple_word_pca_visualization.py
# Description: English sentence to dummy vectors and PCA 2D visualization
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
# --- Example English Sentence ---
sentence = "Learn data science with Python and apply machine learning to analyze Pokemon data"
# --- Tokenize Sentence ---
words = sentence.lower().split()
# --- Simulate Dummy Word Vectors (50-dimensional random vectors) ---
np.random.seed(42)
dummy_vectors = np.random.rand(len(words), 50)
# --- Dimensionality Reduction (PCA) to 2D ---
pca = PCA(n_components=2)
reduced_vectors = pca.fit_transform(dummy_vectors)
# --- 2D Plot ---
plt.figure(figsize=(8, 6))
plt.scatter(reduced_vectors[:, 0], reduced_vectors[:, 1], color='blue')
for i, word in enumerate(words):
plt.text(reduced_vectors[i, 0] + 0.01, reduced_vectors[i, 1] + 0.01, word, fontsize=9)
plt.title('2D PCA Projection of Dummy Word Vectors')
plt.xlabel('PCA Component 1')
plt.ylabel('PCA Component 2')
plt.show()