<jupyter_start><jupyter_text>Build PCA  Why do Dimensionality Reduction? 1 - Space Efficiency 2 - Computing Efficiency 3 - Visualization (so we can always analyze by human eye) Build PCA and compare it to T-SNE and LDA (3 DR methods total)<jupyter_code>import numpy as np
np.random.seed(1)
# Step 1 - Create our dataset

mu_vec1 = np.array([0, 0, 0]) # sample mean
cov_mat1 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # sample covariance


# 3 x 20 matrix 3 columns with 20 rows 
class1_sample = np.random.multivariate_normal(mu_vec1, cov_mat1, 20).T
print(class1_sample)
mu_vec2 = np.array([1, 1, 1]) # sample mean
cov_mat2 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # sample covariance


# 3 x 20 matrix 3 columns with 20 rows 
class2_sample = np.random.multivariate_normal(mu_vec2, cov_mat2, 20).T
print(class2_sample)
# Step 2 Plot the Data

%pylab inline

#plotting
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

#figure, width and height
fig = plt.figure(figsize=(8,8))
#3d subplot
#These are subplot grid parameters encoded as a single integer, so 1x1 grid 1st subplot
ax = fig.add_subplot(111, projection='3d')
#fontsize
plt.rcParams['legend.fontsize'] = 10

#plot samples
ax.plot(class1_sample[0,:], class1_sample[1,:], class1_sample[2,:],
        'o', markersize=8, color='blue', alpha=0.5, label='class1')
ax.plot(class2_sample[0,:], class2_sample[1,:], class2_sample[2,:],
        '^', markersize=8, alpha=0.5, color='green', label='class2')

ax.legend(loc='upper right')

plt.show()
# Step 3 Merge the Data

all_samples = np.concatenate((class1_sample, class2_sample), axis=1)
all_samples
all_samples.T
# Step 4 Compute the Dimensional Mean Vector, it will help compute the covariance matrix<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12994350282485875, 'fraction_numerical': 0.05536723163841808, 'mean_word_length': 5.1923076923076925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '483344', 'license': 'MIT', 'n_tokens_mistral': 712, 'n_tokens_neox': 646, 'n_words': 200, 'path': 'PCA/Build PCA.ipynb', 'repo_name': 'marcelaldecoa/DLND-Labs', 'size': '1770'}