<jupyter_start><jupyter_text>Module Import<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Min-Max Normalization<jupyter_code>before_n = np.random.normal(0, 10, size=(10,))
before_n
after_n = (before_n - before_n.min()) / (before_n.max() - before_n.min())
after_n  # numpy의 Broadcast를 이용하여 간편하게 구현 가능.<jupyter_output><empty_output><jupyter_text>Z-Score Normalization<jupyter_code>before_n = np.random.normal(5, 10, size=(10,))
before_n
after_n = (before_n - before_n.mean()) / before_n.std()
after_n<jupyter_output><empty_output><jupyter_text>PCA (Complex Version by numpy)<jupyter_code>import matplotlib.pyplot as plt

array = np.random.multivariate_normal([5, 5], [[1, 3], [3, 1]], 50)
plt.xlim(-5, 10)
plt.ylim(-5, 10)
plt.scatter(array.T[0], array.T[1])
plt.show()
array -= np.array([array.T[0].mean(), array.T[1].mean()])
array /= np.array([array.T[0].std(), array.T[1].std()])

plt.xlim(-5, 5)
plt.ylim(-5, 5)
plt.scatter(array.T[0], array.T[1])
plt.show()
cov = np.cov(array.T)
eigen_val, eigen_vec = np.linalg.eig(cov)

plt.scatter(array.T[0], array.T[1])
plt.quiver([0, 0], [0, 0], eigen_vec[:, 0], eigen_vec[:, 1], color=['r', 'b'], scale=3)

print("eigenvalue: ", eigen_val)
print("eigenvector: ", eigen_vec)
# 2차원 -> 1차원
index = eigen_val.argmax()
v = eigen_vec[index, :]  # norm: 1

result = array.dot(v) * v.reshape(-1, 1)
plt.scatter(result[0], result[1], color='green')
plt.scatter(array.T[0], array.T[1])
plt.xlim(-4, 4)
plt.ylim(-4, 4)
plt.show()
from sklearn.decomposition import PCA

pca = PCA(n_components=1)  # 차원 수 1개
pca.fit(array)

print('고유 값 :', pca.explained_variance_)  # 고윳값
print('고유 벡터 :', pca.components_.T)  # 고유 벡터
print('사영 후:', pca.transform(array))<jupyter_output>고유 값 : [1.37868277]
고유 벡터 : [[-0.70710678]
 [-0.70710678]]
사영 후: [[ 0.74294083]
 [-0.94307048]
 [ 0.61839566]
 [-0.43973508]
 [ 0.29021079]
 [-1.22711771]
 [-0.97603161]
 [-0.50363041]
 [-1.51911067]
 [-1.95516322]
 [ 1.69424327]
 [-0.21173885]
 [-0.80680118]
 [ 0.06700227]
 [-2.17616083]
 [-1.02729412]
 [ 0.61817404]
 [-0.35968561]
 [-1.14520853]
 [ 0.04673977]
 [ 1.19547148]
 [-1.01964879]
 [ 0.73747498]
 [-2.42142473]
 [ 3.14625774]
 [-0.45833225]
 [-0.51561902]
 [ 1.11511519]
 [-0.75372664]
 [ 0.92259916]
 [ 0.91352659]
 [ 0.74813001]
 [-0.26835234]
 [-1.42581592]
 [ 1.27974275]
 [ 0.64486924]
 [-0.35104897]
 [-0.37354348]
 [ 1.11172166]
 [-1.2327128 ]
 [-0.42964753]
 [ 0.23598146]
 [-0.55205187]
 [ 0.4071089 ]
 [ 2.38139002]
 [ 2.49359029]
 [-0.29456415]
 [ 0.73860085]
 [ 1.30514651]
 [-0.06719663]]
{'fraction_non_alphanumeric': 0.21333853354134166, 'fraction_numerical': 0.20865834633385336, 'mean_word_length': 4.422832980972516, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '134090', 'license': 'MIT', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1292, 'n_words': 195, 'path': 'example/08-Normalization, PCA.ipynb', 'repo_name': 'SolidCitadel/2021-1-Data-Science', 'size': '2564'}