ARFF文件结构解析

Attribute-Relation File Format (ARFF)

ARFF文件是一种ASCLL 文件类型,它描述了实例列表的一系列属性。ARFF文件随着University of Waikato大学计算机科学的发展而被用在机器学习软件Weka上。介绍ARFF文件结构的网址 http://www.cs.waikato.ac.nz/~ml/weka/arff.html

 

ARFF文件格式:

%为注释符号,文件开头一般会以注释开头,介绍文件的名称,属性特征等内容。

关系名,在文件开头定义,格式为:

@relation <relation-name>

关系名为字符串类型,如果名称中含有空格,必须加引号。

接下来是属性定义区,结构为:

@attribute <attribute-name> <datatype>

属性共包含名词性属性、数值性属性、字符串属性和日期属性。在名词性属性用括号{}包含其名词性值。如果名词性值内包含空格,必须加引号。数值属性的数据类型为:numeric; 字符串属性的数据类型为:string;日期属性是特殊形式的字符串,其数据类型为:date [<date-format>]    ,默认时间格式为:

"yyyy-MM-dd'T'HH:mm:ss"。

属性声明的顺序显示在文件的数据部分的列的位置,其后数据区的数据会按属性声明顺序排列。

之后以@data开始的行,是数据集中实例数据开始的标志。

每一行表示一个实例,属性值按照属性的顺序排列,并由逗号分隔,回车表示实例的结束。如果有残缺值,将由?表示,如:

4.4, ?, 1.5, ?, Iris-setosa

如果是稀疏数据,即大部分实例中的属性值为0,可以用非0属性的属性位置和属性值表明。如:

0,26,0, 0, 0, 0,63,0, 0, 0,”class A”

{1 26, 6 63, 10 “class A”}

ARFF文件格式很简单,从Weka里面都可以找到一些它的例子。

(1)天气数据

%ARFF file for the weather data with some numeric features

%

@relation weather

@attribute outlook {sunny, overcast, rainy}

@attribute temperature real

@attribute humidity real

@attribute windy {TRUE, FALSE}

@attribute play?{yes, no}

@data

%

%14 instance

%

sunny,85,85,FALSE,no

sunny,80,90,TRUE,no

overcast,83,86,FALSE,yes

rainy,70,96,FALSE,yes

rainy,68,80,FALSE,yes

rainy,65,70,TRUE,no

overcast,64,65,TRUE,yes

sunny,72,95,FALSE,no

sunny,69,70,FALSE,yes

rainy,75,80,FALSE,yes

sunny,75,70,TRUE,yes

overcast,72,90,TRUE,yes

overcast,81,75,FALSE,yes

rainy,71,91,TRUE,no

(2)鸢尾属植物数据

% 1. Title: Iris Plants Database

%

% 2. Sources:

% (a) Creator: R.A. Fisher

% (b) Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)

% (c) Date: July, 1988

%

@RELATION iris

@ATTRIBUTE sepallength  NUMERIC

@ATTRIBUTE sepalwidth   NUMERIC

@ATTRIBUTE petallength  NUMERIC

@ATTRIBUTE petalwidth   NUMERIC

@ATTRIBUTE class  {Iris-setosa,Iris-versicolor,Iris-virginica} 

@DATA

5.1,3.5,1.4,0.2,Iris-setosa

4.9,3.0,1.4,0.2,Iris-setosa

4.7,3.2,1.3,0.2,Iris-setosa

4.6,3.1,1.5,0.2,Iris-setosa

5.0,3.6,1.4,0.2,Iris-setosa

5.4,3.9,1.7,0.4,Iris-setosa

4.6,3.4,1.4,0.3,Iris-setosa

5.0,3.4,1.5,0.2,Iris-setosa

4.4,2.9,1.4,0.2,Iris-setosa

4.9,3.1,1.5,0.1,Iris-setosa

(3)时间数据

@RELATION Timestamps

@ATTRIBUTE timestamp DATE "yyyy-MM-dd HH:mm:ss"

@DATA

"2001-04-03 12:12:12"

"2001-05-03 12:59:55"

Weka作为数据挖掘开源项目中的经典,很多算法和数据的组织结构是值得学习的。Weka里面大量使用了一种叫做ARFF (Attribute-Relation File Format )的数据文件结构。这种ARFF文件内部结构很简单,主要是测试算法使用的轻量级的数据文件结构。OpenMiner继承Weka的风格,也打算支持ARFF文件格式,并且作为前期的挖掘算法测试数据来源。

“If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.”
原文地址:https://www.cnblogs.com/Scorpio989/p/3959572.html