Skip to content
Advertisement

Clustering on Python and Bokeh; select widget which allows user to change clustering algorithm

I am trying to build a feature in a Bokeh dashboard which allows the user to cluster data. I am using the following example as a template, here is the link:- Clustering in Bokeh example

Here is the code from this example:-

JavaScript

The example allows the user to cluster data. Within the code, you can specify which algorithm to use; in the code pasted above, the algorithm is dbscan. I tried to modify the code so that I can add in a widget which would allow the user to specify the algorithm to use :-

JavaScript

However, I get this error when I try to run it:-

JavaScript

Can anyone tell me what I am missing in order to fix this?

Also, and if not too hard to do, I would like to add in a numeric input widget which allows the user to select the number of clusters for each algorithm to find. Suggestions?

Many thanks :)

EDIT

Here is the current state of the code with @Tony solution.

JavaScript

See algorithm.fit(X) this is where the error occurs. Error message:-

JavaScript

Advertisement

Answer

I don’t know sklearn but comparing both your examples I can see the following:

  1. the Select is a Bokeh model which has value attribute of type string. So select.value is a string
  2. the dbscan is an algorithm function

So when you do algorithm = dbscan you assign an algorithm function to your algorithm variable and when you do algorithm = select.value in your second example you assign just a string to it so it won’t work because string doesn’t have the fit() function. You should do something like this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement