SlideShare a Scribd company logo
Los Angeles R Users’ Group




              NumPy and SciPy for Data Mining and Data Analysis
                  Including iPython, SciKits, and matplotlib

                                            Ryan R. Rosario




                                            March 29, 2011




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                           Los Angeles R Users’ Group
What is NumPy?




      NumPy is the standard package for scientific and numerical computing in
      Python:

              powerful N-dimensional array object.
              sophisticated (broadcasting) functions.
              tools for integrating C/C++ and Fortran code (R is similar)
              useful linear algebra, Fourier transform and random number capabilities.

      Additionally...
              data structures can be used as efficient multi-dimensional container of
              arbitrary data types.

Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                 Los Angeles R Users’ Group
So, What is SciPy?




      Often (incorrectly) used as a synonym of NumPy.
              SciPy depends on NumPy’s data structures.
              OSS for mathematics, science, and engineering.
              provides efficient numerical routines for numerical integration and
              optimization.

      “NumPy provides the data structures, SciPy provides the application layer.”


Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                 Los Angeles R Users’ Group
Getting NumPy
      The ease of installation is highly dependent on OS and CPU.
          Official releases are recommended and available for
                  1   32 bit MacOS X
                            Caveat: Must use Python Python, not Apple Python.
                  2   32 bit Windows
              Unofficial/third-party binary releases for
                  1   All Linux (use platform package system)
                  2   64 bit MacOS X (SciPy Superpack)
                            Requires Apple Python 2.6.1
                  3   64-bit Windows (Christoph Gohlke, UC Irvine)
              Source Code
              Enthought is to SciPy/Numpy as Revolution is to R.
      Main download link is http://www.scipy.org/Download
Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                               Los Angeles R Users’ Group
Disclaimer



      Time is even more limited than usual, so the goal is to illustrate
      what NumPy is, and what NumPy, SciPy and its colleagues can
      achieve. Some goals:
              Brief NumPy tutorial via demo.
              Uses of NumPy and SciPy, including SciKits.
              Brief data analysis demo with NumPy, SciPy and matplotlib.
              Concluding remarks.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                      Los Angeles R Users’ Group
NumPy Basics

      The main data structure is a homogeneous multidimensional array
      – a table of elements all of the same type, indexed by a tuple of
      positive integers. Some examples are vectors, matrices, images and
      spreadsheets.


      Why not just a use a list of lists? NumPy provides functions
      that operate on an entire array at once (like R), Python does
      not...really.


      NumPy is full of syntax and time is limited, so let’s jump straight
      into a demo...

Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                      Los Angeles R Users’ Group
NumPy Basics




      Demo




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis   Los Angeles R Users’ Group
Keep in Mind: Broadcasting vs. Recycling



      In NumPy, if two arrays do not have the same length and we try
      to, say, add them, 1 is appended to the smaller array so that the
      dimensions match.


      In R, if two vectors do not have the same length, the values in the
      shorter vector are recycled and a warning is generated.
      Personally, recycling seems more practical.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                     Los Angeles R Users’ Group
Keep in Mind: Indexing!



      R starts its indices at 1 and ranges are inclusive (i.e. seq(1,3) ->
      1, 2, 3)


      NumPy (and Python) starts its indices at 0 and ranges are
      exclusive (i.e. arange(1,3) -> 1, 2).




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                     Los Angeles R Users’ Group
Keep in Mind: Data Type Matters!




      R does a good job of using the correct data type.


      NumPy requires you to make decisions about data type. Using
      int64 for 1 is typically wasteful.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                  Los Angeles R Users’ Group
ipython: a replacement CLI I




      IPython is the recommended CLI for NumPy/SciPy. I will use
      IPython in my demo.
          1   an enhanced interactive Python shell.
          2   an architecture for interactive parallel computing.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                            Los Angeles R Users’ Group
