<jupyter_start><jupyter_text>Exercise:Write a python program to perform K-Means clustering on Breast Cancer Data<jupyter_code># import libraries
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import mode
from sklearn.cluster import KMeans
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
# Load Breaast cancer data from sklearn
df = load_breast_cancer()
# Visualiza the data
df.data.shape
#printing the target vaues
print("Taeget Name:",df.target_names,"\nTarget Shape:",df.target_names.shape)
# kmeans algorithm to classify given data
model = KMeans(n_clusters=df.target_names.shape[0], random_state=144)
# Fit and Predict using kmeans
predict = model.fit_predict(df.data)
print(predict)
# accuracy
labels = np.zeros_like(predict)
for i in range(2):
    mask = (predict==i)
    labels[mask] = mode(df.target[mask])[0]
accuracy_score(df.target,labels)
# confusion matrix
cmat = confusion_matrix(df.target,labels)
sns.heatmap(cmat,xticklabels=df.target_names,yticklabels=df.target_names)
plt.plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09161624891961971, 'fraction_numerical': 0.005185825410544511, 'mean_word_length': 6.931506849315069, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '141702', 'license': 'MIT', 'n_tokens_mistral': 395, 'n_tokens_neox': 379, 'n_words': 100, 'path': 'LAB-08/144_08.ipynb', 'repo_name': 'rajvaghasiya6/144_RajVaghasiya', 'size': '1157'}