您的位置:首页 > 其它

【机器学习】libsvm使用的数据格式

2008-11-06 22:29 477 查看
该软件使用的训练数据和检验数据文件格式如下:

  <label> <index1>:<value1> <index2>:<value2> ...

  其中<label> 是训练数据集的目标值,对于分类,它是标识某类的整数(支持多个类);对于回归,是任意实数。<index> 是以1开始的整数,可以是不连续的;<value>为实数,也就是我们常说的自变量。检验数据文件中的label只用于计算准确度或误差,如果它是未知的,只需用一个数填写这一栏,也可以空着不填。在程序包中,还包括有一个训练数据实例:heart_scale,方便参考数据文件格式以及练习使用软件。



在NET.SVM中,Node和Problem类提供此项功能。如果说我要定义如下数据集:

+1 1:0.708333 2:1 3:1 4:-0.320755
-1 1:0.583333 2:-1 3:0.333333 4:-0.603774
+1 1:0.166667 2:1 3:-0.333333 4:-0.433962
-1 1:0.458333 2:1 3:1 4:-0.358491

可以先定义X的矩阵:private Node[][] _X;一组Y的数组private double[] _Y;然后再分别给_X和_Y赋值;

当然,也可以用Problem类提供的方法来Read(Stream)Read(String)来将数据直接读取到Problem中去。

Class Node

Member

Description

Node()()()

Default Constructor.

Node(Int32, Double)

Constructor.

CompareTo(Node)

Compares this node with another.

Equals(Object)

(Inherited from Object.)

Finalize()()()

(Inherited from Object.)

GetHashCode()()()

(Inherited from Object.)

GetType()()()

(Inherited from Object.)

Index

Index of this Node.

MemberwiseClone()()()

(Inherited from Object.)

ToString()()()

String representation of this Node as {index}:{value}.

(Overrides Object.ToString()()().)

Value

Value at Index.

Class Problem

Member

Description

Problem(Int32, array<Double>[]()[], array<array<Node>[]()[]>[]()[], Int32)

Constructor.

Problem()()()

Empty Constructor. Nothing is initialized.

Count

Number of vectors.

Equals(Object)

(Inherited from Object.)

Finalize()()()

(Inherited from Object.)

GetHashCode()()()

(Inherited from Object.)

GetType()()()

(Inherited from Object.)

MaxIndex

Maximum index for a vector.

MemberwiseClone()()()

(Inherited from Object.)

Read(Stream)

Reads a problem from a stream.

Read(String)

Reads a Problem from a file.

ToString()()()

(Inherited from Object.)

Write(Stream, Problem)

Writes a problem to a stream.

Write(String, Problem)

Writes a problem to a file. This will overwrite any previous data in the file.

X

Vector data.

Y

Class labels.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: