Let's see how to automatically estimate the number of clusters using the DBSCAN algorithm:
- The full code for this recipe is given in the estimate_clusters.py file that has already been provided to you. Now let's look at how it's built. Create a new Python file, and import the necessary packages:
from itertools import cycle import numpy as np from sklearn.cluster import DBSCAN from sklearn import metrics import matplotlib.pyplot as plt
- Load the input data from the data_perf.txt file. This is the same file that we used in the previous recipe, which will help us to compare the methods on the same dataset:
# Load datainput_file = ('data_perf.txt')x = []with open(input_file, 'r') as f: for line in f.readlines(): data = [float(i) ...