1

I am new into using moa and I am having a hard time trying to decode how the clustering algorithms have to be used. The documentation lacks of sample code for common usages, and the implementation is not well explained with comments ... have not found any tutorial either.

So, here is my code:

import com.yahoo.labs.samoa.instances.DenseInstance;
import moa.cluster.Clustering;
import moa.clusterers.denstream.WithDBSCAN;

public class TestingDenstream {
    static DenseInstance randomInstance(int size) {
        DenseInstance instance = new DenseInstance(size);
        for (int idx = 0; idx < size; idx++) {
            instance.setValue(idx, Math.random());
        }
        return instance;
    }
    public static void main(String[] args) {
        WithDBSCAN withDBSCAN = new WithDBSCAN();
        withDBSCAN.resetLearningImpl();
        for (int i = 0; i < 10; i++) {
            DenseInstance d = randomInstance(2);
            withDBSCAN.trainOnInstanceImpl(d);
        }
        Clustering clusteringResult = withDBSCAN.getClusteringResult();
        Clustering microClusteringResult = withDBSCAN.getMicroClusteringResult();

        System.out.println(clusteringResult);

    }
}

And here is the error I get:

enter image description here

Any insights into how the algorithm has to be used will be appreciated. Thanks!

onofricamila
  • 930
  • 1
  • 11
  • 20

1 Answers1

0

I have updated the code. It is working as I mentioned in the github, you have to assign header to your instance. See the github discussion

here is the updated code:

    static DenseInstance randomInstance(int size) {
        // generates the name of the features which is called as InstanceHeader
        ArrayList<Attribute> attributes = new ArrayList<Attribute>();
        for (int i = 0; i < size; i++) {
            attributes.add(new Attribute("feature_" + i));
        }
        // create instance header with generated feature name
        InstancesHeader streamHeader = new InstancesHeader(
                new Instances("Mustafa Çelik Instance",attributes, size));

        // generates random data
        double[] data = new double[2];
        Random random = new Random();
        for (int i = 0; i < 2; i++) {
            data[i] = random.nextDouble();
        }

        // creates an instance and assigns the data
        DenseInstance inst = new DenseInstance(1.0, data);

        // assigns the instanceHeader(feature name)
        inst.setDataset(streamHeader);

        return inst;
    }

    public static void main(String[] args) {
        WithDBSCAN withDBSCAN = new WithDBSCAN();
        withDBSCAN.resetLearningImpl();
        withDBSCAN.initialDBScan();
        for (int i = 0; i < 1500; i++) {
            DenseInstance d = randomInstance(5);

            withDBSCAN.trainOnInstanceImpl(d);
        }
        Clustering clusteringResult = withDBSCAN.getClusteringResult();
        Clustering microClusteringResult = withDBSCAN.getMicroClusteringResult();

        System.out.println(clusteringResult);
    }

here is the screenshot of debug process, as you see the clustering result is generated:

debug screenshot image link is broken, you can find it on github github entry link

Celik
  • 2,311
  • 2
  • 32
  • 54
  • Well thanks! I continued the discussion [on github](https://github.com/Waikato/moa/issues/191#issuecomment-555208983) – onofricamila Nov 18 '19 at 21:07
  • @onofricamila why did you approve answer, then remove it? the code is working? – Celik Nov 19 '19 at 07:06
  • I do not know what happened. Of course I approved the answer, and I did not remove the approvation (maybe I did it without realizing it, because I also use stack overflow on my mobile - I may have touched the icon while scrolling) – onofricamila Nov 19 '19 at 15:06
  • Any ideas about the irregularities regarding some fields, which I mentioned on github? Thanks :) – onofricamila Nov 19 '19 at 15:10