0% found this document useful (0 votes)
2 views3 pages

Code 1

The document contains Python code for analyzing the breast cancer dataset using libraries such as Matplotlib, Pandas, NumPy, and Seaborn. It includes steps for loading the dataset, scaling the features, applying PCA for dimensionality reduction, and visualizing the results with scatter plots and heatmaps. The code demonstrates data preprocessing, transformation, and visualization techniques in machine learning.

Uploaded by

Pratham Malhotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Code 1

The document contains Python code for analyzing the breast cancer dataset using libraries such as Matplotlib, Pandas, NumPy, and Seaborn. It includes steps for loading the dataset, scaling the features, applying PCA for dimensionality reduction, and visualizing the results with scatter plots and heatmaps. The code demonstrates data preprocessing, transformation, and visualization techniques in machine learning.

Uploaded by

Pratham Malhotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Code 1

import matplotlib.pyplot as plt


import pandas as pd
import numpy as np
import seaborn as sns

Code 2

from sklearn.datasets import load_breast_cancer

Code 3

cancer=load_breast_cancer()

Code 4

type(cancer)

Code 5

cancer.keys()

Code 6

print(cancer['DESCR'])

Code 7

print(cancer['feature_names'])

Code 8

print(cancer['data'])

Code 9

df=pd.DataFrame(cancer['data'],columns=cancer['feature_names'])

Code 10

df
Code 11

print(cancer['target'])

Code 12

cancer['target_names']

Code 13

from sklearn.preprocessing import StandardScaler

Code 14

scaler=StandardScaler()

Code 15

scaler.fit(df).transform(df)

Code 16

scaler.fit(df)

Code 17

scaled_data =scaler.transform(df)

Code 18

scaled_data

Code 19

from sklearn.decomposition import PCA

Code 20

pca = PCA(n_components=2)
Code 21

x_pca=pca.fit(scaled_data).transform(scaled_data)

Code 22

x_pca

Code 23

scaled_data.shape

Code 24

x_pca.shape

Code 25

plt.figure(figsize=(8,6))
plt.scatter(x_pca[:,0],x_pca[:,1],c=cancer['target'],cmap='plasma')
plt.xlabel('First Principal Component')
plt.ylabel('Second Principal Component')

Code 26

pca.components_

Code 27

df_comp=pd.DataFrame(pca.components_,columns=cancer['feature_names'])

Code 28

df_comp

Code 29

sns.heatmap(df_comp,cmap='plasma')

You might also like