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])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值