|
楼主 |
发表于 29-6-2016 11:16 PM
|
显示全部楼层
|
|
|
|
|
|
|
楼主 |
发表于 30-6-2016 12:02 PM
|
显示全部楼层
本帖最后由 凌云 于 30-6-2016 12:27 PM 编辑
第二章:用图表视觉化数据
A)笛卡尔坐标系 (平面直角坐标)
|
|
|
|
|
|
|
|
楼主 |
发表于 30-6-2016 12:21 PM
|
显示全部楼层
本帖最后由 凌云 于 30-6-2016 12:24 PM 编辑
第二章:B)Python 的 List 和 tuple
学过其它编程语言的网友应该知道 Array,但是python里面没有Array,只有List。
List 和 tuple 的差别在于tuple是不能改变数值的,它们可以使用的函数都一样。
- >>> simplelist = [1, 2, 3]
- >>> simplelist[0]
- 1
- >>> simplelist[1]
- 2
- >>> simplelist[2]
- 3
复制代码
List 可以存放String和其它物件,其它关于List的资料请参考相关Python书籍。
- >>> stringlist = ['a string','b string','c string']
- >>> stringlist[0]
- 'a string'
- >>> stringlist[1]
- 'b string'
- >>> stringlist[2]
- 'c string'
复制代码
这里介绍一个List的函数 append(), 用来加入数值到 List 中。
- >>> emptylist
- []
- >>> emptylist.append(1)
- >>> emptylist
- [1]
- >>> emptylist.append(2)
- >>> emptylist
- [1, 2]
复制代码
tuple 的创建方法是用 () 并且数值不可改变,其它都和 List 一样。
- >>> simpletuple = (1, 2, 3)
- >>> simpletuple[0]
- 1
- >>> simpletuple[1]
- 2
- >>> simpletuple[2]
- 3
复制代码
你也可以用 -1,-2 值来取得最后和最后第二个数值。
- simplelist[-1]
- simplelist[-2]
复制代码
迭代 (loop)的语法( List 和 Tuple 都可以):
- >>> l = [1, 2, 3]
- >>> for item in l:
- print(item)
复制代码 Output 输出:
也可以用 enumerate 内建函数来取得 index 和 value :
- >>> l = [1, 2, 3]
- >>> for index, item in enumerate(l):
- print(index, item)
复制代码 Output 输出:
|
|
|
|
|
|
|
|
楼主 |
发表于 30-6-2016 12:55 PM
|
显示全部楼层
本帖最后由 凌云 于 30-6-2016 12:56 PM 编辑
第二章:C)简单图表
我们现在要画一个经过三个点的线,分别是 (1,2),(2,4),(3,6)。
先把 x 和 y 设成两个list:
- >>> x_numbers = [1, 2, 3]
- >>> y_numbers = [2, 4, 6]
复制代码 然后创建图表:
- >>> from pylab import plot, show #导入函数
- >>> plot(x_numbers, y_numbers) #使用函数
复制代码 然后再用show()来画出并显现图表。
你就会看到:
|
|
|
|
|
|
|
|
楼主 |
发表于 30-6-2016 01:33 PM
|
显示全部楼层
第二章:D)图表上的标示
只要加上 marker 的参数,值可以是:o, *, x, +
- >>> plot(x_numbers, y_numbers, marker='o')
复制代码 然后用 show() 函数,就可以看到:
如果只要标示,不要线,可以这样写:
- >>> plot(x_numbers, y_numbers, 'o')
复制代码 同样的用 show() 过后,可以看到:
|
|
|
|
|
|
|
|
楼主 |
发表于 30-6-2016 01:57 PM
|
显示全部楼层
本帖最后由 凌云 于 30-6-2016 02:01 PM 编辑
第二章:E)标示纽约的2000-2012年平均温度
把平均温度写成list,并且创建plot, 然后用 show() 函数画出图表:
- >>> nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 57.3]
- >>> plot(nyc_temp, marker='o')
复制代码 你就会看到:
图中没有显示年份,要显示年份,代码这样写:
- >>> nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 57.3]
- >>> years = range(2000, 2013) #标示从2000 至 2012 的数值
- >>> plot(years, nyc_temp, marker='o')
复制代码 这样,x 值就变成了2000年到2012年的数值,用 show() 来画出图表:
|
|
|
|
|
|
|
|
楼主 |
发表于 30-6-2016 02:28 PM
|
显示全部楼层
本帖最后由 凌云 于 1-7-2016 10:45 PM 编辑
第二章:F)比较纽约的月平均温度
首先我们把要比较的一整年的温度写成list,写三年的温度:
- >>> nyc_temp_2000 = [31.3, 37.3, 47.2, 51.0, 63.5, 71.3, 72.3, 72.7, 66.0, 57.0, 45.3, 31.1]
- >>> nyc_temp_2006 = [40.9, 35.7, 43.1, 55.7, 63.1, 71.0, 77.9, 75.8, 66.6, 56.2, 51.9, 43.6]
- >>> nyc_temp_2012 = [37.3, 40.9, 50.9, 54.8, 65.1, 71.0, 78.8, 76.7, 68.8, 58.0, 43.9, 41.5]
复制代码 然后用 range() 建一个月份的list,然后用plot() 创建图表:
- >>> months = range(1, 13)
- >>> plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
复制代码 然后用 show() 画出图表:
你就会看到:
也可以分成三行代码来写:
- >>> plot(months, nyc_temp_2000)
- [<matplotlib.lines.Line2D object at 0x7f1e51351810>]
- >>> plot(months, nyc_temp_2006)
- [<matplotlib.lines.Line2D object at 0x7f1e5ae8e390>]
- >>> plot(months, nyc_temp_2012)
- [<matplotlib.lines.Line2D object at 0x7f1e5136ccd0>]
- >>> show()
复制代码
但是我们有一个问题,就是三条线都一样颜色,为了把三条线用不同颜色标示出来,我们可以用 legend() 函数,先创建图表:
- >>> plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
复制代码
然后倒入 legend() 函数,再使用函数,加入三年的标签:
- >>> from pylab import legend
- >>> legend([2000, 2006, 2012])
- <matplotlib.legend.Legend object at 0x7f2549d79410>
复制代码 然后用 show() 画出图表,会看到右上角多了标示,分别标示三条线的颜色:
然后加上 title,xlabel,ylabel,代码如下(>>>的是要打入的代码):
- >>> from pylab import plot, show, title, xlabel, ylabel, legend #导入需要用到的函数
- >>> plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012) #创建图表
- [<matplotlib.lines.Line2D object at 0x7f2549a9e210>, <matplotlib.lines.Line2D
- object at 0x7f2549a4be90>, <matplotlib.lines.Line2D object at 0x7f2549a82090>]
- >>> title('Average monthly temperature in NYC') #设title
- <matplotlib.text.Text object at 0x7f25499f7150>
- >>> xlabel('Month') #设xlabel
- <matplotlib.text.Text object at 0x7f2549d79210>
- >>> ylabel('Temperature') #设ylabel
- <matplotlib.text.Text object at 0x7f2549b8b2d0>
- >>> legend([2000, 2006, 2012]) #用不同颜色分别标示三条线
- <matplotlib.legend.Legend object at 0x7f2549a82910>
复制代码 最后用 show() 函数,画出图表:
|
|
|
|
|
|
|
|
发表于 14-8-2016 12:40 PM
|
显示全部楼层
想起我是AI毕业的现在做的竟然完全不是AI 真是惭愧 |
|
|
|
|
|
|
|
发表于 14-8-2016 04:13 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 17-8-2016 10:38 AM
|
显示全部楼层
如果是股票分析,应该用哪一个machine learning library? |
|
|
|
|
|
|
|
楼主 |
发表于 4-2-2017 11:13 AM
|
显示全部楼层
本帖最后由 凌云 于 4-2-2017 11:15 AM 编辑
其实里面的数学和理论很简单的,主要是,linear algebra, statistic, calculas.建议可以先看 Andrew Ng 在 coursera.org 的教程。
|
|
|
|
|
|
|
|
楼主 |
发表于 4-2-2017 11:19 AM
|
显示全部楼层
Machine Learning 本身是没有针对某个领域的,它是一种 general 的算法,不同的是数据的输入和人为的调整。 |
|
|
|
|
|
|
|
楼主 |
发表于 4-2-2017 11:21 AM
|
显示全部楼层
现在在做什么?我觉得学了就不要浪费,这个领域是未来的主流,谷歌百度等都全力投入了。
|
|
|
|
|
|
|
|
发表于 17-2-2017 04:42 PM
|
显示全部楼层
等 lz 开发 Beta Go 来打败 Alpha Go |
|
|
|
|
|
|
|
发表于 7-10-2018 10:31 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 15-10-2018 06:43 PM
|
显示全部楼层
樓主有用Jupyter notebook來玩visualization嗎?
小弟最近也在學習中 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|