VNRVJIET Sheet No……………..
Name of the Laboratory: Name of the Experiment
Principles of Machine Learning
Laboratory (22MC2AM401) Experiment No. Date
EXPERIMENT No. – 4
AIM: Given the following data, which specify classifications for nine combinations of VAR1 and
VAR2 predict a classification for a case where VAR1=0.906 and VAR2=0.606, using the result of k-
means clustering with 3 means (i.e., 3 centroids).
SOFTWARE USED:
• Python 3.x – Programming language used to implement the K-Means clustering model.
• NumPy – For creating and handling numerical arrays.
• Matplotlib – For visualizing clusters (if needed).
• Scikit-learn (sklearn) – For applying the KMeans clustering algorithm.
• Jupyter Notebook / Google Colab – Environment used to execute Python code interactively.
THEORY:
K-Means is an unsupervised machine learning algorithm used for clustering data into K distinct
groups based on similarity. The algorithm works by initializing K centroids and assigning each data
point to the cluster with the nearest centroid using Euclidean distance. After assignment, centroids
are recomputed as the mean of all points in each cluster. This process repeats iteratively until the
centroids stabilize.
The goal of K-Means is to minimize the within-cluster sum of squares, ensuring that each cluster
contains points that are close to each other and far from points in other clusters. After the model is
trained, new data points can be classified by determining the nearest centroid. In this experiment, K-
Means with 3 clusters was applied to the given (VAR1, VAR2) dataset, and the model was then used
to predict the cluster for a new case with VAR1 = 0.906 and VAR2 = 0.606.
22071A04P4
22071A0218
VNRVJIET Sheet No……………..
Name of the Laboratory: Name of the Experiment
Principles of Machine Learning
Laboratory (22MC2AM401) Experiment No. Date
PROCEDURE:
1. Import necessary libraries such as NumPy, Matplotlib, and KMeans from scikit-learn.
2. Create the dataset by storing the values of VAR1 and VAR2 in a NumPy array.
3. Initialize the K-Means model with 3 clusters and a fixed random state for reproducibility.
4. Fit the K-Means model using the dataset to compute the three centroids.
5. Prepare a new data point with VAR1 = 0.906 and VAR2 = 0.606.
6. Use the predict() function of the trained K-Means model to determine the cluster assignment
of this new point.
7. Display the predicted cluster label as the classification result.
CODE:
from [Link] import KMeans
import [Link] as plt
import numpy as np
X = [Link]([[1.713,1.586], [0.180,1.786], [0.353,1.240], [0.940,1.566], [1.486,0.759],
[1.266,1.106],[1.540,0.419],[0.459,1.799],[0.773,0.186]])
y=[Link]([0,1,1,0,1,0,1,1,1])
kmeans = KMeans(n_clusters=3, random_state=0).fit(X,y)
p=[Link]([[0.906, 0.606]])
print('Prediction of classification for a case where VAR1=0.906 and VAR2=0.606,')
print('Class',p)
OUTPUT:
RESULT:
The default RBF-SVM trained on the breast cancer dataset produced strong baseline performance on
the 30% test split. After grid search over 𝐶and 𝛾, the tuned model (best parameters printed by
grid.best_params_) achieved improved test metrics, as evidenced by a higher overall accuracy and
better precision/recall/F1 in the classification_report, along with fewer misclassifications in the
confusion_matrix.
22071A04P4
22071A0218