.arff files with scikit-learn?

2019-03-19 09:27发布

I would like to use an Attribute-Relation File Format with scikit-learn to do some NLP task, is this possible? How can use an .arff file with scikit-learn?

3条回答
SAY GOODBYE
2楼-- · 2019-03-19 09:54

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.

查看更多
The star\"
3楼-- · 2019-03-19 10:00

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.

查看更多
ら.Afraid
4楼-- · 2019-03-19 10:02

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'])
查看更多
登录 后发表回答