【问题标题】:Weka linear regression doesn't loadWeka 线性回归不加载
【发布时间】:2016-07-20 16:32:48
【问题描述】:

我一直在关注this 关于如何使用WEKA 的教程,但我已经达到了我的代码无法运行的地步。我意识到我使用的是与教程中所示的 3.6 不同的 Weka 3.8 版本,但我认为我进行了必要的更改。我在linearRegression.buildClassifier(dataset); 线上收到一条错误消息,我不知道为什么。

错误信息:

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

代码:

// 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();
        }

    }

【问题讨论】:

    标签: java weka


    【解决方案1】:

    这不是错误,而是警告。 Weka 在您的小型 Java 应用程序启动期间找不到一些线性代数库(LAPACK、BLAS)。对于将曲线拟合到 7 个数据点的线性回归任务,它无论如何都不需要它们。

    (阅读本文以供参考https://github.com/fommil/netlib-java

    要摆脱该消息,您可以将程序的 STDERR 输出重定向到 /dev/null 。

    使用包管理器,我刚刚安装了 Weka 包 netlibNativeLinux(或尝试使用 netlibNativeWindows 或 netlibOSX 等),将其 jar 包含到构建路径中,并收到以下警告:

    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
    

    我也得到了输出219328.35717359098 - 正如教程所说的那样。您是否忘记包含教程中的最后几行代码,尤其是

    System.out.println(myHouseValue);

    ?

    【讨论】:

    • 我安装了这些软件包,现在我收到了您收到的信息消息,但它仍然不打印。是的,我有一份印刷声明。程序在显示该消息后立即停止,如果我在`linearRegression.buildClassifier(dataset);`之前和之后放置一个打印行,第一个将打印,但第二个不会表明该行发生了什么事。
    • 我的代码在这里gist.github.com/knbknb/c7f75d8eaa5b50a7b6786ca5f0fedbfb,它打印一个数字。在 linux 上的 weka3.8 上为我工作,尝试了 java7 (oracle jvm) 和 java8 openjdk。
    • 嗯,昨天你和我的 git hub 上的代码都不起作用,今天它们都起作用了,我真的不知道问题是什么
    猜你喜欢
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2015-01-24
    • 2021-06-04
    • 2015-01-21
    • 2021-06-06
    • 2017-11-04
    • 2020-05-04
    相关资源
    最近更新 更多