OpenCV 机器学习算法的 CSV 格式
OpenCV 中的机器学习算法似乎使用以 CSV 格式读取的数据。例如,请参阅 此 cpp 文件< /a>.使用以下代码将数据读入 OpenCV 机器学习类 CvMLData
:
CvMLData data;
data.read_csv( filename )
但是,似乎没有任何关于 csv 文件所需格式的现成文档。有谁知道csv文件应该如何排列?
其他(非 Opencv)程序往往每个训练示例都有一行,并以指示类标签的整数或字符串开头。
Machine learning algorithms in OpenCV appear to use data read in CSV format. See for example this cpp file. The data is read into an OpenCV machine learning class CvMLData
using the following code:
CvMLData data;
data.read_csv( filename )
However, there does not appear to be any readily available documentation on the required format for the csv file. Does anyone know how the csv file should be arranged?
Other (non-Opencv) programs tend to have a line per training example, and begin with an integer or string indicating the class label.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我阅读 来源类,特别是 str_to_flt_elem 函数,以及 类文档 我得出的结论是有效格式文件中的各个项目是:
第 1 项和第 2 项仅对功能有效。与项目 3 匹配的任何内容都被假定为类标签,并且据我所知,项目的顺序并不重要。 read_csv 函数会自动为 csv 文件中的每一列分配正确的类型,并且(如果需要)您可以使用 set_response_index。明智的分隔符您可以使用默认值 (,) 或在使用 set_delimiter (只要不使用小数点)。
因此,这应该适用于例如 3 个类中的 6 个数据点,每个点有 3 个特征:
您可以将文本标签移动到所需的任何列,甚至可以有多个文本标签。
If I read the source for that class, particularly the str_to_flt_elem function, and the class documentation I conclude that valid formats for individual items in the file are:
Items 1 and 2 are only valid for features. anything matched by item 3 is assumed to be a class label, and as far as I can deduce the order of the items doesn't matter. The read_csv function automatically assigns each column in the csv file the correct type, and (if you want) you can override the labels with set_response_index. Delimiter wise you can use the default (,) or set it to whatever you like before calling read_csv with set_delimiter (as long as you don't use the decimal point).
So this should work for example, for 6 datapoints in 3 classes with 3 features per point:
You can move your text label to any column you want, or even have multiple text labels.