3. Neighborhood Approaches and DBSCAN
Activity 3.01: Implementing DBSCAN from Scratch
Solution:
- Generate a random cluster dataset as follows:
from sklearn.cluster import DBSCAN from sklearn.datasets import make_blobs import matplotlib.pyplot as plt import numpy as np %matplotlib inline X_blob, y_blob = make_blobs(n_samples=500, \ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â centers=4, n_features=2, \ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â random_state=800)
- Visualize the generated data:
plt.scatter(X_blob[:,0], X_blob[:,1]) plt.show()
The output is as follows:
- Create functions from scratch that allow you to call DBSCAN on a dataset:
Activity3.01.ipynb
def scratch_DBSCAN(x, eps, min_pts...