K-means Clustering in Scikit-learn

Hello,

In the example code given –> here <– I cannot understand why we can only select one data point in the figure (x=0.2, y=5.1, z=1.4), obtaining the corresponding hover, in all of the subplots. I tried to avoid this problem but I cannot figure out a way.

Any help please?
https://plot.ly/~WolfLo/108.embed

For simplicity, here is the code:

np.random.seed(5)

fig = tools.make_subplots(rows=2, cols=3,
                      print_grid=False,
                      specs=[[{'is_3d': True}, {'is_3d': True}, {'is_3d': True}],
                             [ {'is_3d': True, 'rowspan':1}, None, None]])
scene = dict(
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=2.5, y=0.1, z=0.1)
),
xaxis=dict(
    range=[-1, 4],
    title='Petal width',
    gridcolor='rgb(255, 255, 255)',
    zerolinecolor='rgb(255, 255, 255)',
    showbackground=True,
    backgroundcolor='rgb(230, 230,230)',
    showticklabels=False, ticks=''
),
yaxis=dict(
    range=[4, 8],
    title='Sepal length',
    gridcolor='rgb(255, 255, 255)',
    zerolinecolor='rgb(255, 255, 255)',
    showbackground=True,
    backgroundcolor='rgb(230, 230,230)',
    showticklabels=False, ticks=''
),
zaxis=dict(
    range=[1,8],
    title='Petal length',
    gridcolor='rgb(255, 255, 255)',
    zerolinecolor='rgb(255, 255, 255)',
    showbackground=True,
    backgroundcolor='rgb(230, 230,230)',
    showticklabels=False, ticks=''
)
)

centers = [[1, 1], [-1, -1], [1, -1]]
iris = datasets.load_iris()
X = iris.data
y = iris.target

estimators = {'k_means_iris_3': KMeans(n_clusters=3),
          'k_means_iris_8': KMeans(n_clusters=8),
          'k_means_iris_bad_init': KMeans(n_clusters=3, n_init=1,
                                          init='random')}
fignum = 1
for name, est in estimators.items():
est.fit(X)
labels = est.labels_

trace = go.Scatter3d(x=X[:, 3], y=X[:, 0], z=X[:, 2],
                     showlegend=False,
                     mode='markers',
                     marker=dict(
                            color=labels.astype(np.float),
                            line=dict(color='black', width=1)
    ))
fig.append_trace(trace, 1, fignum)

fignum = fignum + 1

y = np.choose(y, [1, 2, 0]).astype(np.float)

trace1 = go.Scatter3d(x=X[:, 3], y=X[:, 0], z=X[:, 2],
                  showlegend=False,
                  mode='markers',
                  marker=dict(
                        color=y,
                        line=dict(color='black', width=1)))
fig.append_trace(trace1, 2, 1)

fig['layout'].update(height=900, width=900,
                 margin=dict(l=10,r=10))

fig['layout']['scene1'].update(scene)
fig['layout']['scene2'].update(scene)
fig['layout']['scene3'].update(scene)
fig['layout']['scene4'].update(scene)
fig['layout']['scene5'].update(scene)

Many thanks in advance!

Hi @WolfLo, I don’t think I’m seeing the problem you’re talking about. When I open your link I get hover tooltips on all of the points in all of the subplots. I wonder if you’re hitting the same problem discussed in https://github.com/plotly/plotly.py/issues/952 (which we haven’t been able to reproduce/diagnose yet).

Could you try out the simple example from that issue and see if the problem persists? If so, could you add a comment to the issue with:

  • Python version
  • plotly.py version
  • Operating system
  • Browser version

Thanks!
-Jon

1 Like

Thanks @jmmease, I commented that issue with all you asked. Hope you will be able to find a solution.

Have a good day!