0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Java初心者】Wekaによる機械学習 11-ファイルを作らずArffデータ作成(簡易版)

0
Posted at

前回難しくやりすぎました

前回( https://qiita.com/SeijiMiwa/items/0e241c22cee1bcf2d91d )の記事で、ArffデータをJavaコードで作る方法を書きましたが、あそこまで面倒な方法を取らなくても作れることがわかりました。

実際のコード

今回もmini-wekaを使っています。

import java.util.ArrayList;
import java.util.List;
import weka.core.Attribute;
import weka.core.Instances;

public class easyArff {

    public static void main(String[] args) {
        Attribute a1 = new Attribute("1つ目のATTR_numeric"); // 数値
        Attribute a2 = new Attribute("2つ目のATTR_class", List.of("A", "B", "C")); // クラス分け
        Attribute a3 = new Attribute("3つ目のATTR_string", true); //文字列
        Attribute a4 = new Attribute("4つ目のATTR_date", "yyyy/MM/dd"); // 日付

        ArrayList<Attribute> attrs = new ArrayList<>();
        attrs.add(a1);
        attrs.add(a2);
        attrs.add(a3);
        attrs.add(a4);
        Instances dataset = new Instances("ARFFの説明", attrs, 0);

        System.out.println(dataset);
    }
}

実行結果

@relation ARFFの説明

@attribute 1つ目のATTR_numeric numeric
@attribute 2つ目のATTR_class {A,B,C}
@attribute 3つ目のATTR_string string
@attribute 4つ目のATTR_date date yyyy/MM/dd

@data

データはコードで真面目に入れてもいいし、テキストを流し込んでもいいかもしれません

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?