Top Banner
Statistics and Data Analysis in Python with pandas and statsmodels Wes McKinney @wesmckinn NYC Open Statistical Programming Meetup 9/14/2011 Thursday, September 15,
29

Data Analysis and Statistics in Python using pandas and statsmodels

Nov 28, 2014

Download

Technology

wesm

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Analysis and Statistics in Python using pandas and statsmodels

Statistics and Data Analysis in Python with pandas and statsmodels

Wes McKinney @wesmckinn

NYC Open Statistical Programming Meetup9/14/2011

Thursday, September 15,

Page 2: Data Analysis and Statistics in Python using pandas and statsmodels

Talk Overview

• Statistical Computing Big Picture

• Scientific Python Stack

• pandas

• statsmodels

• Ideas for the (near) future

Thursday, September 15,

Page 3: Data Analysis and Statistics in Python using pandas and statsmodels

Who am I?

MIT Math AQR: Quant Finance

Statistics

Back to NYC

Thursday, September 15,

Page 4: Data Analysis and Statistics in Python using pandas and statsmodels

The Big Picture

• Building the “next generation” statistical computing environment

• Making data analysis / statistics more intuitive, flexible, powerful

• Closing the “research-production” gap

Thursday, September 15,

Page 5: Data Analysis and Statistics in Python using pandas and statsmodels

Application areas

• General data munging, manipulation

• Financial modeling and analytics

• Statistical modeling and econometrics

• “Enterprise” / “Big Data” analytics?

Thursday, September 15,

Page 6: Data Analysis and Statistics in Python using pandas and statsmodels

R, the solution?

“R is the most powerful statistical computing language on the planet”

Hadley Wickham (ggplot2, plyr, reshape, ...)

Thursday, September 15,

Page 7: Data Analysis and Statistics in Python using pandas and statsmodels

Easy to miss the point

Thursday, September 15,

Page 8: Data Analysis and Statistics in Python using pandas and statsmodels

R, the solution?

“I have been worried for some time that R isn’t going to provide the base that we’re going to need for statistical computation in the future. (It may well be that the future is already upon us.) ... I have come to the conclusion that rather than ‘fixing’ R, it would be much more productive to simply start over and build something better”

Ross Ihaka (One of creators of R)

Thursday, September 15,

Page 9: Data Analysis and Statistics in Python using pandas and statsmodels

Some of my gripes about R

• Wonky, highly idiosyncratic programming language*

• Poor speed and memory usage

• General purpose libraries and software development tools lacking

• The GPL

* But yes, really great libraries

Thursday, September 15,

Page 10: Data Analysis and Statistics in Python using pandas and statsmodels

R: great libraries and deep connections to academia

Jeff Ryanxts, quantmod

Hadley Wickhamggplot2, plyr, reshape

Example R superstars

Thursday, September 15,

Page 11: Data Analysis and Statistics in Python using pandas and statsmodels

Uniting against common enemies

Thursday, September 15,

Page 12: Data Analysis and Statistics in Python using pandas and statsmodels

“Research-Production” Gap

• Best data analysis / statistics tools: often least well-suited for building production systems

• The “Black Box”: embedding or RPC

• High productivity <=> Low productivity

Thursday, September 15,

Page 13: Data Analysis and Statistics in Python using pandas and statsmodels

• Production: much more than crunching data and making pretty plots

• Code readability, debuggability, maintainability matter a lot in the long run

• Integration with other systems

“Research-Production” Gap

Thursday, September 15,

Page 14: Data Analysis and Statistics in Python using pandas and statsmodels

“Research-Production” Gap

Thursday, September 15,

Page 15: Data Analysis and Statistics in Python using pandas and statsmodels

Thursday, September 15,

Page 16: Data Analysis and Statistics in Python using pandas and statsmodels

My assertion

Python is the best (only?)viable solution to the

Research-Production gap

Thursday, September 15,

Page 17: Data Analysis and Statistics in Python using pandas and statsmodels

Scientific Python Stack

• Incredible growth in libraries and tools over the last 5 years

• NumPy: the cornerstone

• Killer app: IPython

• Cython: C speedups, 80+% less dev time

• Other exciting high-profile projects: scikit-learn, theano, sympy

Thursday, September 15,

Page 18: Data Analysis and Statistics in Python using pandas and statsmodels

Uniting the Python Community

• Fragmentation is a (big) problem / risk

• Statistical libraries need to be able to talk to each other easily

• R’s success: S-Plus legacy + quality CRAN packages built around cohesive base R / data structures

Thursday, September 15,

Page 19: Data Analysis and Statistics in Python using pandas and statsmodels

pandas

• Foundational rich data structures and data analysis tools

• Arrays with labeled axes and support for heterogeneous data

• Similar to R data.frame, but with many more built-in features

• Missing data, time series support

Thursday, September 15,

Page 20: Data Analysis and Statistics in Python using pandas and statsmodels

pandas

• Milestone: 0.4 release 9/12/2011

• Dozens of new features and enhancements

• Completely rewritten docs: pandas.sf.net

• Many more new features planned for the future

Thursday, September 15,

Page 21: Data Analysis and Statistics in Python using pandas and statsmodels

The sleeping dragon

Thursday, September 15,

Page 22: Data Analysis and Statistics in Python using pandas and statsmodels

Little did I know...

Thursday, September 15,

Page 23: Data Analysis and Statistics in Python using pandas and statsmodels

pandas: some key features

• Automatic and explicit data alignment

• Label-based (inc hierarchical) indexing

• GroupBy, pivoting, and reshaping

• Missing data support

• Time series functionality

Thursday, September 15,

Page 24: Data Analysis and Statistics in Python using pandas and statsmodels

Demo time

Thursday, September 15,

Page 25: Data Analysis and Statistics in Python using pandas and statsmodels

statsmodels

• Statistics and econometrics in Python

• Focused on estimation of statistical models

• Regression models (GLS, Robust LM, ...)

• Time series models (AR/ARMA, VAR, Kalman Filter, ...)

• Non-parametric models (e.g. KDE)

Thursday, September 15,

Page 26: Data Analysis and Statistics in Python using pandas and statsmodels

statsmodels

• Development has been largely focused on computation

• Correct, tested results

• In progress: better user interface

• Formula frameworks (e.g. similar to R)

• pandas integration

Thursday, September 15,

Page 27: Data Analysis and Statistics in Python using pandas and statsmodels

Demo time

Thursday, September 15,

Page 28: Data Analysis and Statistics in Python using pandas and statsmodels

Ideas for the future

• ggpy: ggplot2 for Python

• Statistical Python Distribution / Umbrella project

• Interactive GUI widgets to visualize / explore data and statsmodels results

Thursday, September 15,

Page 29: Data Analysis and Statistics in Python using pandas and statsmodels

Thanks

• pandas: http://pandas.sf.net

• statsmodels: http://statsmodels.sf.net

• Twitter: @wesmckinn

• E-mail: wesmckinn (at) gmail (dot) com

• Blog: http://blog.wesmckinney.com

Thursday, September 15,