<jupyter_start><jupyter_text>Câncer de Mama O conjunto de dados de Câncer de mama é um dado multivariado com valor real que consiste em duas classes, em que cada classe significa se um paciente tem câncer de mama ou não. As duas categorias são: maligna e benigna. A classe maligna possui 212 amostras, enquanto a classe benigna possui 357 amostras. Possui 30 recursos compartilhados em todas as classes: raio, textura, perímetro, área, suavidade, dimensão fractal, etc. Você pode fazer o download do conjunto de dados de câncer de mama a partir daqui, ou uma maneira fácil é carregá-lo com a ajuda da biblioteca sklearn.<jupyter_code>from sklearn.datasets import load_breast_cancer
breast = load_breast_cancer()
breast_data = breast.data
breast_data.shape
breast_labels = breast.target
breast_labels.shape
breast_labels
import numpy as np
labels = np.reshape(breast_labels,(569,1))
final_breast_data = np.concatenate([breast_data,labels],axis=1)
final_breast_data.shape
import pandas as pd
breast_dataset = pd.DataFrame(final_breast_data)
features = breast.feature_names
features
features_labels = np.append(features,'label')
breast_dataset.columns = features_labels
breast_dataset.head()
breast_dataset['label'].replace(0, 'Benign',inplace=True)
breast_dataset['label'].replace(1, 'Malignant',inplace=True)
breast_dataset.tail()
from sklearn.preprocessing import StandardScaler
x = breast_dataset.loc[:, features].values
x = StandardScaler().fit_transform(x) # normalizing the features
x.shape
np.mean(x),np.std(x)
feat_cols = ['feature'+str(i) for i in range(x.shape[1])]
normalised_breast = pd.DataFrame(x,columns=feat_cols)
normalised_breast.tail()
from sklearn.decomposition import PCA
pca_breast = PCA(n_components=2)
principalComponents_breast = pca_breast.fit_transform(x)
principal_breast_Df = pd.DataFrame(data = principalComponents_breast
             , columns = ['principal component 1', 'principal component 2'])
principal_breast_Df.tail()
print('Explained variation per principal component: {}'.format(pca_breast.explained_variance_ratio_))
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure()
plt.figure(figsize=(10,10))
plt.xticks(fontsize=12)
plt.yticks(fontsize=14)
plt.xlabel('Principal Component - 1',fontsize=20)
plt.ylabel('Principal Component - 2',fontsize=20)
plt.title("Principal Component Analysis of Breast Cancer Dataset",fontsize=20)
targets = ['Benign', 'Malignant']
colors = ['r', 'g']
for target, color in zip(targets,colors):
    indicesToKeep = breast_dataset['label'] == target
    plt.scatter(principal_breast_Df.loc[indicesToKeep, 'principal component 1']
               , principal_breast_Df.loc[indicesToKeep, 'principal component 2'], c = color, s = 50)

plt.legend(targets,prop={'size': 15})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10201874549387166, 'fraction_numerical': 0.014780100937274693, 'mean_word_length': 6.751396648044692, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '326832', 'license': 'MIT', 'n_tokens_mistral': 969, 'n_tokens_neox': 921, 'n_words': 240, 'path': '002 - Dimensionality Reduction/.ipynb_checkpoints/PCA_Advanced_Example_01-checkpoint.ipynb', 'repo_name': 'howardroatti/Machine_Learning', 'size': '2774'}