<jupyter_start><jupyter_text>PCA<jupyter_code>pca = PCA(n_components=2)

pca.fit(x)
(pca.explained_variance_ratio_).sum()
plt.plot(np.cumsum(pca.explained_variance_ratio_))
plt.xlabel('Number of Components')
plt.ylabel('Variance (%)') #for each component
plt.title('Dataset Explained Variance')
plt.grid(True)
plt.show()<jupyter_output><empty_output><jupyter_text>Transform the data<jupyter_code>x.shape
x_transformed = pca.transform(x)
x_transformed.shape
x_transformed = pd.DataFrame(x_transformed,columns=['PC1','PC2'])
x_transformed
x_transformed.set_index(df.index,inplace=True)
x_transformed['diagnosis'] = y<jupyter_output><empty_output><jupyter_text>Transformed Dataset<jupyter_code>x_transformed<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13760217983651227, 'fraction_numerical': 0.004087193460490463, 'mean_word_length': 13.134615384615385, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '343096', 'license': 'MIT', 'n_tokens_mistral': 302, 'n_tokens_neox': 284, 'n_words': 29, 'path': 'Machine Learning/Supervised Learning/Module 8 - Case Studies (Dimensionality Reduction)/Module 8 - Case Study 3.ipynb', 'repo_name': 'mohammedsaqlainattar/Python-for-Data-Science', 'size': '734'}