Perform linear regression on data (from .arff file) - JAVA, Weka
I want to perform linear regression on a dataset using Java. I have a couple of questions.
-
what datatypes are allowed by linear regression method? Because I tried to load data in pure nominal format as well as numeric, but then when I try to pass this "data" (an instance variable created in the program) to Linear Regression it gives me this exception. You cannot handle a nominal class with multiple values
-
How can I print linear regression output to console in java. I can't create the code to do this by going through the predefined LinearRegression.java class, I found out that buildClassifier () is a method that takes "data" as an input file. But then I cannot move forward. Can anyone help me understand the sequence of steps to follow in order to be able to output to the console.
protected static void useLinearRegression(Instances data) throws Exception{ BufferedReader reader = new BufferedReader(new FileReader("c:\somePath\healthCare.arff")); Instances data = new Instances(reader); data1.setClassIndex(data1.numAttributes() - 1); LinearRegression2 rl=new LinearRegression2(); rl.buildClassifier(data); //What after this? or before
source to share
-
Linear regression must accept both nominal and numeric data types. It's just that the target class cannot be a nominal data type.
-
The toString () method should be able to spit out the model (depending on your use, different needs classifier parameters may be required), but if you are also after predictions and summaries, you may also need an evaluator. There you can use toSummaryString () or toMatrixString () to get other statistics about the model that was generated.
Hope it helps!
source to share