您的位置:首页 > 其它

在多标签分类中,准备mulan开源软件所需要的.arff和.xml数据的方法

2014-05-27 14:00 253 查看
最近在工作中需要学习多标签分类的算法,发现了mulan这个开源软件很不错,这个软件是用java编写的,同时也是建立在Weka之上的。这个软件需要输入两个文件,一个是.arff文件,一个是.xml文件。

预备软件:matlab和Weka,;

.arrf文件的格式如下:

@relation MultiLabelExample

@attribute feature1 numeric
@attribute feature2 numeric
@attribute feature3 numeric
@attribute label1 {0, 1}
@attribute label2 {0, 1}
@attribute label3 {0, 1}
@attribute label4 {0, 1}
@attribute label5 {0, 1}

@data
2.3,5.6,1.4,0,1,1,0,0
2.0,1.3,2.6,0,1,0,0,1


.xml文件的格式如下:

<?xml version="1.0" encoding="utf-8"?>
<labels xmlns="http://mulan.sourceforge.net/labels">
<label name="label1"></label>
<label name="label2"></label>
<label name="label3"></label>
<label name="label4"></label>
<label name="label5"></label>
</labels>


生成这两种文件的方法如下:

(1)首先采用matlab中自带的函数csvwrite('filename.csv',fliename)生成.csv文件,其中filename.csv是你要生成的文

件名字,filename是在matlab中的矩阵名字,矩阵的每行代表一个样本;例如:

csvwrite('MultiLabelExample.csv',MultiLabelExample),

MultiLabelExample= [2.3,5.6,1.4,0,1,1,0,0;2.0,1.3,2.6,0,1,0,0,1],假设只有两个样本

(2)将生成的filename.csv用excel或者EditPlus打开将相应的属性名填写好,采用都好隔开(最好是采用程序修改,

如果数据的维数很高的时候,采用手动修改工作量很大);例如:

feature1 ,feature2,featuer3,label1,label2,label3,label4,label5(注意这些名字都可以根据自己需要进行修改)

2.3,5.6,1.4,0,1,1,0,0

2.0,1.3,2.6,0,1,0,0,1

(3)运行Weka程序,选择Simple SLI按钮,在出现的对话框最下面一行输入:

weka.core.converters.CSVLoader MultiLabelExample.csv
> MultiLabelExample.arff,结果如下:

@relation MultiLabelExample

@attribute feature1 numeric
@attribute feature2 numeric
@attribute feature3 numeric
@attribute label1 numeric
@attribute label2 numeric
@attribute label3 numeric
@attribute label4 numeric
@attribute label5 mumeric

@data
2.3,5.6,1.4,0,1,1,0,0
2.0,1.3,2.6,0,1,0,0,1


手动修改label1-5 后边的“numeric”为{0,1},结果如下:(实际情况应该是自动生成下面的结果的,但是本人始终

没有实现,因此手动修改)

@relation MultiLabelExample

@attribute feature1 numeric
@attribute feature2 numeric
@attribute feature3 numeric
@attribute label1 {0, 1}
@attribute label2 {0, 1}
@attribute label3 {0, 1}
@attribute label4 {0, 1}
@attribute label5 {0, 1}

@data
2.3,5.6,1.4,0,1,1,0,0
2.0,1.3,2.6,0,1,0,0,1


这样.arff文件已经完成的了。

(4)对于.xml格式文件,本人没有找到更好的方法,采用手动修改很容易就可以实现。

<?xml version="1.0" encoding="utf-8"?>
<labels xmlns="http://mulan.sourceforge.net/labels">
<label name="label1"></label>
<label name="label2"></label>
<label name="label3"></label>
<label name="label4"></label>
<label name="label5"></label>
</labels>


这个文件中可以改变的有label1-label5这些名字(我尝试过),注意和.arff文件中的相应名字对应上,否者会出错

至此:mulan软件需要的两个输入文件就准备好了,如何进行实验将在下一章阐述。

—————本方法仅供参考,如果有不足之处请指正。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: