0% found this document useful (0 votes)
9 views2 pages

Program 9

The document contains a Python script that performs K-Means clustering on the Wisconsin Breast Cancer dataset. It standardizes the features, applies K-Means with two clusters, and uses PCA for dimensionality reduction to visualize the results. A scatter plot is generated to display the clustering outcomes in a two-dimensional space.

Uploaded by

prathibhard3
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)
9 views2 pages

Program 9

The document contains a Python script that performs K-Means clustering on the Wisconsin Breast Cancer dataset. It standardizes the features, applies K-Means with two clusters, and uses PCA for dimensionality reduction to visualize the results. A scatter plot is generated to display the clustering outcomes in a two-dimensional space.

Uploaded by

prathibhard3
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

5/21/25, 8:36 AM Untitled3.

ipynb - Colab

import numpy as np
import pandas as pd
import [Link] as plt
import seaborn as sns
from [Link] import load_breast_cancer
from [Link] import StandardScaler
from [Link] import KMeans
from [Link] import PCA

# 1. Load the Wisconsin Breast Cancer dataset


data = load_breast_cancer()
X = [Link]
y = [Link]
feature_names = data.feature_names
target_names = data.target_names

# 2. Standardize the features


scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# 3. Apply K-Means clustering


kmeans = KMeans(n_clusters=2, random_state=42)
[Link](X_scaled)
cluster_labels = kmeans.labels_

# 4. Reduce dimensions for visualization (PCA 2D)


pca = PCA(n_components=2)
X_pca = pca.fit_transform(X_scaled)

# 5. Plot clustering results


[Link](figsize=(10, 6))
[Link](X_pca[:, 0], X_pca[:, 1], c=cluster_labels, cmap='viridis', edgecolor='k', s=100)
[Link]("K-Means Clustering on Wisconsin Breast Cancer Dataset (PCA Projection)")
[Link]("Principal Component 1")
[Link]("Principal Component 2")
[Link](True)
[Link](label='Cluster Label')
[Link]()

[Link] 1/2
5/21/25, 8:36 AM [Link] - Colab

[Link] 2/2

You might also like