<jupyter_start><jupyter_text>Data Visualization **Import**<jupyter_code>import csv
import os
import numpy as np
from scipy import optimize
from itertools import product
import matplotlib.pyplot as plt
from tqdm import tqdm_notebook
import scipy as sp
from utils.data import load_data, save_results
from utils.models import SVM, SPR, PCA
from utils.kernels import GaussianKernel<jupyter_output><empty_output><jupyter_text>**Paths and Globals**<jupyter_code>CWD = os.getcwd()
DATA_DIR = os.path.join(CWD, "data")
RESULT_DIR = os.path.join(CWD, "results")

FILES = {0: {"train_mat": "Xtr0_mat100.csv",
             "train": "Xtr0.csv",
             "test_mat": "Xte0_mat100.csv",
             "test": "Xte0.csv",
             "label": "Ytr0.csv"},
         1: {"train_mat": "Xtr1_mat100.csv",
             "train": "Xtr1.csv",
             "test_mat": "Xte1_mat100.csv",
             "test": "Xte1.csv",
             "label": "Ytr1.csv"},
         2: {"train_mat": "Xtr2_mat100.csv",
             "train": "Xtr2.csv",
             "test_mat": "Xte2_mat100.csv",
             "test": "Xte2.csv",
             "label": "Ytr2.csv"}}<jupyter_output><empty_output><jupyter_text>Test Kernel PCA **Linear Kernel**<jupyter_code>[...]<jupyter_output><empty_output><jupyter_text>**Gaussian Kernel**<jupyter_code># choose kernel and kernel's parameter
kernel = GaussianKernel(200)


# load data
i = 0
X_train, Y_train, X_test = load_data(i, data_dir=DATA_DIR, files_dict=FILES)


# compute PCA
pca = PCA(kernel)
pca.fit(X_train)

# print eigenvalues
plt.plot(pca._lambda)
plt.title("Eigenvalues of PCA")

# plot 2D graph of the data projected on the eigenvectors associated to the 2 highest eigenvalues
n = 2
X_proj = pca.proj(X_train,n)

# plot PCA
plt.figure(figsize=(7,7))
plt.scatter(X_proj[:,0], X_proj[:,1], s= 20, c = Y_train)
plt.title('PCA projection in feature space')
plt.xlabel('PC1')
plt.ylabel('PC2')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14425553838227717, 'fraction_numerical': 0.02627511591962906, 'mean_word_length': 3.9289340101522843, 'pattern_counts': {'":': 15, '<': 17, '<?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': '513487', 'license': 'MIT', 'n_tokens_mistral': 772, 'n_tokens_neox': 725, 'n_words': 158, 'path': 'Data_Visualization.ipynb', 'repo_name': 'inzouzouwetrust/KMML_challenge', 'size': '1941'}