You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mahout.apache.org by john abbott <ab...@gmail.com> on 2011/04/07 18:30:03 UTC
Re: Returning number of points in KMeans
Hi,
I was wondering whether someone on this list might be able to help with some
code I'm running. I'm a newbie who's been working with Mahout for a few
weeks and working my way through the Mahout in Action Book. My issue is
with KMeans. I can create clusters fine but cannot retrieve the number of
points in each cluster from my Cluster objects.
Here my code
...
List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
clusters, new GeoDistanceMeasure(), 100, t2);
for (Iterator iterator = myClust.iterator(); iterator.hasNext();) {
List clustersList = (List) iterator.next();
for (Iterator iterator2 = clustersList.iterator(); iterator2.hasNext();)
{
Cluster finalCluster = (Cluster) iterator2.next();
//if(finalCluster.isConverged()){
ClusterObservations obs = finalCluster.getObservations();
System.out.print("S0 is "+obs.getS0());
System.out.print(" Count "+finalCluster.count());
System.out.print(" ID is "+finalCluster.getIdentifier());
System.out.print(" Number points "+finalCluster.getNumPoints());
System.out.print("Size is "+finalCluster.getCenter().size());
System.out.println("Lat "+finalCluster.getCenter().get(0)+" Long"
+finalCluster.getCenter().get(1));
...
And here is the output:
S0 is 0.0 Count 0 ID is CL-0 Number points 0Size is 2Lat 51.5015202264285
Long-0.17545441392857
S0 is 0.0 Count 0 ID is CL-1 Number points 0Size is 2Lat 50.967885199444495
Long-1.3534804972222
S0 is 0.0 Count 0 ID is CL-2 Number points 0Size is 2Lat 50.96263126
Long-1.3584173975
S0 is 0.0 Count 0 ID is CL-3 Number points 0Size is 2Lat 50.973428999999996
Long-1.3687605
S0 is 0.0 Count 0 ID is CL-4 Number points 0Size is 2Lat 50.93504983
Long-1.46711701
I'd really like to know the number of points within each cluster.
Also I have written a GeoDistanceMeasure class that calculates distances
using the Haversine method and takes Latitude and Longitude as inputs. I'd
really like to contribute it back if people thought it was
interesting/useful and walked me through how I might do that.
Thanks very much in advance,
John
On Thu, Apr 7, 2011 at 4:38 PM, Jeff Eastman <je...@narus.com> wrote:
> You mean you are seeing the same clusters as clusters-0 in all other
> clusters-i directories? That would indeed be a huge bug! I will investigate.
>
> -----Original Message-----
> From: Jose Fuentes De Frutos [mailto:infjfd00@udc.es]
> Sent: Thursday, April 07, 2011 3:59 AM
> To: user@mahout.apache.org
> Subject: FuzzyKMeans in distributed execution
>
> Hello!,
>
> I'm working with the latest release of the Mahout (trunk version) and I
> have a problem with the FuzzyKMeans algorithm in distributed mode. I printed
> the clusters in each iteration of the algorithm and I think that the
> algorithm always save the initial clusters, consequently the results are the
> same independently of the number of iterations.
>
> Am I doing something wrong, or we are talking about a bug?
>
> Thank you.
>
>
>
--
John Abbott
Co-Founder
www.oobafit.com
m. 44 (0)7919392754
@scmjea
Re: Returning number of points in KMeans
Posted by john abbott <ab...@gmail.com>.
Robin and Jeff,
Please ignore the last post I have fixed the issue by looking again at the
debugger.
My problem was that I was calling CanopyClusterer.createCanopies with
a List<Vector>
made up of my points and then sending the same List<Vector> into my
KMeansClusterer.clusterPoints
code. However by calling .createCanopies all elements are removed
from theList<Vector> so
I ended up clustering my canopies rather than points.
Thanks again for your help,
John
On Fri, Apr 8, 2011 at 10:53 AM, john abbott <ab...@gmail.com> wrote:
> Robin and Jeff,
>
> Thank you both so much for the quick replies and the tips. I've stepped
> through the debugger and cannot see anything obvious.
>
> Robin my apologies I'm not sure I understand you advice.
>
> I have generated my clusters using:
>
> List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
> clusters, new GeoDistanceMeasure(), 100, t2);
>
>
> I don't see an obvious method to assign points to clusters. Do you mean me
> to call something like:
> KMeansClusterer.addPointsToNearestCluster or
> KMeansClusterer.emitPointToNearestCluster or
> KMeansClusterer.outputPointWithClusterInfo .
>
> Thanks again very much,
>
> John
>
> I'll create a JIRA and upload my source for GeoDistance measure at the
> weekend I haven't yet overidden the method
> public double distance(double centroidLengthSquare, Vector centroid,
> Vector v)
> but I'm hoping that if someone's interested they might be able to help me
> fix that.
>
> On Thu, Apr 7, 2011 at 9:08 PM, Robin Anil <ro...@gmail.com> wrote:
>
>> Once you create the clusters, you need to assign the points to the nearest
>> cluster based on your distance measure. You just need to iterate and
>> assign
>> it
>>
>> Robin
>>
>> On Thu, Apr 7, 2011 at 10:17 PM, Jeff Eastman <je...@narus.com> wrote:
>>
>> > Looks like you are running the in-memory implementation. I can
>> investigate
>> > some this weekend but you'll get quicker results by single-stepping in
>> your
>> > debugger. It's not obvious what's going on here.
>> >
>> > If you want to contribute your distance measure, create a Jira for it
>> and
>> > add a patch file. It does seem like an interesting distance measure.
>> >
>> > Jeff
>> >
>> > -----Original Message-----
>> > From: john abbott [mailto:abbottje@gmail.com]
>> > Sent: Thursday, April 07, 2011 9:30 AM
>> > To: user@mahout.apache.org
>> > Subject: Re: Returning number of points in KMeans
>> >
>> > Hi,
>> >
>> > I was wondering whether someone on this list might be able to help with
>> > some
>> > code I'm running. I'm a newbie who's been working with Mahout for a few
>> > weeks and working my way through the Mahout in Action Book. My issue is
>> > with KMeans. I can create clusters fine but cannot retrieve the number
>> of
>> > points in each cluster from my Cluster objects.
>> >
>> > Here my code
>> >
>> > ...
>> >
>> > List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
>> > clusters, new GeoDistanceMeasure(), 100, t2);
>> >
>> > for (Iterator iterator = myClust.iterator(); iterator.hasNext();) {
>> >
>> > List clustersList = (List) iterator.next();
>> >
>> > for (Iterator iterator2 = clustersList.iterator();
>> iterator2.hasNext();)
>> > {
>> >
>> > Cluster finalCluster = (Cluster) iterator2.next();
>> >
>> > //if(finalCluster.isConverged()){
>> >
>> > ClusterObservations obs = finalCluster.getObservations();
>> >
>> > System.out.print("S0 is "+obs.getS0());
>> >
>> > System.out.print(" Count "+finalCluster.count());
>> >
>> > System.out.print(" ID is "+finalCluster.getIdentifier());
>> >
>> > System.out.print(" Number points
>> "+finalCluster.getNumPoints());
>> >
>> > System.out.print("Size is "+finalCluster.getCenter().size());
>> >
>> > System.out.println("Lat "+finalCluster.getCenter().get(0)+"
>> Long"
>> > +finalCluster.getCenter().get(1));
>> >
>> > ...
>> >
>> >
>> > And here is the output:
>> >
>> > S0 is 0.0 Count 0 ID is CL-0 Number points 0Size is 2Lat
>> 51.5015202264285
>> > Long-0.17545441392857
>> >
>> > S0 is 0.0 Count 0 ID is CL-1 Number points 0Size is 2Lat
>> 50.967885199444495
>> > Long-1.3534804972222
>> >
>> > S0 is 0.0 Count 0 ID is CL-2 Number points 0Size is 2Lat 50.96263126
>> > Long-1.3584173975
>> >
>> > S0 is 0.0 Count 0 ID is CL-3 Number points 0Size is 2Lat
>> 50.973428999999996
>> > Long-1.3687605
>> > S0 is 0.0 Count 0 ID is CL-4 Number points 0Size is 2Lat 50.93504983
>> > Long-1.46711701
>> >
>> > I'd really like to know the number of points within each cluster.
>> >
>> >
>> > Also I have written a GeoDistanceMeasure class that calculates distances
>> > using the Haversine method and takes Latitude and Longitude as inputs.
>> I'd
>> > really like to contribute it back if people thought it was
>> > interesting/useful and walked me through how I might do that.
>> >
>> > Thanks very much in advance,
>> >
>> > John
>> >
>> > On Thu, Apr 7, 2011 at 4:38 PM, Jeff Eastman <je...@narus.com>
>> wrote:
>> >
>> > > You mean you are seeing the same clusters as clusters-0 in all other
>> > > clusters-i directories? That would indeed be a huge bug! I will
>> > investigate.
>> > >
>> > > -----Original Message-----
>> > > From: Jose Fuentes De Frutos [mailto:infjfd00@udc.es]
>> > > Sent: Thursday, April 07, 2011 3:59 AM
>> > > To: user@mahout.apache.org
>> > > Subject: FuzzyKMeans in distributed execution
>> > >
>> > > Hello!,
>> > >
>> > > I'm working with the latest release of the Mahout (trunk version) and
>> I
>> > > have a problem with the FuzzyKMeans algorithm in distributed mode. I
>> > printed
>> > > the clusters in each iteration of the algorithm and I think that the
>> > > algorithm always save the initial clusters, consequently the results
>> are
>> > the
>> > > same independently of the number of iterations.
>> > >
>> > > Am I doing something wrong, or we are talking about a bug?
>> > >
>> > > Thank you.
>> > >
>> > >
>> > >
>> >
>> >
>> > --
>> > John Abbott
>> > Co-Founder
>> > www.oobafit.com
>> > m. 44 (0)7919392754
>> > @scmjea
>> >
>>
>
>
>
> --
> John Abbott
> Co-Founder
> www.oobafit.com
> m. 44 (0)7919392754
> @scmjea
>
--
John Abbott
Co-Founder
www.oobafit.com
m. 44 (0)7919392754
@scmjea
Re: Returning number of points in KMeans
Posted by john abbott <ab...@gmail.com>.
Robin and Jeff,
Thank you both so much for the quick replies and the tips. I've stepped
through the debugger and cannot see anything obvious.
Robin my apologies I'm not sure I understand you advice.
I have generated my clusters using:
List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
clusters, new GeoDistanceMeasure(), 100, t2);
I don't see an obvious method to assign points to clusters. Do you mean me
to call something like:
KMeansClusterer.addPointsToNearestCluster or
KMeansClusterer.emitPointToNearestCluster or
KMeansClusterer.outputPointWithClusterInfo .
Thanks again very much,
John
I'll create a JIRA and upload my source for GeoDistance measure at the
weekend I haven't yet overidden the method
public double distance(double centroidLengthSquare, Vector centroid,
Vector v)
but I'm hoping that if someone's interested they might be able to help me
fix that.
On Thu, Apr 7, 2011 at 9:08 PM, Robin Anil <ro...@gmail.com> wrote:
> Once you create the clusters, you need to assign the points to the nearest
> cluster based on your distance measure. You just need to iterate and assign
> it
>
> Robin
>
> On Thu, Apr 7, 2011 at 10:17 PM, Jeff Eastman <je...@narus.com> wrote:
>
> > Looks like you are running the in-memory implementation. I can
> investigate
> > some this weekend but you'll get quicker results by single-stepping in
> your
> > debugger. It's not obvious what's going on here.
> >
> > If you want to contribute your distance measure, create a Jira for it and
> > add a patch file. It does seem like an interesting distance measure.
> >
> > Jeff
> >
> > -----Original Message-----
> > From: john abbott [mailto:abbottje@gmail.com]
> > Sent: Thursday, April 07, 2011 9:30 AM
> > To: user@mahout.apache.org
> > Subject: Re: Returning number of points in KMeans
> >
> > Hi,
> >
> > I was wondering whether someone on this list might be able to help with
> > some
> > code I'm running. I'm a newbie who's been working with Mahout for a few
> > weeks and working my way through the Mahout in Action Book. My issue is
> > with KMeans. I can create clusters fine but cannot retrieve the number
> of
> > points in each cluster from my Cluster objects.
> >
> > Here my code
> >
> > ...
> >
> > List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
> > clusters, new GeoDistanceMeasure(), 100, t2);
> >
> > for (Iterator iterator = myClust.iterator(); iterator.hasNext();) {
> >
> > List clustersList = (List) iterator.next();
> >
> > for (Iterator iterator2 = clustersList.iterator();
> iterator2.hasNext();)
> > {
> >
> > Cluster finalCluster = (Cluster) iterator2.next();
> >
> > //if(finalCluster.isConverged()){
> >
> > ClusterObservations obs = finalCluster.getObservations();
> >
> > System.out.print("S0 is "+obs.getS0());
> >
> > System.out.print(" Count "+finalCluster.count());
> >
> > System.out.print(" ID is "+finalCluster.getIdentifier());
> >
> > System.out.print(" Number points "+finalCluster.getNumPoints());
> >
> > System.out.print("Size is "+finalCluster.getCenter().size());
> >
> > System.out.println("Lat "+finalCluster.getCenter().get(0)+"
> Long"
> > +finalCluster.getCenter().get(1));
> >
> > ...
> >
> >
> > And here is the output:
> >
> > S0 is 0.0 Count 0 ID is CL-0 Number points 0Size is 2Lat 51.5015202264285
> > Long-0.17545441392857
> >
> > S0 is 0.0 Count 0 ID is CL-1 Number points 0Size is 2Lat
> 50.967885199444495
> > Long-1.3534804972222
> >
> > S0 is 0.0 Count 0 ID is CL-2 Number points 0Size is 2Lat 50.96263126
> > Long-1.3584173975
> >
> > S0 is 0.0 Count 0 ID is CL-3 Number points 0Size is 2Lat
> 50.973428999999996
> > Long-1.3687605
> > S0 is 0.0 Count 0 ID is CL-4 Number points 0Size is 2Lat 50.93504983
> > Long-1.46711701
> >
> > I'd really like to know the number of points within each cluster.
> >
> >
> > Also I have written a GeoDistanceMeasure class that calculates distances
> > using the Haversine method and takes Latitude and Longitude as inputs.
> I'd
> > really like to contribute it back if people thought it was
> > interesting/useful and walked me through how I might do that.
> >
> > Thanks very much in advance,
> >
> > John
> >
> > On Thu, Apr 7, 2011 at 4:38 PM, Jeff Eastman <je...@narus.com> wrote:
> >
> > > You mean you are seeing the same clusters as clusters-0 in all other
> > > clusters-i directories? That would indeed be a huge bug! I will
> > investigate.
> > >
> > > -----Original Message-----
> > > From: Jose Fuentes De Frutos [mailto:infjfd00@udc.es]
> > > Sent: Thursday, April 07, 2011 3:59 AM
> > > To: user@mahout.apache.org
> > > Subject: FuzzyKMeans in distributed execution
> > >
> > > Hello!,
> > >
> > > I'm working with the latest release of the Mahout (trunk version) and I
> > > have a problem with the FuzzyKMeans algorithm in distributed mode. I
> > printed
> > > the clusters in each iteration of the algorithm and I think that the
> > > algorithm always save the initial clusters, consequently the results
> are
> > the
> > > same independently of the number of iterations.
> > >
> > > Am I doing something wrong, or we are talking about a bug?
> > >
> > > Thank you.
> > >
> > >
> > >
> >
> >
> > --
> > John Abbott
> > Co-Founder
> > www.oobafit.com
> > m. 44 (0)7919392754
> > @scmjea
> >
>
--
John Abbott
Co-Founder
www.oobafit.com
m. 44 (0)7919392754
@scmjea
Re: Returning number of points in KMeans
Posted by Robin Anil <ro...@gmail.com>.
Once you create the clusters, you need to assign the points to the nearest
cluster based on your distance measure. You just need to iterate and assign
it
Robin
On Thu, Apr 7, 2011 at 10:17 PM, Jeff Eastman <je...@narus.com> wrote:
> Looks like you are running the in-memory implementation. I can investigate
> some this weekend but you'll get quicker results by single-stepping in your
> debugger. It's not obvious what's going on here.
>
> If you want to contribute your distance measure, create a Jira for it and
> add a patch file. It does seem like an interesting distance measure.
>
> Jeff
>
> -----Original Message-----
> From: john abbott [mailto:abbottje@gmail.com]
> Sent: Thursday, April 07, 2011 9:30 AM
> To: user@mahout.apache.org
> Subject: Re: Returning number of points in KMeans
>
> Hi,
>
> I was wondering whether someone on this list might be able to help with
> some
> code I'm running. I'm a newbie who's been working with Mahout for a few
> weeks and working my way through the Mahout in Action Book. My issue is
> with KMeans. I can create clusters fine but cannot retrieve the number of
> points in each cluster from my Cluster objects.
>
> Here my code
>
> ...
>
> List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
> clusters, new GeoDistanceMeasure(), 100, t2);
>
> for (Iterator iterator = myClust.iterator(); iterator.hasNext();) {
>
> List clustersList = (List) iterator.next();
>
> for (Iterator iterator2 = clustersList.iterator(); iterator2.hasNext();)
> {
>
> Cluster finalCluster = (Cluster) iterator2.next();
>
> //if(finalCluster.isConverged()){
>
> ClusterObservations obs = finalCluster.getObservations();
>
> System.out.print("S0 is "+obs.getS0());
>
> System.out.print(" Count "+finalCluster.count());
>
> System.out.print(" ID is "+finalCluster.getIdentifier());
>
> System.out.print(" Number points "+finalCluster.getNumPoints());
>
> System.out.print("Size is "+finalCluster.getCenter().size());
>
> System.out.println("Lat "+finalCluster.getCenter().get(0)+" Long"
> +finalCluster.getCenter().get(1));
>
> ...
>
>
> And here is the output:
>
> S0 is 0.0 Count 0 ID is CL-0 Number points 0Size is 2Lat 51.5015202264285
> Long-0.17545441392857
>
> S0 is 0.0 Count 0 ID is CL-1 Number points 0Size is 2Lat 50.967885199444495
> Long-1.3534804972222
>
> S0 is 0.0 Count 0 ID is CL-2 Number points 0Size is 2Lat 50.96263126
> Long-1.3584173975
>
> S0 is 0.0 Count 0 ID is CL-3 Number points 0Size is 2Lat 50.973428999999996
> Long-1.3687605
> S0 is 0.0 Count 0 ID is CL-4 Number points 0Size is 2Lat 50.93504983
> Long-1.46711701
>
> I'd really like to know the number of points within each cluster.
>
>
> Also I have written a GeoDistanceMeasure class that calculates distances
> using the Haversine method and takes Latitude and Longitude as inputs. I'd
> really like to contribute it back if people thought it was
> interesting/useful and walked me through how I might do that.
>
> Thanks very much in advance,
>
> John
>
> On Thu, Apr 7, 2011 at 4:38 PM, Jeff Eastman <je...@narus.com> wrote:
>
> > You mean you are seeing the same clusters as clusters-0 in all other
> > clusters-i directories? That would indeed be a huge bug! I will
> investigate.
> >
> > -----Original Message-----
> > From: Jose Fuentes De Frutos [mailto:infjfd00@udc.es]
> > Sent: Thursday, April 07, 2011 3:59 AM
> > To: user@mahout.apache.org
> > Subject: FuzzyKMeans in distributed execution
> >
> > Hello!,
> >
> > I'm working with the latest release of the Mahout (trunk version) and I
> > have a problem with the FuzzyKMeans algorithm in distributed mode. I
> printed
> > the clusters in each iteration of the algorithm and I think that the
> > algorithm always save the initial clusters, consequently the results are
> the
> > same independently of the number of iterations.
> >
> > Am I doing something wrong, or we are talking about a bug?
> >
> > Thank you.
> >
> >
> >
>
>
> --
> John Abbott
> Co-Founder
> www.oobafit.com
> m. 44 (0)7919392754
> @scmjea
>
RE: Returning number of points in KMeans
Posted by Jeff Eastman <je...@Narus.com>.
Looks like you are running the in-memory implementation. I can investigate some this weekend but you'll get quicker results by single-stepping in your debugger. It's not obvious what's going on here.
If you want to contribute your distance measure, create a Jira for it and add a patch file. It does seem like an interesting distance measure.
Jeff
-----Original Message-----
From: john abbott [mailto:abbottje@gmail.com]
Sent: Thursday, April 07, 2011 9:30 AM
To: user@mahout.apache.org
Subject: Re: Returning number of points in KMeans
Hi,
I was wondering whether someone on this list might be able to help with some
code I'm running. I'm a newbie who's been working with Mahout for a few
weeks and working my way through the Mahout in Action Book. My issue is
with KMeans. I can create clusters fine but cannot retrieve the number of
points in each cluster from my Cluster objects.
Here my code
...
List<List<Cluster>> myClust = KMeansClusterer.clusterPoints(vectors,
clusters, new GeoDistanceMeasure(), 100, t2);
for (Iterator iterator = myClust.iterator(); iterator.hasNext();) {
List clustersList = (List) iterator.next();
for (Iterator iterator2 = clustersList.iterator(); iterator2.hasNext();)
{
Cluster finalCluster = (Cluster) iterator2.next();
//if(finalCluster.isConverged()){
ClusterObservations obs = finalCluster.getObservations();
System.out.print("S0 is "+obs.getS0());
System.out.print(" Count "+finalCluster.count());
System.out.print(" ID is "+finalCluster.getIdentifier());
System.out.print(" Number points "+finalCluster.getNumPoints());
System.out.print("Size is "+finalCluster.getCenter().size());
System.out.println("Lat "+finalCluster.getCenter().get(0)+" Long"
+finalCluster.getCenter().get(1));
...
And here is the output:
S0 is 0.0 Count 0 ID is CL-0 Number points 0Size is 2Lat 51.5015202264285
Long-0.17545441392857
S0 is 0.0 Count 0 ID is CL-1 Number points 0Size is 2Lat 50.967885199444495
Long-1.3534804972222
S0 is 0.0 Count 0 ID is CL-2 Number points 0Size is 2Lat 50.96263126
Long-1.3584173975
S0 is 0.0 Count 0 ID is CL-3 Number points 0Size is 2Lat 50.973428999999996
Long-1.3687605
S0 is 0.0 Count 0 ID is CL-4 Number points 0Size is 2Lat 50.93504983
Long-1.46711701
I'd really like to know the number of points within each cluster.
Also I have written a GeoDistanceMeasure class that calculates distances
using the Haversine method and takes Latitude and Longitude as inputs. I'd
really like to contribute it back if people thought it was
interesting/useful and walked me through how I might do that.
Thanks very much in advance,
John
On Thu, Apr 7, 2011 at 4:38 PM, Jeff Eastman <je...@narus.com> wrote:
> You mean you are seeing the same clusters as clusters-0 in all other
> clusters-i directories? That would indeed be a huge bug! I will investigate.
>
> -----Original Message-----
> From: Jose Fuentes De Frutos [mailto:infjfd00@udc.es]
> Sent: Thursday, April 07, 2011 3:59 AM
> To: user@mahout.apache.org
> Subject: FuzzyKMeans in distributed execution
>
> Hello!,
>
> I'm working with the latest release of the Mahout (trunk version) and I
> have a problem with the FuzzyKMeans algorithm in distributed mode. I printed
> the clusters in each iteration of the algorithm and I think that the
> algorithm always save the initial clusters, consequently the results are the
> same independently of the number of iterations.
>
> Am I doing something wrong, or we are talking about a bug?
>
> Thank you.
>
>
>
--
John Abbott
Co-Founder
www.oobafit.com
m. 44 (0)7919392754
@scmjea