人工智能算法小白入门-|人工智能算法小白入门- Jupyter notebook python 基础入门
作者:刘算法一、前言 笔者在前面的几篇文章中讲述了关于算法学习及入门的一些方法与技能,这其中包括自己的一些学习经历和实践方法。但是,空谈方法难免有些空洞,所以从此开始系统的讲述算法入门应该必备的技能及算法原理、思想。
来源: 恒生LIGHT云社区
这将是一个系列课程,首先发布文本版本,后续有时间会继续更新细节或添加代码实现细节,欢迎关注。
本篇文章主要以jupyter notebook为代码开发环境,开始python 基础编程之旅。
二、Jupyter notebook的安装 在文章《【人工智能算法小白入门系列】- 如何入门学习成为一名AI算法工程师?》一种,我曾提到Jupyter notebook的安装步骤,在此再简单描述一下。
1. 首先,安装Anaconda解析环境,安装完成后可以在Anaconda prompt窗口键入jupyter notebook 回车后启动,可以通过ctrl+C停止jupyter,具体见图:

文章图片
也可以在该窗口上,先cd 到特定路径下然后再键入jupyter notebook启动。
2. 启动后,就可以在网页版的编辑环境下正常的运行Python代码了,例如下图展示了在python导入简答的包并打印输出提示语句。

文章图片
三、Jupyter notebook基础 1. 文本单元格使用markdown 语法基础,可以参考
https://guides.github.com/features/mastering-markdown/
2. 代码单元格执行:

文章图片
四、Python基础 1. 列表生成器及索引功能,包括索引,过滤,切片和求长度

文章图片
List不要求存储相同类型的数据,带来效率问题。
2. numpy array 数据类型,要求相同的数据结构,不然会显示错误。缺点在于数据并没有做成向量或者矩阵,不支持运算。

文章图片
3. 创建numpy及基本功能
1. 通过不同的方式创建array及常见的技巧。

文章图片
2. 生成不同size的array并初始化: 【人工智能算法小白入门-|人工智能算法小白入门- Jupyter notebook python 基础入门】

文章图片
3. 按照一定的间隔生成,但是不支持浮点作为间隔。

文章图片
4. 在一定范围内生成有限的数值:

文章图片
5. 生成特定区间内的随机数

文章图片
6. 生成特定size的随机数

文章图片
4. numpy 合并和分割
1. 合并:

文章图片
2. 分割:

文章图片
5. matplotlib基础

文章图片
1. 关于color的参数可以参考: https://matplotlib.org/2.0.2/api/colors_api.html

文章图片
2. 关于linestyle参数: https://matplotlib.org/devdocs/gallery/lines_bars_and_markers/line_styles_reference.html
3. scatter 点图:

文章图片
四、机器学习算法实践 当前经典的机器学习算法中,我们选定KNN作为简单代码实践的过程。KNN算法属于无监督分类算法模型,关于算法的原理及细节我会再后续的课程中详细描述,当前只借助jupyter简单实现其过程。
首先,定义训练数据样本raw_data_X和对应的标签数据raw_data_y,测试样本暂定一个x
具体代码如下:

文章图片
建模、训练及推理

文章图片
以上是基于jupyter notebook 实现的Python代码和简单应用,后续会更新更多相关课程,尽情关注。
推荐阅读
- 画解算法(1.|画解算法:1. 两数之和)
- Guava|Guava RateLimiter与限流算法
- 一个选择排序算法
- SG平滑轨迹算法的原理和实现
- 人工智能|干货!人体姿态估计与运动预测
- 《算法》-图[有向图]
- 驾校小白的“日常”
- LeetCode算法题-11.|LeetCode算法题-11. 盛最多水的容器(Swift)
- 虚拟DOM-Diff算法详解
- 《数据结构与算法之美》——队列