尝试在 Java AndroidStudio 中调用 .buildClassifier (Weka) 时出错
Error trying to call .buildClassifier (Weka) in Java AndroidStudio
我正在尝试在 Android Studio 中使用 Weka。我被困在这一行:
linearRegresion.buildClassifier(data);
其红色下划线表示:
Unhandled Exception:Java.lang.Exception
我正在尝试其他方式和不同的数据集,它总是在 .buildClassifier
处带有下划线
//test:
NaiveBayes nB = new NaiveBayes();
nB.buildClassifier(dataSet); //Unhandled exception
Classifier cModel = (Classifier)new LinearRegression();
cModel.buildClassifier(data); //Unhandled exception
尝试修复此问题数小时,在互联网上找不到解决方案,我想我只是遗漏了一些东西,也许我只需要导入更多东西?
我是在教程中这样做的,所以代码应该可以工作。教程:
http://www.ibm.com/developerworks/opensource/library/os-weka3/index.html
整个代码
import weka.*;
import weka.classifiers.trees.J48;
import weka.core.*;
import weka.classifiers.Classifier;
import weka.core.Instance;
import weka.core.Instances;
import weka.classifiers.functions.LinearRegression;
import weka.classifiers.bayes.NaiveBayes;
public class Meni extends Activity {
public void Weka(){
//@ATTRIBUTE houseSize NUMERIC
Attribute a1 = new Attribute("houseSize", 0);
Attribute a2 = new Attribute("lotSize", 1);
Attribute a3 = new Attribute("bedrooms", 2);
Attribute a4 = new Attribute("granite", 3);
Attribute a5 = new Attribute("bathroom", 4);
Attribute a6 = new Attribute("sellingPrice", 5);
//ArrayList attr = new ArrayList();
FastVector attrs = new FastVector();
attrs.addElement(a1);
attrs.addElement(a2);
attrs.addElement(a3);
attrs.addElement(a4);
attrs.addElement(a5);
attrs.addElement(a6);
//@DATA
Instance i1 = new DenseInstance(6);
i1.setValue(a1, 3529);
i1.setValue(a2, 9191);
i1.setValue(a3, 6);
i1.setValue(a4, 0);
i1.setValue(a5, 0);
i1.setValue(a6, 205000);
Instance i2 = new DenseInstance(6);
i2.setValue(a1, 3247);
i2.setValue(a2, 10061);
i2.setValue(a3, 5);
i2.setValue(a4, 1);
i2.setValue(a5, 1);
i2.setValue(a6, 224900);
Instance i3 = new DenseInstance(6);
i3.setValue(a1, 4032);
i3.setValue(a2, 10150);
i3.setValue(a3, 5);
i3.setValue(a4, 0);
i3.setValue(a5, 1);
i3.setValue(a6, 197900);
//set class Atribute
dataSet.setClassIndex(dataSet.numAttributes()-1);
//Creating model
LinearRegression linearRegresion = new LinearRegression();
linearRegresion.buildClassifier(data); //Unhandled exception :(
}
}
weka.jar 库有问题。我从 weka 站点下载的普通版本无法使用 android.Now 我从用户 rjmanrsan 下载了修改后的版本:
https://github.com/rjmarsan/Weka-for-Android
现在工作:)
我正在尝试在 Android Studio 中使用 Weka。我被困在这一行:
linearRegresion.buildClassifier(data);
其红色下划线表示:
Unhandled Exception:Java.lang.Exception
我正在尝试其他方式和不同的数据集,它总是在 .buildClassifier
处带有下划线 //test:
NaiveBayes nB = new NaiveBayes();
nB.buildClassifier(dataSet); //Unhandled exception
Classifier cModel = (Classifier)new LinearRegression();
cModel.buildClassifier(data); //Unhandled exception
尝试修复此问题数小时,在互联网上找不到解决方案,我想我只是遗漏了一些东西,也许我只需要导入更多东西?
我是在教程中这样做的,所以代码应该可以工作。教程: http://www.ibm.com/developerworks/opensource/library/os-weka3/index.html
整个代码
import weka.*;
import weka.classifiers.trees.J48;
import weka.core.*;
import weka.classifiers.Classifier;
import weka.core.Instance;
import weka.core.Instances;
import weka.classifiers.functions.LinearRegression;
import weka.classifiers.bayes.NaiveBayes;
public class Meni extends Activity {
public void Weka(){
//@ATTRIBUTE houseSize NUMERIC
Attribute a1 = new Attribute("houseSize", 0);
Attribute a2 = new Attribute("lotSize", 1);
Attribute a3 = new Attribute("bedrooms", 2);
Attribute a4 = new Attribute("granite", 3);
Attribute a5 = new Attribute("bathroom", 4);
Attribute a6 = new Attribute("sellingPrice", 5);
//ArrayList attr = new ArrayList();
FastVector attrs = new FastVector();
attrs.addElement(a1);
attrs.addElement(a2);
attrs.addElement(a3);
attrs.addElement(a4);
attrs.addElement(a5);
attrs.addElement(a6);
//@DATA
Instance i1 = new DenseInstance(6);
i1.setValue(a1, 3529);
i1.setValue(a2, 9191);
i1.setValue(a3, 6);
i1.setValue(a4, 0);
i1.setValue(a5, 0);
i1.setValue(a6, 205000);
Instance i2 = new DenseInstance(6);
i2.setValue(a1, 3247);
i2.setValue(a2, 10061);
i2.setValue(a3, 5);
i2.setValue(a4, 1);
i2.setValue(a5, 1);
i2.setValue(a6, 224900);
Instance i3 = new DenseInstance(6);
i3.setValue(a1, 4032);
i3.setValue(a2, 10150);
i3.setValue(a3, 5);
i3.setValue(a4, 0);
i3.setValue(a5, 1);
i3.setValue(a6, 197900);
//set class Atribute
dataSet.setClassIndex(dataSet.numAttributes()-1);
//Creating model
LinearRegression linearRegresion = new LinearRegression();
linearRegresion.buildClassifier(data); //Unhandled exception :(
} }
weka.jar 库有问题。我从 weka 站点下载的普通版本无法使用 android.Now 我从用户 rjmanrsan 下载了修改后的版本: https://github.com/rjmarsan/Weka-for-Android 现在工作:)