RicardoSantos

Function K-Means Clustering

RicardoSantos Wizard Updated   
Description:
A Function that returns cluster centers for given data (X,Y) vector points.

Inputs:
_X: Array containing x data points.¹
_Y: Array containing y data points.¹
_number_of_clusters: number of clusters.

Note:
¹: _X and _Y size must match.

Outputs:
_centers_x: Array containing x data points.
_centers_y: Array containing y data points.

Resources:
rosettacode.org/wiki...K-means++_clustering
en.wikipedia.org/wik...i/K-means_clustering
Release Notes:
Update to V5 and fixed a a few errors in the code. -_-*
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?