I am pretty new for python. I am using python to read the arff file now:
import arff
for row in arff.load('cpu.arff'):
x = row
print(x)
The part of sample output is like this format:
Actually, only the last column of data is the label, and the rest of data are the attributes. I am wondering how I can save them by using array?
Because I want to assign the data of last column as y, and the first six column data as my x, and then I will do the cross-validation for the data from arff file.
Or is there any approaches to separate data by attributes and label from arff file automatically?
解决方案
Row objects from arff module support typical python array slicing, thus you can separate data from labels easily
import arff
X = []
y = []
for row in arff.load('cpu.arff'):
X.append(row[:-1])
y.append(row[-1])