我正在使用维度超过10,000的数据集。要使用Weka,我需要将文本文件转换为ARFF格式,但由于即使在使用稀疏ARFF格式后文件太大也存在太多属性。是否有与数据类似的方法,以避免在ARFF文件的头文件中写入如此多的属性标识符。
例如:
@attribute A1 NUMERICAL
@attribute A2 NUMERICAL
...
...
@attribute A10000 NUMERICAL
答案 0 :(得分:0)
我在AWK中编写了一个脚本,将以下行(在TXT文件中)格式化为ARFF
example.txt source:
Att_0 | Att_1 | Att_2 | ... | Att_n
1 | 2 | 3 | ... | 999
我的脚本(to_arff),您可以根据TXT文件中使用的分隔符更改FS值:
#!/usr/bin/awk -f
# ./<script>.awk data.txt > data.arff
BEGIN {
FS = "|";
# WEKA separator
separator = ",";
}
# The first line
NR == 1 {
# WEKA headers
split(FILENAME, relation, ".");
# the relation's name is the source file's name
print "@RELATION "relation[1]"\n";
# attributes are "numeric" by default
# types available: numeric, <nominal> {n1, n2, ..., nN}, string and date [<date-format>]
for (i = 1; i <= NF; i++) {
print "@ATTRIBUTE "$i" NUMERIC";
}
print "\n@DATA";
}
NR > 1 {
s = "";
first = 1;
for (i = 1; i <= NF; i++) {
if (first)
first = 0;
else
s = s separator;
s = s $i;
}
print s;
}
输出:
@RELATION example
@ATTRIBUTE Att_0 NUMERIC
@ATTRIBUTE Att_1 NUMERIC
@ATTRIBUTE Att_2 NUMERIC
@ATTRIBUTE Att_n NUMERIC
@DATA
1,2,3,9999