1D cluster - Jenks optimization - Finding optimal number I have a sample data variable shown below
score
10,
11,
12,
90,
95,
97,
38,
37,
35

Instead of applying/binning data based on quantiles etc, I would like to bin based on pattern present in the data.
That's when I came to know about the jenks natural breaks here
However, this approach requires us to define the n_clusters for us to segment the data
This is what I tried as of now
df['score_segment'] = pd.cut(
    df['score'],
    bins=jenkspy.jenks_breaks(df['score'], nb_class=5),
    labels=[1,2,3,4,5],
    include_lowest=True)

Is there any automated approach that can give us the optimal number of clusters for 1D data based on its property?

This seems to be a two stage problem: first, identify the number of clusters and then, secondly, optimally perform the clustering.
For the first part, I'd suggest Cluster Validation by Prediction Strength to identify the number of clusters. The linked article has Python code and links to a github with R code to perform this.
Once you've identified the number of clusters, you could use the R package Ckmeans.1d.dp to do the optimal 1 dimensional clustering.
