I took a second look at Tribuo published by Oracle. Tribuo --A Java prediction library (v4.0)

Postscript 2020/09/28 This article is out of date. I have reorganized it here. https://qiita.com/jashika/items/d7c86dd8053379fd909f

Preface

I have a lot of thoughts, but even if I just complain, it doesn't start. Rather, I will make this, so Oracle will hire me. Please give me.

About materials

See here for the original story. If you need Japanese, please see here. Click here to download the data.

Move somehow

Download bezdekIris.data.

Transfer the sample code from the manual Gatting Started to a Java file. Because it's not new, I'm not surprised at all. If such a variable is not defined, you will get angry with an error.

image.png

I defined DataSource

image.png MutableDataset (testData) gets angry if there is no MutableDataset # get () method. ~~ If it is an Oracle class, it can be called without any method. Absolutely test ry ~~

image.png Is it around #getData () that seems to be connected to testData # hoge # get (0)? Let's use getData () for the time being.

image.png

I get angry if there is no LabelEvaluation # evaluate (Model

image.png However, there is not even a method with a similar name that receives Model and MutableDataset as arguments and returns Evaluation. ~~ I think it's a genius to call with this. As expected, Oracle ~~ Probably, you have to create an instance of LabelEvaluator instead of creating an instance of LabelEvaluation. surely. I'm guessing. The argument, method name, and return value type match.

image.png

Hmm. Cast it ~~ suitable ~~. With this, the error disappeared.

TribuoSample


/**
 *
 */
package org.project.eden.adam;

import java.io.IOException;
import java.nio.file.Paths;

import org.tribuo.DataSource;
import org.tribuo.Model;
import org.tribuo.MutableDataset;
import org.tribuo.Prediction;
import org.tribuo.classification.Label;
import org.tribuo.classification.LabelFactory;
import org.tribuo.classification.dtree.CARTClassificationTrainer;
import org.tribuo.classification.evaluation.LabelEvaluation;
import org.tribuo.classification.evaluation.LabelEvaluator;
import org.tribuo.classification.sgd.linear.LogisticRegressionTrainer;
import org.tribuo.data.csv.CSVLoader;
import org.tribuo.evaluation.Evaluation;
import org.tribuo.evaluation.TrainTestSplitter;

/**
 * @author jashika
 *
 */
public class TribuoSample {

    /**
     * @param args main method arguments.
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        //Labeled iris(Iris)Read data
        var irisHeaders = new String[] { "sepalLength", "sepalWidth", "petalLength", "petalWidth", "species" };
        DataSource<Label> irisData = new CSVLoader<>(new LabelFactory()).loadDataSource(Paths.get("/Users/admin/Downloads/bezdekIris.data"),irisHeaders[4],irisHeaders);

        //iris(Iris)Data training set(70%)And test set(30%)Divided into
        var splitIrisData = new TrainTestSplitter<>(irisData, 0.7, 1L);

        var trainData = new MutableDataset<>(splitIrisData.getTrain());
        var testData = new MutableDataset<>(splitIrisData.getTest());

        //Learn decision trees
        var cartTrainer = new CARTClassificationTrainer();
        Model<Label> tree = cartTrainer.train(trainData);

        //Logistic regression
        var linearTrainer = new LogisticRegressionTrainer();
        Model<Label> linear = linearTrainer.train(trainData);

        //Ultimately, make predictions from invisible data
        //Each prediction is scored from the output name (label)/Map to probability
        Prediction<Label> prediction = linear.predict(testData.getData().get(0));

        //The complete test dataset may be evaluated to calculate accuracy, F1, etc.
        Evaluation<Label> evaluation = new LabelEvaluator().evaluate(linear, testData);

        //Inspect manual evaluation.
        double acc = LabelEvaluation.class.cast(evaluation).accuracy();

        //Display the formatted evaluation string.
        System.out.println(evaluation.toString());
    }
}

I will try it. Is line 151 only one element? image.png

Blank line···. Isn't the blank line ignored? Is there any resentment because it is an LF line break? Apart from that, it's okay to ignore this, right? It's not a violation of CSV rules.

image.png

I deleted it from the data file. manually. image.png

Run again. Something like that came out. I will add a little more detail later. ~~ Maybe. ~~ image.png

Recommended Posts

I took a second look at Tribuo published by Oracle. Tribuo --A Java prediction library (v4.0)
I tried Tribuo published by Oracle. Tribuo --A Java prediction library (v4.0)
I touched Tribuo published by Oracle. Document Tribuo --A Java prediction library (v4.0)
I touched Tribuo published by Oracle. Document Tribuo --A Java prediction library (v4.0)
I tried Tribuo published by Oracle. Tribuo --A Java prediction library (v4.0)
I took a second look at Tribuo published by Oracle. Tribuo --A Java prediction library (v4.0)
I took a look at the resources of Azure Container Instance
A look at Jenkins, OpenJDK 8 and Java 11
I took a quick look at how WebView's Javascript Interface is called when using OkHttp.