python怎么读取文件中的数据
python读取arff⽂件,如何使⽤python处理来⾃arff⽂件的数据?
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])

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。