博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[学习笔记]人工智能-数据解析和可视化
阅读量:4146 次
发布时间:2019-05-25

本文共 3308 字,大约阅读时间需要 11 分钟。

一、投喂学习模型的数据

原始数据

数据可以通过我的github工程下载

1.读取数据

运行示例

# 加载数据原料import pandas as pdfile = "D:/EclipseProject/PythonStudyBySu/su/iris.data.csv"# 无文件头df = pd.read_csv(file, header=None)# 读取前面 10 行数据print(df.head(10))

显示结果

0    1    2    3            40  5.1  3.5  1.4  0.2  Iris-setosa1  4.9  3.0  1.4  0.2  Iris-setosa2  4.7  3.2  1.3  0.2  Iris-setosa3  4.6  3.1  1.5  0.2  Iris-setosa4  5.0  3.6  1.4  0.2  Iris-setosa5  5.4  3.9  1.7  0.4  Iris-setosa6  4.6  3.4  1.4  0.3  Iris-setosa7  5.0  3.4  1.5  0.2  Iris-setosa8  4.4  2.9  1.4  0.2  Iris-setosa9  4.9  3.1  1.5  0.1  Iris-setosa

2.数据显示

运行示例

# 数据可视化展示import matplotlib.pyplot as pltimport numpy as npy = df.loc[0:100, 4].valuesprint("显示第四列前100条数据", y)

显示结果

显示第四列前100条数据 ['Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-setosa' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-versicolor' 'Iris-virginica']

3.对数据进行分类

示例

y = np.where(y == "Iris-setosa", -1, 1)print("对数据进行分类", y)

运行结果

对数据进行分类 [-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1]

4.抽取出第0和2列的数据

示例

x = df.iloc[0:100, [0, 2]].valuesprint("抽取出第0和2列的数据", x)

类似一个二维数组

抽取出第0和2列的数据 [[ 5.1  1.4] [ 4.9  1.4] [ 4.7  1.3] [ 4.6  1.5] [ 5.   1.4] ........... [ 6.1  4.6] [ 5.8  4. ] [ 5.   3.3] [ 5.6  4.2] [ 5.7  4.2] [ 5.7  4.2] [ 6.2  4.3] [ 5.1  3. ] [ 5.7  4.1]]

5 可视化数据

这里的可视化的目的是区分分界线

可视化数据集

# 画出图形# x 的第一列为x轴,第二列为y轴plt.scatter(x[:50, 0], x[:50, 1], color='red', marker='o', label='setosa')plt.scatter(x[50:100, 0], x[50:100, 1], color='blue',            marker='x', label='versicolor')plt.xlabel("花瓣长度")plt.ylabel("花茎长度")plt.legend(loc='upper left')plt.show()

6 学习来源

慕课网视频

你可能感兴趣的文章
必须要理解掌握的贝塞尔曲线
查看>>
服务端渲染和客户端渲染区别?
查看>>
编译与链接详解
查看>>
windows异常处理__try__except
查看>>
performance 查看页面性能
查看>>
STL中vector、list、deque和map的区别
查看>>
WinDbg-如何抓取dump文件
查看>>
C/C++函数调用过程--函数栈(一)
查看>>
信号量、互斥体和自旋锁
查看>>
WTL 窗口创建消息队列
查看>>
互斥量使用实例
查看>>
共享内存+信号量 实例
查看>>
C/C++函数调用过程--函数栈(二)
查看>>
【Windows】线程漫谈——线程基础(一)
查看>>
【Windows】线程漫谈——线程栈(二)
查看>>
内存映射文件
查看>>
Windows进程间各种通信方式浅谈
查看>>
一则简单的Windows共享内存IPC代码
查看>>
Windows进程间通信
查看>>
异步过程调用(APC)——操作系统实现异步的原理
查看>>