1、手写最基本读取
f = open('8.iris.data','r',encoding='utf-8')
x = []
y = []
for d in f:
d = d.strip()
if not d:
continue
d = d.split(',')
x.append(list(map(float,d[:2])))
y.append((d[-1]))
y = np.array(list(map(iris_type,y)))
x = np.array(x)
2、使用python自带库csv
x = []
y = []
f = open('8.iris.data', 'r', encoding='utf-8')
d = csv.reader(f)
for line in d:
if not d:
continue
x.append(list(map(float, line[:2])))
y.append(line[-1])
y = np.array(list(map(iris_type, y)))
x = np.array(x)
3、使用numpy的方法读入
data = np.loadtxt('8.iris.data', converters={4: iris_type},dtype=float, delimiter=',',encoding='utf-8')
print(type(data))
x, y = np.split(data, (4,), axis=1)
x = x[:, :2]
print(x)
print(y.shape)
print(y.ravel().shape)
#split返回的y的shape是(150, 1),但是训练时的函数fit用的y是(150,),所以需要拉平y.ravel()
#4、使用pandas的方法读入
data = pd.read_csv('8.iris.data',converters={4: iris_type},header=None)
x = data.loc[:,:1].values
y = data.loc[:,4].values
print(x.shape)
print(y.shape)
相关知识
基于Echarts的鸢尾花数据可视化
Tensorflow鸢尾花分类(数据加载与特征处理)
人工智能考试——k近邻算法对鸢尾花(iris)数据集进行分析
鸢尾花数据集下载
Tensorflow训练鸢尾花数据集
【机器学习实战】科学处理鸢尾花数据集
分析鸢尾花数据集
iris鸢尾花数据集最全数据分析写在前面本文介绍数据预处理
神经网络与深度学习(五)前馈神经网络(3)鸢尾花分类
在WinCC中如何使用VBS读取变量归档数据到ECEL(9页)
网址: 鸢尾花数据读取的总结 https://m.huajiangbk.com/newsview387253.html
上一篇: 诗歌 |
下一篇: python机器学习 |