Reputation: 782
I've been following this tutorial on how to use WEKA and I have reached a point where my code will not run. I realize that I am using a different version of Weka 3.8 as opposed to 3.6 as shown in the tutorial but I thought I made the necessary changes. I get an error message on the line linearRegression.buildClassifier(dataset);
and I don't know why.
Error message:
Jul 19, 2016 10:47:21 AM com.github.fommil.netlib.BLAS <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeSystemBLAS
Jul 19, 2016 10:47:21 AM com.github.fommil.netlib.BLAS <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeRefBLAS
Jul 19, 2016 10:47:21 AM com.github.fommil.netlib.LAPACK <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeSystemLAPACK
Jul 19, 2016 10:47:21 AM com.github.fommil.netlib.LAPACK <clinit>
WARNING: Failed to load implementation from: com.github.fommil.netlib.NativeRefLAPACK
Code:
// Define each attribute (or column), and give it a numerical column
// number
// Likely, a better design wouldn't require the column number, but
// would instead get it from the index in the container
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);
// Each element must be added to a FastVector, a custom
// container used in this version of Weka.
// Later versions of Weka corrected this mistake by only
// using an ArrayList
ArrayList<Attribute> attrs = new ArrayList<>();
attrs.add(a1);
attrs.add(a2);
attrs.add(a3);
attrs.add(a4);
attrs.add(a5);
attrs.add(a6);
// Each data instance needs to create an Instance class
// The constructor requires the number of columns that
// will be defined. In this case, this is a good design,
// since you can pass in empty values where they exist.
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);
i1.setValue(a1, 3247);
i1.setValue(a2, 10061);
i1.setValue(a3, 5);
i1.setValue(a4, 1);
i1.setValue(a5, 1);
i1.setValue(a6, 224900);
Instance i3 = new DenseInstance(6);
i1.setValue(a1, 4032);
i1.setValue(a2, 10150);
i1.setValue(a3, 5);
i1.setValue(a4, 0);
i1.setValue(a5, 1);
i1.setValue(a6, 197900);
Instance i4 = new DenseInstance(6);
i1.setValue(a1, 2397);
i1.setValue(a2, 14156);
i1.setValue(a3, 4);
i1.setValue(a4, 1);
i1.setValue(a5, 0);
i1.setValue(a6, 189900);
Instance i5 = new DenseInstance(6);
i1.setValue(a1, 2200);
i1.setValue(a2, 9600);
i1.setValue(a3, 4);
i1.setValue(a4, 0);
i1.setValue(a5, 1);
i1.setValue(a6, 195000);
Instance i6 = new DenseInstance(6);
i1.setValue(a1, 3536);
i1.setValue(a2, 19994);
i1.setValue(a3, 6);
i1.setValue(a4, 1);
i1.setValue(a5, 1);
i1.setValue(a6, 325000);
Instance i7 = new DenseInstance(6);
i1.setValue(a1, 2983);
i1.setValue(a2, 9365);
i1.setValue(a3, 5);
i1.setValue(a4, 0);
i1.setValue(a5, 1);
i1.setValue(a6, 230000);
// Each Instance has to be added to a larger container, the
// Instances class. In the constructor for this class, you
// must give it a name, pass along the Attributes that
// are used in the data set, and the number of
// Instance objects to be added. Again, probably not ideal design
// to require the number of objects to be added in the constructor,
// especially since you can specify 0 here, and then add Instance
// objects, and it will return the correct value later (so in
// other words, you should just pass in '0' here)
Instances dataset = new Instances("housePrices", attrs, 7);
dataset.add(i1);
dataset.add(i2);
dataset.add(i3);
dataset.add(i4);
dataset.add(i5);
dataset.add(i6);
dataset.add(i7);
// In the Instances class, we need to set the column that is
// the output (aka the dependent variable). You should remember
// that some data mining methods are used to predict an output
// variable, and regression is one of them.
dataset.setClassIndex(dataset.numAttributes() - 1);
// Create the LinearRegression model, which is the data mining
// model we're using in this example
linearRegression = new LinearRegression();
try {
// This method does the "magic", and will compute the regression
// model. It takes the entire dataset we've defined to this point
// When this method completes, all our "data mining" will be
// complete
// and it is up to you to get information from the results
linearRegression.buildClassifier(dataset);
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 3
Views: 3862
Reputation: 9285
That is not an error, but a warning. Weka cannot find some Linear Algebra Libraries (LAPACK, BLAS) during the startup of your little java app. It does not need them anyway, for the linear regression task of fitting a curve to 7 data points.
(Read this for reference https://github.com/fommil/netlib-java)
To get rid of the message, you can redirect the STDERR output of your program to /dev/null .
Using the Package Manager, I just installed the Weka Package netlibNativeLinux
(or try netlibNativeWindows or netlibOSX, whatever), included its jars to the build-path, and got this warning:
Jul 20, 2016 10:20:32 AM com.github.fommil.jni.JniLoader liberalLoad
INFO: successfully loaded /tmp/jniloader5044252696376965086netlib-native_system-linux-x86_64.so
Jul 20, 2016 10:20:32 AM com.github.fommil.jni.JniLoader load
INFO: already loaded netlib-native_system-linux-x86_64.so
I also got the output 219328.35717359098
- just as the tutorial said. Did you forget to include the last lines of codes from the tutorial, especially
System.out.println(myHouseValue);
?
Upvotes: 4