Lab-7 Clustering
Lab-7 Clustering
import numpy as np
from sklearn.cluster import KMeans
# Get the labels (which cluster each point belongs to) and centroids
labels = kmeans.labels_
centroids = kmeans.cluster_centers_
1
#Code for viaualization
# Plot the data points with different colors for each cluster
for i in range(3):
plt.scatter([data_points[j][0] for j in range(len(data_points)) if
labels[j] == i],
[data_points[j][1] for j in range(len(data_points)) if
labels[j] == i],
label=f"Cluster {i+1}")
2
Lab work:
1. Use DBSCAN algorithm to cluster the given datapoints where minpoints=3 and
Epsilon =3:
A1(2, 10), A2(2,5), A3(8, 4), B1(5, 8), B2(7,5), B3(6, 4), C1(1, 2), C2(4, 9)
2. Load a dataset (Iris or Titanic) using Pandas. Explore the dataset showing the
information, descriptive statistics, check for null values. Also visualize the
distributions of the dataset using matplotlib or seaborn.
3
1. You are provided with the following dataset:
import pandas as pd