File Exchange > Data Analysis >    Optimal Cluster Number

OriginLab Technical Support
Date Added:
Last Update:
Downloads (90 Days):
Total Ratings:
File Size:
382 KB
Average Rating:
File Name:
File Version:
Minimum Versions:

Identify the optimal number of clusters.

Screen Shot and Video:


This App can be used to determine the optimal number of clusters, which is an important parameter in cluster analysis.

Notes: This App needs Embedded Python and scikit-learn, gap-stat,gapstat_rs library. Other dependent libraries include pytz, six, python-dateutil, numpy, pandas, matplotlib, and scipy


  1. Download the clusterNum.opx file, then drag-and-drop onto the Origin workspace.
  2. The App will start downloading dependent Python libraries. Wait a few minutes until the download is completed and restart Origin.


  1. Activate a worksheet. Click the App icon to bring up the dialog.
  2. Select multiple columns of data for cluster analysis.
  3. Enter start and end value for the range of possible number of clusters K.
  4. Choose methods to determine cluster number: 
    • Elbow method: The within-cluster sum of squares (WSS) at each number of clusters is calculated and graphed. Increasing number of clusters will first add much information, but at some point the marginal gain will drop, showing a sharp "elbow" in the graph. The optimal number of clusters is chosen at this point.
    • Silhouette method: The average silhouette of observations for different number of clusters are computed. The optimal number of clusters k is the one that maximize the average silhouette.
    • Gap Statistic: The gap statistic compares the total within intra-cluster variation for different number of clusters k with their expected values under null reference distribution of the data. The estimate of the optimal clusters will be value that maximize the gap statistic.
  5. Click OK to output results.

Sample OPJU File
This app provides a sample OPJU file.  Right click the App icon in the Apps Gallery window, and choose Show Samples Folder from the short-cut menu. A folder will open. Drag-and-drop the project file clusterNum_sample.opju from the folder onto Origin. The Notes window in the project shows detailed steps.
Note: If you wish to save the OPJU after changing, it is recommended that you save to a different folder location (e.g. User Files Folder).


v1.21:8/31/2023 Fix gap-stat installation issue.
v1.2:4/3/2023 Support python 3.11.
v1.1: 6/29/2022 Suppress warning messages.

Reviews and Comments:
01/03/2024senolh18Great app

01/03/2024senolh18Great app


08/09/2023 根本没法用

04/17/2023SerbianNSCorrection and addition to the previous post:

Everything is fine with this app.

I made a mistake while installing the python package.
The installation process takes a little longer, and I ended the process earlier than I should have by turning off CMD.

Thanks again for this app.
Best Regards.

04/17/2023SerbianNSUnfortunately, this app does not work for me. App activation was performed on Origin PRO 2022 ( x64. This app installs successfully and all additional Python packages install successfully. I also applied all the steps to perform the analysis, but instead of performing the operation, it immediately outputs this:

" Traceback (most recent call last):
File "C:\Users\Branislav\AppData\Local\OriginLab\Apps\Optimal Cluster Number\", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Is there something wrong with this application or am I possibly doing something wrong?

What exactly must be entered in the output?
Plot data?

All other applications that have been activated work successfully, but not this one.

04/16/2023SerbianNSExcellent app, what's more, it's very useful because it's not in the tools of the ORIGIN software directly.