Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: help me in this problem related to ml-java

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question help me in this problem related to ml-java

    I have a problem can any one help me?

    When I using machine learning library for java (ml-java) for KNN cluster:
    I have a 2D array of features (double type), so to use the ml-java I should convert it to dataset datatype
    to do this I convert each record in the features array into instance and I add this instance to dataset
    but when I print the dataset data I found the following :
    {[0.893139842, 0.550304878, 0.536294691, 0.0, 0.321348315, 0.732189974, 0.0, 0.0, 0.0, 0.0, 0.0];null}

    this null value come when I convert the feature records into instance which represent the label of record, so I hava error when I apply the KNN code :

    Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
    at net.sf.javaml.classification.evaluation.CrossValid ation.crossValidation(CrossValidation.java:66)
    at net.sf.javaml.classification.evaluation.CrossValid ation.crossValidation(CrossValidation.java:111)
    at net.sf.javaml.classification.evaluation.CrossValid ation.crossValidation(CrossValidation.java:126)
    at multiapp.jButton1ActionPerformed(multiapp.java:468 )
    at multiapp.access$100(multiapp.java:39)
    at multiapp$2.actionPerformed(multiapp.java:121)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6505)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:627 0)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:703)
    at java.awt.EventQueue.access$000(EventQueue.java:102 )
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:676)
    at java.awt.EventQueue$4.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 673)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)




    how can I eliminate the null value from the dataset or any way to solve this problem????????/


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,181
    My Mood
    Hungover
    Thanks
    141
    Thanked 602 Times in 517 Posts

    Default Re: help me in this problem related to ml-java

    I'm not sure how you expect us to help you with the information you've provided. We have no idea what's in the original array or how you're converting it. What value in the original array leads to a null in your output?

    If you want help, you'll have to throw together an SSCCE (as few lines as possible) that demonstrates exactly what you're doing to lead to the problem.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help me in this problem related to ml-java

    Ok this is the code of my program:
    double [][]features=new double[data3.size()][11]; // The array that contains the features of all samples , where number of samples equal data3.size()


    Dataset data = new DefaultDataset();

    for (int i=0;i<data3.size();i++)
    {
    double []inst_feature=new double[11];
    System.arraycopy(features[0], 0, inst_feature, 0, 11);
    Instance instance = new DenseInstance(inst_feature) ;
    data.add(instance);
    }
    After that I applied KNN code on the dataset
    KNearestNeighbors knn = new KNearestNeighbors(5);
    CrossValidation cv = new CrossValidation(knn);
    knn.buildClassifier(data);
    Map<Object, PerformanceMeasure> p = cv.crossValidation(data); // the problem appear here


    This code I study it from this site
    Classification cross validation | Java Machine Learning Library (Java-ML)
    Creating an Instance | Java Machine Learning Library (Java-ML)
    Creating a Dataset | Java Machine Learning Library (Java-ML)

Similar Threads

  1. Replies: 2
    Last Post: September 23rd, 2011, 11:54 AM
  2. Doubt related to Java
    By Jagatha in forum Member Introductions
    Replies: 1
    Last Post: September 15th, 2011, 04:21 AM
  3. Layout related problem
    By Gaurav18 in forum Member Introductions
    Replies: 3
    Last Post: September 14th, 2011, 05:12 AM
  4. problem related combobox nd database
    By harsimran in forum Java Theory & Questions
    Replies: 1
    Last Post: September 9th, 2011, 02:27 PM
  5. Swing problem, newbie'ish . Perhaps thread related?
    By fenderman in forum AWT / Java Swing
    Replies: 3
    Last Post: July 22nd, 2009, 04:45 AM