.arff files with scikit-learn?

依然范特西╮ 提交于 2019-12-03 06:37:33

I really recommend liac-arff. It doesn't load directly to numpy, but the conversion is simple:

import arff, numpy as np
dataset = arff.load(open('mydataset.arff', 'rb'))
data = np.array(dataset['data'])

I found that scipy has a loader for arff files to load them as numpy record arrays. I am not 100% sure that those arrays are suitable for direct consumption by scikit-learn but that should get your started.

Follow renatopp's answer: assume your data is the iris dataset, there should be 5 dimensional with last one is the class label column.

s = svm.SVC()
data_input = data[:,0:4]
labels = data[:,4] # this is the class column
s.fit(data_input, labels)

I think this is something you want.

If your "arff" file is a text file, try the following code instead:

import arff, numpy as np
dataset = arff.loads(open('mydataset.arff', 'rt'))
data = np.array(dataset['data'])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!