您的位置:首页 > 编程语言 > Python开发

python的数据科学资源

2015-03-10 15:20 716 查看
http://xccds1977.blogspot.jp/search?updated-max=2014-10-16T10:11:00%2B08:00&max-results=5&start=14&by-date=false

python和R是数据科学家手中两种最常用的工具,R已经介绍的太多了,后续我们来玩玩python吧。从出身来看,R是统计学家写的,python是计算机科学家写的,两者的出生背景不一样,随着数据爆发,python也慢慢发展,逐渐在数据科学中找到了一席之地。

包:

python也有非常多的扩展包,不过用于数据分析的并不象R那么品种繁多。常用的:

numpy:提供最基本的数值计算,使向量化计算成为可能。

scipy:提供了包括最优化在内的科学计算函数,不用自己写啦。

pandas:提供了类似dataframe的数据结构,处理表格数据非常方便。

matplotlib:画图必备,但用起来感觉不如ggplot2啊。

statsmodel:提供包括回归、检验等多种统计分析函数,python也能干R的活。

sklearn:数据挖掘必备,各种函数非常丰富,文档齐全,看得出CS出品就是不一样啊。

书:

python的数据方面书还不算很多,不过很有CS的味道,就是用show me the code,公式不多,这点我很喜欢。

现有可以找到的书基本上分为三类,一类是用基本语法实现统计分析和科学计算,例如下面的:

Think Stats

Think Bayes

A Primer on Scientific Programming with Python

另一类是以介绍一些包为目的,带有一些案例,例如:

Introduction to Python for Econometrics, Statistics and Data Analysis

numpy begin guide

Python for Data Analysis

matplotlib cookbook

Learning scikit learn Machine Learning

python text processing with nltk 2.0 cookbook

Social Network Analysis for Startups

最后一类是专门讲数据挖掘、机器学习的书:

programming collective intelligence:不用numpy包,只用基本语法实现一些算法

Machine Learning in Action:使用了numpy包,介绍了如何实现大部分算法

Machine learning an algorithmic perspective:体系非常完善,而且示例代码中使用了类

Notebook:

python的一大妙处就是ipython notebook,它可以把代码及其结果都存在一个网页上,方便分享学习。网上有非常多的notebook,其中成体系而又精彩的有下面三个:

https://github.com/datadave/GADS9-NYC-Spring2014-Lectures

http://blog.yhathq.com/posts/data-science-in-python-tutorial.html

http://slendermeans.org/pages/will-it-python.html

更多资源,请参见github上的一个列表

https://github.com/jonathan-bower/DataScienceResources

have fun!

5 评论



通过电子邮件发送BlogThis!共享给
Twitter共享给
Facebook分享到Pinterest

<iframe name="I0_1425971854903" width="100%" tabindex="0" title="+1" id="I0_1425971854903" src="https://apis.google.com/u/0/se/0/_/+1/fastbutton?usegapi=1&annotation=inline&width=300&size=medium&source=blogger%3Ablog%3Aplusone&hl=zh_CN&origin=http%3A%2F%2Fxccds1977.blogspot.jp&url=http%3A%2F%2Fxccds1977.blogspot.com%2F2014%2F10%2Fpython.html&gsrc=3p&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.Lva-I2OjVX0.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCP8jVvHfwdvqmQxtTaokZCFP7BK-A#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&id=I0_1425971854903&parent=http%3A%2F%2Fxccds1977.blogspot.jp&pfname=&rpctoken=1104819" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" vspace="0" hspace="0" style="margin: 0px; left: 0px; top: 0px; width: 300px; height: 20px; visibility: visible; position: static;" qbiframeattached="true" data-gapiattached="true"></iframe>

标签:
book,
python,
网上资源

星期五, 十月 10, 2014

python读入csv的三种方式

读数据到python有好几种方法,我们以读取iris.csv为例,将其中的数值部分提取出来。第一种方法是列表理解,文件读取到lines之后用一个嵌套的列表理解就可以将数值存为一个list。第二种方法是使用numpy库,它内带的loadtxt函数,读取的数据都认作是字符串,所以在第二行取我们需要的部分,并转为数值array。第三种方法是使用pandas库,它内带read_csv函数,读取数据会自动判断数值还是字符串,而且会自动保存好变量名,只需要用ix方法就可以类似R一样取出需要的子集,它存为dataframe对象。

这三种方法中最后一种最简单,不过花费时间比较长一点,第一种最麻烦,不过用时最短。这个可以通过ipython中的magic函数%%timeit来看。

12345678910111213141516
#原始的方式

lines = [line.split(',') for line in open('iris.csv')]
df = [[float(x) for x in line[:4]] for line in lines[1:]]

#使用numpy包

import numpy as np
lines = np.loadtxt('iris.csv',delimiter=',',dtype='str')
df = lines[1:,:4].astype('float')

#使用pandas包

import pandas as pd
df = pd.read_csv('iris.csv')
df=df.ix[:,:4]

view raw

openfile.py hosted with ❤ by
GitHub

0 评论



通过电子邮件发送BlogThis!共享给
Twitter共享给
Facebook分享到Pinterest

<iframe name="I1_1425971854912" width="100%" tabindex="0" title="+1" id="I1_1425971854912" src="https://apis.google.com/u/0/se/0/_/+1/fastbutton?usegapi=1&annotation=inline&width=300&size=medium&source=blogger%3Ablog%3Aplusone&hl=zh_CN&origin=http%3A%2F%2Fxccds1977.blogspot.jp&url=http%3A%2F%2Fxccds1977.blogspot.com%2F2014%2F10%2Fpythoncsv.html&gsrc=3p&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.Lva-I2OjVX0.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCP8jVvHfwdvqmQxtTaokZCFP7BK-A#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&id=I1_1425971854912&parent=http%3A%2F%2Fxccds1977.blogspot.jp&pfname=&rpctoken=68113656" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" vspace="0" hspace="0" style="margin: 0px; left: 0px; top: 0px; width: 300px; height: 20px; visibility: visible; position: static;" data-gapiattached="true"></iframe>

标签:
python,
数据导入

星期日, 七月 20, 2014

python和ggplot2

python有个非常强大的工具,那就是ipython notebook。用户可以在浏览器中直接编写python脚本,并立即得到输出结果。这类文档可以存为ipynb分享给其它人,也可以存为html直接放在网站上,非常有利于学习交流。

在R语言方面就缺乏这类工具,不过ipython有一种“魔法”,可以在ipython中运行其它语言。在数据分析时,可以将python和R代码混编,充分利用两种语言的优势。以可视化为例,R的ggplot2图形语法可谓是独步江湖,python中虽然已经有不少优秀的绘图库。但总不及ggplot2用得习惯。下面的小例子就是示范在ipython notebook中画ggplot2。

首先是用numpy库建立两个向量,再用%load_ext建立python和R的连接机制。之后在ipython notebook的一个cell里面就可以使用%R后面接R代码行,或者使用%%R使用代码块。如果要在R代码块中读入python的对象,需要使用-i参数。

其它例子可以参见这个,python中也有人复制了ggplot语法,可参见这里

123456789101112131415161718
import numpy as np
x = np.random.randn(100)
y = 2*x + np.random.randn(100)

%load_ext rpy2.ipython

%%R -i x,y -w 500 -h 300
df <- data.frame(x,y)
m <- lm(y~x)
inter <- m$coef[1]
slop <- m$coef[2]

library(ggplot2)
p <- ggplot(df, aes(x,y))
p <- p +
geom_point() +
geom_abline(intercept = inter, slope = slop)
print(p)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