<p>I apply range searcher and add a function to generate seeds from the data set as initial centroids like what scikit does. I use all the points as initial centroids before.  Generated seeds is much fewer than all the points.<br>
I used the following test script for scikit:</p>

<pre><code>import numpy
import time
from sklearn.cluster import MeanShift, estimate_bandwidth

d = numpy.genfromtxt('iris.csv', delimiter=',')
bw = estimate_bandwidth(d, quantile=0.2, n_samples=500)

print(bw)

ms = MeanShift(bandwidth=bw, bin_seeding = True)
t1 = time.time()
ms.fit(d)
t2 = time.time()
print t2 - t1


print(ms.cluster_centers_)
print(len(numpy.unique(ms.labels_)))
</code></pre>

<p>the result is 0.038s<br>
0.912643298082<br>
0.0381479263306<br>
[[ 6.28301887  2.88679245  4.90754717  1.7       ]<br>
 [ 4.97391304  3.39130435  1.47391304  0.24130435]]<br>
2<br>
then I call MS program with <br>
-v -i iris.csv -o assignments.csv -C centroids.csv -r 0.912643298082<br>
I get <br>
clustering: 0.048295s<br>
MS program is much faster than before.<br>
But my implementation is still slower than scikit because of the algorithm.</p>

<pre><code>          distances[0][j] /= radius;
          double weight = kernel.Gradient(distances[0][j]) / distances[0][j];
          sumWeight += weight;
          newCentroid += weight * data.unsafe_col(neighbors[0][j]);
</code></pre>

<p>I use this to iterate and can use user-defined kernel.<br>
But scikit just use the average </p>

<pre><code>my_mean = np.mean(points_within, axis=0)
</code></pre>

<p>I tried to use the same simple algorithm like scikit, then MLPACK and scikit cost the same time.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/pull/388#issuecomment-91872693">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFNvQbAbs9GxDM_awxPzWbUJlpYQyks5n-UBigaJpZM4DTzb1.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/388#issuecomment-91872693"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>