机器学习导入数据的方法

以鸢尾花数据集为例:

# (1) 使用python标准库导入

from  csv import reader
filename = 'iris.csv'
with open(filename,'rt') as raw_data:
    readers = reader(raw_data,delimiter  = ',')
    dataSet = list(readers)
    print(dataSet)
#  (2)  采用numpy 导入数据

from numpy import loadtxt
filename = 'iris.csv'
with open(filename,'rt') as raw_data:
    dataSet = loadtxt(raw_data,delimiter=',')
    print(dataSet)
#  (3) 采用pandas 导入数据

from pandas import read_csv
filename = 'iris.csv'
names = ['花瓣长度','花瓣宽度','花萼长度','花萼宽度','类别']
dataSet = read_csv(filename,names=names)
print(dataSet)

上一篇:C++对象模型那点事儿(布局篇)


下一篇:Java之对象序列化