<jupyter_start><jupyter_text>[View in Colaboratory](https://colab.research.google.com/github/getmrinal/ML-Notebook/blob/master/19.%20PCA/PCABreast.ipynb)<jupyter_code>breast = datasets.load_breast_cancer()
from sklearn import decomposition ,ensemble ,datasets,linear_model
import numpy as np
import time
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
X = breast.data
X.shape
sc = StandardScaler()
X_std = sc.fit_transform(X)
x_train,x_test,y_train,y_test = train_test_split(X_std,breast.target,random_state = 0)
total = sum(pca.explained_variance_)
k = 0
curr_var =0
while curr_var/total < 0.95:
  curr_var += pca.explained_variance_[k]
  k = k+1
k
pca = decomposition.PCA(n_components = k)

x_train_pca = pca.fit_transform(x_train)
x_test_pca = pca.transform(x_test)
lr = linear_model.LogisticRegression()
start = time.time()
lr.fit(x_train,y_train)
end = time.time()
print(end-start)
print(lr.score(x_test,y_test))
lr = linear_model.LogisticRegression()
start = time.time()
lr.fit(x_train_pca,y_train)
end = time.time()
print(end-start)
print(lr.score(x_test_pca,y_test))<jupyter_output>0.00146412849426
0.951048951048951
{'fraction_non_alphanumeric': 0.11884550084889643, 'fraction_numerical': 0.035653650254668934, 'mean_word_length': 7.244755244755245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '310524', 'license': 'MIT', 'n_tokens_mistral': 495, 'n_tokens_neox': 467, 'n_words': 74, 'path': '19. PCA/PCABreast.ipynb', 'repo_name': 'yaminikonka/ML-Notebook', 'size': '1178'}