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????????/
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.
Re: help me in this problem related to ml-java
Ok this is the code of my program:
Quote:
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
Quote:
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)