Function K-Means Clustering

A Function that returns cluster centers for given data (X,Y) vector points.

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

¹: _X and _Y size must match.

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

Remove from Favorite Scripts Add to Favorite Scripts


Excellent Work @RicardoSantos !
+1 Reply
@RicardoSantos Olá Ricardo! Esta implementação de clustering por K-Means está funcional? Obrigado!
ruimnetob ruimnetob
@ruimnetob, gostaria de agrupar uns valores, e obter os seus centros
Hello, @RicardoSantos is there any chance that you could show an example of using k-means clustering in Pine Script? Perhaps something along the lines of this would be very useful! https://medium.com/@judopro/using-machine-learning-to-programmatically-determine-stock-support-and-resistance-levels-9bb70777cf8e

My intent is to use k-means clustering in Pine Script the same way as the above article does, however, I am only familiar with python and sklearn and feel like I would need to see a working pine script example first. If you do decide to make the above before me then I applaud you!
RicardoSantos DEAD_HUNTER
@DEAD_HUNTER, we are still quite a bit off to be able to do any meaningful AI in pine :P, the kmeans function is a bit expensive computationally so your very limited, maybe later it will be possible to apply it correctly, i dont have any plans of using it in a more complex way any time soon
DEAD_HUNTER RicardoSantos
@RicardoSantos, Thats such a shame, I really think that the above mentioned python implementation is pretty neat, however I don't really use it due to the fact that I have to run it on my own pc and fetch data from yahoo finance and in the end I get a chart that isn't linked with Tradingview. Its just a bit of a hassle to read and trade really :/
@DEAD_HUNTER, I personally trade using TradingView and love the charting so I wanted to have the k-means function in tradingview like you said.
But wasn't possible, so built quickly using python. @ricardoSantos from what I see, you already have a code generating centers tho, so why can't he use that to draw the centers?
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out