ipython: a replacement CLI II


      Some advantages over the standard CLI:
          1   tab completion for object attributes and filenames, auto
              parentheses and quotes for function calls.
          2   simple object querying
                     object name? prints details about an object.
                     %pdoc (docstring), %pdef (function definition), %psource (full
                     source code).
          3   %run to run a code file, much like source in R. Differs from
              import because the code file is reread each time %run is
              called. Also provides special flags for profiling and debugging.



Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                             Los Angeles R Users’ Group
ipython: a replacement CLI III
          4   %pdb for spawning a pdb debug session.
          5   Output cache saves the results of executing each line of
              code. , ,      save the last three results.
          6   Input cache allows re-execution of previously executed code
              using a snapshot of the original input data in variable In. (to
              rexecute lines 22 through 28, and line 34: exec In[22:29]
              + In[34].
          7   Command history with(out) line numbers using %hist. Can
              also toggle journaling with %logstart.
          8   Execute system commands from within IPython as if you are
              in the terminal by prefixing with !. Use !!, %sc, %sx to get
              output into a Python variable (var = !ls -la). Use Python
              variables when calling the shell.
Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                         Los Angeles R Users’ Group
ipython: a replacement CLI IV

          9   Easy access to the profiler, %prun.
         10   Easy to integrate with matplotlib.
         11   Custom profiles (options, modules to load, function
              definitions). Similar to R workspace.
         12   Run other programs (that use pipes) and extract output
              (gnuplot).
         13   Easily run doctests.
         14   Lightweight version control.
         15   Save/restore session, like in R (the authors specifically said
              “like R”).


Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                          Los Angeles R Users’ Group
matplotlib: SciPy’s Graphics System I




      2D graphics library for Python that produces publication quality
      figures. Quality with respect to R is in the eye of the beholder.
              Graphics in R are much easier to construct, and require less
              code.
              Graphics in matplotlib may look nicer; require much more
              code.


Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                        Los Angeles R Users’ Group
matplotlib: SciPy’s Graphics System II




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis   Los Angeles R Users’ Group
matplotlib: SciPy’s Graphics System III




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis   Los Angeles R Users’ Group
matplotlib: SciPy’s Graphics System IV




      Show matplotlib gallery.


      I will do a demo of matplotlib in the data analysis demo, if time.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                    Los Angeles R Users’ Group
Quick Linear Regression Demo




      Demo here.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis   Los Angeles R Users’ Group
SciKits I


      SciKits are modules or “plug-ins” for SciPy; they are too
      specialized to be included in SciPy itself. Below is a list of some
      relevant SciKits.
          1   statsmodels: OLS, GLS, WLS, GLM, M-estimators for
              robust regression.
          2   timeseries: time series analysis.
          3   bootstrap: bootstrap error-estimation.
          4   learn: machine learning and data mining




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                       Los Angeles R Users’ Group
SciKits II



          5   sparse: sparse matrices
          6   cuda: Python interface to GPU powered libraries.
          7   image: image processing
          8   optimization: numerical optimization
      For more information, see
      http://scikits.appspot.com/scikits.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                         Los Angeles R Users’ Group
Scientific Software Relying on SciPy I

      Many exciting software packages rely on SciPy

                              Python Based Reinforcement Learning, Artificial Intelligence and
                              Neural Network Library. Built around a neural networks kernel.
                              Provides unsupervised learning and evolution.
                              http://www.pybrain.org


                              PyMC Pythonic Markov Chain Monte Carlo. MCMC, Gibbs
                              sampling, diagnostics




                              PyML: SVM, nearest neighbor, ridge regression, multiclass methods,
                              model selection, filtering, CV, ROC.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                       Los Angeles R Users’ Group
Scientific Software Relying on SciPy II


                              Monte: gradient based learning machines, logistic regression,
                              conditional random fields.




                              MILK: SVM, k-NN, random forests, decision trees, feature selection,
                              affinity propagation.




                              Modular toolkit for Data Processing: signal processing, PCA, ICA,
                              manifold learning, factor analysis, regression, neural networks,
                              mixture models.



Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                         Los Angeles R Users’ Group
Scientific Software Relying on SciPy III


                              PyEvolve: Genetic algorithms




                              Theano: Theano is a Python library that allows you to define,
                              optimize, and evaluate mathematical expressions involving
                              multi-dimensional arrays efficiently: GPUs, symbolic expressions,
                              dynamic C code generation.


                              Orange: Data mining, visualization and machine learning. Full GUI
                              and Python scripting.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                        Los Angeles R Users’ Group
Scientific Software Relying on SciPy IV




                              SAGE: a hodgepodge of open-source software designed to be one
                              analysis platform.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                     Los Angeles R Users’ Group
Pros/Cons I

      What NumPy/SciPy does better:
          1   Much larger community (SciPy + Python).
          2   Better, and cleaner graphics...slightly.
          3   Sits on atop a programming language rather than being one.
          4   Dictionary data type is very useful (Python).
          5   Adheres to a system of thought (“Pythonic”) that is more flexible.
          6   Memory mapped files and extensive sparse matrix packages.
          7   Easier to incorporate into a company/development workflow.
          8   Opinion: Developers don’t have to dive into C as soon as they do with
              R.



Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                Los Angeles R Users’ Group
Pros/Cons II


      What R does better:
          1   One word data.frame.
          2   Installation is simple and universal.
          3   Application is self-contained (NumPy consists of several moving parts).
          4   Very simple, user friendly syntax.
          5   Graphics and analysis are fairly quick to code.
          6   Much easier data input.
          7   Handles missing values better.




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                                 Los Angeles R Users’ Group
The SciPy community is very useful, prolific and friendly. Project
      has very high morale. Some places to get help:
          1   http://www.numpy.org: extensive documentation, examples
              and cookbook.
          2   http://www.scipy.org: extensive documentation, examples
              and cookbook.
          3   NumPy and SciPy mailing lists are helpful.
          4   StackOverflow
          5   IRC channel #scipy
          6   Frequent sprints and hackathons.
          7   SciPyCon (Austin, TX)
          8   SoCalPiggies and LA Python (first meeting April 1!)


Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                      Los Angeles R Users’ Group
Keep in Touch!




      My email: ryan@stat.ucla.edu

      My blog: http://www.bytemining.com

      Follow me on Twitter: @datajunkie




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis   Los Angeles R Users’ Group
References



          1   NumPy http://www.numpy.org
          2   SciPy http://www.scipy.org
          3   SciKits http://scikits.appspot.com
          4   iPython http://ipython.scipy.org/moin/
          5   matplotlib http://matplotlib.sourceforge.net/




Ryan R. Rosario
NumPy/SciPy for Data Mining and Analysis                Los Angeles R Users’ Group

More Related Content

PDF
Python final ppt
PDF
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
PDF
Accessing R from Python using RPy2
PDF
Scipy, numpy and friends
PDF
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
PDF
Accessing r from python using r py2
PPTX
Python libraries
PDF
Numba: Array-oriented Python Compiler for NumPy
Python final ppt
Taking R to the Limit (High Performance Computing in R), Part 1 -- Paralleliz...
Accessing R from Python using RPy2
Scipy, numpy and friends
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Accessing r from python using r py2
Python libraries
Numba: Array-oriented Python Compiler for NumPy

What's hot (20)

PDF
Python interview questions
PDF
Math synonyms
PPTX
Python libraries for data science
DOCX
Python interview questions and answers
PDF
Most Asked Python Interview Questions
PDF
Introduction to r bddsil meetup
DOCX
Python interview questions
PDF
Getting started with Linux and Python by Caffe
ODP
Python and Machine Learning
PDF
R crash course
PPTX
Python interview question for students
PDF
Python Interview Questions And Answers
PPTX
Introduction to R Programming
PDF
Introduction to R software, by Leire ibaibarriaga
PDF
summer training report on python
PPTX
Basic lisp
DOCX
Python interview questions for experience
PPTX
Python Summer Internship
PPTX
R language tutorial
PDF
Sequence Learning with CTC technique
Python interview questions
Math synonyms
Python libraries for data science
Python interview questions and answers
Most Asked Python Interview Questions
Introduction to r bddsil meetup
Python interview questions
Getting started with Linux and Python by Caffe
Python and Machine Learning
R crash course
Python interview question for students
Python Interview Questions And Answers
Introduction to R Programming
Introduction to R software, by Leire ibaibarriaga
summer training report on python
Basic lisp
Python interview questions for experience
Python Summer Internship
R language tutorial
Sequence Learning with CTC technique
Ad

Viewers also liked (19)

PPTX
Text mining presentation in Data mining Area
PDF
Lecture 01 Data Mining
PPTX
Analytics and Data Mining Industry Overview
PDF
Big Data v Data Mining
PPT
Data Mining Overview
PDF
Machine Learning and Data Mining: 19 Mining Text And Web Data
PPTX
Data Mining: an Introduction
PPTX
Knowledge Discovery and Data Mining
PPT
Chapter - 6 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
PPTX
Data warehousing and data mining
PPT
Data Mining and Data Warehousing
PPT
introduction to data mining tutorial
PDF
Data Mining and Business Intelligence Tools
PPTX
Data Mining: Application and trends in data mining
PPT
Ch 1 Intro to Data Mining
PPT
DATA WAREHOUSING AND DATA MINING
PPTX
Data mining
PPT
Data mining slides
 
Text mining presentation in Data mining Area
Lecture 01 Data Mining
Analytics and Data Mining Industry Overview
Big Data v Data Mining
Data Mining Overview
Machine Learning and Data Mining: 19 Mining Text And Web Data
Data Mining: an Introduction
Knowledge Discovery and Data Mining
Chapter - 6 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
Data warehousing and data mining
Data Mining and Data Warehousing
introduction to data mining tutorial
Data Mining and Business Intelligence Tools
Data Mining: Application and trends in data mining
Ch 1 Intro to Data Mining
DATA WAREHOUSING AND DATA MINING
Data mining
Data mining slides
 
Ad

Similar to NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits, and matplotlib (20)

PDF
Scientific Python
PDF
DS LAB MANUAL.pdf
PDF
Travis Oliphant "Python for Speed, Scale, and Science"
PPTX
Data Analysis packages
PDF
Python vs. r for data science
PDF
Python Científico
PDF
Migrating from matlab to python
PPTX
Scipy Libraries to Work with Various Datasets.pptx
PPTX
Introduction to Machine Learning by MARK
PDF
The Joy of SciPy
PPTX
Introduction-to-NumPy-in-Python (1).pptx
PPTX
Numpy and Pandas Introduction for Beginners
PPTX
2.2-Intro-NumPy-Matplotlib.pptx
PDF
SciPy Latin America 2019
PDF
London level39
PPTX
Intellectual technologies
PDF
Data Structures for Statistical Computing in Python
PDF
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Linux
PPT
PDF
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Mac
Scientific Python
DS LAB MANUAL.pdf
Travis Oliphant "Python for Speed, Scale, and Science"
Data Analysis packages
Python vs. r for data science
Python Científico
Migrating from matlab to python
Scipy Libraries to Work with Various Datasets.pptx
Introduction to Machine Learning by MARK
The Joy of SciPy
Introduction-to-NumPy-in-Python (1).pptx
Numpy and Pandas Introduction for Beginners
2.2-Intro-NumPy-Matplotlib.pptx
SciPy Latin America 2019
London level39
Intellectual technologies
Data Structures for Statistical Computing in Python
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Linux
How to Install numpy, scipy, matplotlib, pandas and scikit-learn on Mac

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
Advanced IT Governance
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PDF
Newfamily of error-correcting codes based on genetic algorithms
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Understanding_Digital_Forensics_Presentation.pptx
Sensors and Actuators in IoT Systems using pdf
GamePlan Trading System Review: Professional Trader's Honest Take
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced Soft Computing BINUS July 2025.pdf
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reimagining Insurance: Connected Data for Confident Decisions.pdf
Advanced IT Governance
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Newfamily of error-correcting codes based on genetic algorithms
NewMind AI Weekly Chronicles - August'25 Week I
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
madgavkar20181017ppt McKinsey Presentation.pdf
CIFDAQ's Teaching Thursday: Moving Averages Made Simple

NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits, and matplotlib

  • 1. Los Angeles R Users’ Group NumPy and SciPy for Data Mining and Data Analysis Including iPython, SciKits, and matplotlib Ryan R. Rosario March 29, 2011 Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 2. What is NumPy? NumPy is the standard package for scientific and numerical computing in Python: powerful N-dimensional array object. sophisticated (broadcasting) functions. tools for integrating C/C++ and Fortran code (R is similar) useful linear algebra, Fourier transform and random number capabilities. Additionally... data structures can be used as efficient multi-dimensional container of arbitrary data types. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 3. So, What is SciPy? Often (incorrectly) used as a synonym of NumPy. SciPy depends on NumPy’s data structures. OSS for mathematics, science, and engineering. provides efficient numerical routines for numerical integration and optimization. “NumPy provides the data structures, SciPy provides the application layer.” Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 4. Getting NumPy The ease of installation is highly dependent on OS and CPU. Official releases are recommended and available for 1 32 bit MacOS X Caveat: Must use Python Python, not Apple Python. 2 32 bit Windows Unofficial/third-party binary releases for 1 All Linux (use platform package system) 2 64 bit MacOS X (SciPy Superpack) Requires Apple Python 2.6.1 3 64-bit Windows (Christoph Gohlke, UC Irvine) Source Code Enthought is to SciPy/Numpy as Revolution is to R. Main download link is http://www.scipy.org/Download Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 5. Disclaimer Time is even more limited than usual, so the goal is to illustrate what NumPy is, and what NumPy, SciPy and its colleagues can achieve. Some goals: Brief NumPy tutorial via demo. Uses of NumPy and SciPy, including SciKits. Brief data analysis demo with NumPy, SciPy and matplotlib. Concluding remarks. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 6. NumPy Basics The main data structure is a homogeneous multidimensional array – a table of elements all of the same type, indexed by a tuple of positive integers. Some examples are vectors, matrices, images and spreadsheets. Why not just a use a list of lists? NumPy provides functions that operate on an entire array at once (like R), Python does not...really. NumPy is full of syntax and time is limited, so let’s jump straight into a demo... Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 7. NumPy Basics Demo Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 8. Keep in Mind: Broadcasting vs. Recycling In NumPy, if two arrays do not have the same length and we try to, say, add them, 1 is appended to the smaller array so that the dimensions match. In R, if two vectors do not have the same length, the values in the shorter vector are recycled and a warning is generated. Personally, recycling seems more practical. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 9. Keep in Mind: Indexing! R starts its indices at 1 and ranges are inclusive (i.e. seq(1,3) -> 1, 2, 3) NumPy (and Python) starts its indices at 0 and ranges are exclusive (i.e. arange(1,3) -> 1, 2). Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 10. Keep in Mind: Data Type Matters! R does a good job of using the correct data type. NumPy requires you to make decisions about data type. Using int64 for 1 is typically wasteful. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 11. ipython: a replacement CLI I IPython is the recommended CLI for NumPy/SciPy. I will use IPython in my demo. 1 an enhanced interactive Python shell. 2 an architecture for interactive parallel computing. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 12. ipython: a replacement CLI II Some advantages over the standard CLI: 1 tab completion for object attributes and filenames, auto parentheses and quotes for function calls. 2 simple object querying object name? prints details about an object. %pdoc (docstring), %pdef (function definition), %psource (full source code). 3 %run to run a code file, much like source in R. Differs from import because the code file is reread each time %run is called. Also provides special flags for profiling and debugging. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 13. ipython: a replacement CLI III 4 %pdb for spawning a pdb debug session. 5 Output cache saves the results of executing each line of code. , , save the last three results. 6 Input cache allows re-execution of previously executed code using a snapshot of the original input data in variable In. (to rexecute lines 22 through 28, and line 34: exec In[22:29] + In[34]. 7 Command history with(out) line numbers using %hist. Can also toggle journaling with %logstart. 8 Execute system commands from within IPython as if you are in the terminal by prefixing with !. Use !!, %sc, %sx to get output into a Python variable (var = !ls -la). Use Python variables when calling the shell. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 14. ipython: a replacement CLI IV 9 Easy access to the profiler, %prun. 10 Easy to integrate with matplotlib. 11 Custom profiles (options, modules to load, function definitions). Similar to R workspace. 12 Run other programs (that use pipes) and extract output (gnuplot). 13 Easily run doctests. 14 Lightweight version control. 15 Save/restore session, like in R (the authors specifically said “like R”). Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 15. matplotlib: SciPy’s Graphics System I 2D graphics library for Python that produces publication quality figures. Quality with respect to R is in the eye of the beholder. Graphics in R are much easier to construct, and require less code. Graphics in matplotlib may look nicer; require much more code. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 16. matplotlib: SciPy’s Graphics System II Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 17. matplotlib: SciPy’s Graphics System III Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 18. matplotlib: SciPy’s Graphics System IV Show matplotlib gallery. I will do a demo of matplotlib in the data analysis demo, if time. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 19. Quick Linear Regression Demo Demo here. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 20. SciKits I SciKits are modules or “plug-ins” for SciPy; they are too specialized to be included in SciPy itself. Below is a list of some relevant SciKits. 1 statsmodels: OLS, GLS, WLS, GLM, M-estimators for robust regression. 2 timeseries: time series analysis. 3 bootstrap: bootstrap error-estimation. 4 learn: machine learning and data mining Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 21. SciKits II 5 sparse: sparse matrices 6 cuda: Python interface to GPU powered libraries. 7 image: image processing 8 optimization: numerical optimization For more information, see http://scikits.appspot.com/scikits. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 22. Scientific Software Relying on SciPy I Many exciting software packages rely on SciPy Python Based Reinforcement Learning, Artificial Intelligence and Neural Network Library. Built around a neural networks kernel. Provides unsupervised learning and evolution. http://www.pybrain.org PyMC Pythonic Markov Chain Monte Carlo. MCMC, Gibbs sampling, diagnostics PyML: SVM, nearest neighbor, ridge regression, multiclass methods, model selection, filtering, CV, ROC. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 23. Scientific Software Relying on SciPy II Monte: gradient based learning machines, logistic regression, conditional random fields. MILK: SVM, k-NN, random forests, decision trees, feature selection, affinity propagation. Modular toolkit for Data Processing: signal processing, PCA, ICA, manifold learning, factor analysis, regression, neural networks, mixture models. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 24. Scientific Software Relying on SciPy III PyEvolve: Genetic algorithms Theano: Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently: GPUs, symbolic expressions, dynamic C code generation. Orange: Data mining, visualization and machine learning. Full GUI and Python scripting. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 25. Scientific Software Relying on SciPy IV SAGE: a hodgepodge of open-source software designed to be one analysis platform. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 26. Pros/Cons I What NumPy/SciPy does better: 1 Much larger community (SciPy + Python). 2 Better, and cleaner graphics...slightly. 3 Sits on atop a programming language rather than being one. 4 Dictionary data type is very useful (Python). 5 Adheres to a system of thought (“Pythonic”) that is more flexible. 6 Memory mapped files and extensive sparse matrix packages. 7 Easier to incorporate into a company/development workflow. 8 Opinion: Developers don’t have to dive into C as soon as they do with R. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 27. Pros/Cons II What R does better: 1 One word data.frame. 2 Installation is simple and universal. 3 Application is self-contained (NumPy consists of several moving parts). 4 Very simple, user friendly syntax. 5 Graphics and analysis are fairly quick to code. 6 Much easier data input. 7 Handles missing values better. Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 28. The SciPy community is very useful, prolific and friendly. Project has very high morale. Some places to get help: 1 http://www.numpy.org: extensive documentation, examples and cookbook. 2 http://www.scipy.org: extensive documentation, examples and cookbook. 3 NumPy and SciPy mailing lists are helpful. 4 StackOverflow 5 IRC channel #scipy 6 Frequent sprints and hackathons. 7 SciPyCon (Austin, TX) 8 SoCalPiggies and LA Python (first meeting April 1!) Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 29. Keep in Touch! My email: [email protected] My blog: http://www.bytemining.com Follow me on Twitter: @datajunkie Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group
  • 30. References 1 NumPy http://www.numpy.org 2 SciPy http://www.scipy.org 3 SciKits http://scikits.appspot.com 4 iPython http://ipython.scipy.org/moin/ 5 matplotlib http://matplotlib.sourceforge.net/ Ryan R. Rosario NumPy/SciPy for Data Mining and Analysis Los Angeles R Users’ Group