Complete the code to import the DBSCAN class from scikit-learn.
from sklearn.cluster import [1]
The DBSCAN class is imported from sklearn.cluster to perform density-based clustering.
Complete the code to create a DBSCAN model with epsilon 0.5.
model = DBSCAN(eps=[1])The eps parameter sets the radius for neighborhood search. 0.5 is a common default value.
Fix the error in the code to fit the DBSCAN model on data X.
model = DBSCAN(eps=0.3) model.[1](X)
DBSCAN uses the fit() method to learn clusters from data X.
Fill both blanks to create a dictionary of cluster labels for each point in X.
labels = model.[1] clusters = {i: labels[i] for i in [2](len(labels))}
The labels attribute stores cluster labels. Using range(len(labels)) iterates over all points.
Fill all three blanks to compute the number of clusters excluding noise points.
import numpy as np unique_labels = set(model.[1]) num_clusters = len(unique_labels) - (1 if [2] in unique_labels else 0) noise_points = np.sum(model.[3] == -1)
The labels attribute holds cluster labels. Noise points are labeled -1. We count clusters excluding noise.
