Share
Embed
Python for Data Science at Pivotal
Talk given at Python Ireland meetup
Python is a key part of the technology stack used at Pivotal for data science projects. In this talk I will outline how Python and the PyData ecosystem of projects has been used in a variety of customer projects, in small-, medium- and big-data scenarios.
Ian Huston
August 12, 2015
Transcript
47 slides
-
Python for Data Science at Pivotal • Ian Huston, Data
Scientist Ian Huston, Data Scientist Python Ireland August 2015 -
2 © Copyright 2015 Pivotal. All rights reserved. Who am
I? Ian Huston @ianhuston www.ianhuston.net Data Scientist Use PyData stack for predictive analytics and machine learning Previously a theoretical physicist using Python for numerical simulations & HPC -
3 © Copyright 2015 Pivotal. All rights reserved. Who are
Pivotal? OPEN DATA PLATFORM Pivotal Big Data Suite -
Data Scientist (n.): Person who is better at statistics than
any software engineer and better at software engineering than any statistician. - Josh Wills -
6 © Copyright 2015 Pivotal. All rights reserved. Plan 1
Python for Data packages and tools 2 Python in your database 3 Python in the cloud -
8 © Copyright 2015 Pivotal. All rights reserved. Why Python?
Powerful & simple syntax – great for interactive work Backed up with fast C & Fortran numerical libraries Growing community and set of libraries R is still extremely popular in data science GIL and multi-core support make scaling Python difficult -
10 © Copyright 2015 Pivotal. All rights reserved. Python for
Data community Pycon Ireland Data Science track! PyData conferences + videos – London, Berlin, multiple US locations #PyData on Twitter -
11 © Copyright 2015 Pivotal. All rights reserved. Packages -
Data Manipulation Low level array operations Data tables and in-memory manipulation Parallel out-of-core array manipulation High level interface for databases and different computational backends NumPy Dask -
12 © Copyright 2015 Pivotal. All rights reserved. Packages -
Modelling FFTs, integration, other general algorithms Statistical distributions and tests Machine Learning pipelines Bayesian Probabilistic Programming SciPy PyMC3 -
13 © Copyright 2015 Pivotal. All rights reserved. Packages -
Visualisation Widely used and powerful plotting package Opinionated but beautiful data visualisations Interactive plotting with server option Graphics API with translation between languages (e.g. Python -> D3) seaborn Bokeh -
14 © Copyright 2015 Pivotal. All rights reserved. IPython Notebooks
http://nbviewer.ipython.org/gist/fonnesbeck/2352771 -
18 © Copyright 2015 Pivotal. All rights reserved. Connected Car
http://tinyurl.com/pivotal-car https://github.com/pivotal/IoT-ConnectedCar -
20 © Copyright 2015 Pivotal. All rights reserved. Bring your
code to the data Procedural Python – support in PostgreSQL + others Use the expressive power of Python inside the database Reduce/remove large data movements Couple with distributed databases for simple parallelisation -
CREATE FUNCTION pymax (a integer, b integer)
RETURNS integer AS $$ if a > b: return a return b $$ LANGUAGE plpythonu; SQL wrapper Language Normal Python -
22 © Copyright 2015 Pivotal. All rights reserved. Data Parallelism
Little or no effort is required to break up the problem into a number of parallel tasks, and there exists no dependency (or communication) between those parallel tasks. Examples: – Measure the height of each student in a classroom (explicitly parallelizable by student) – MapReduce – map() function in Python -
23 © Copyright 2015 Pivotal. All rights reserved. PostgreSQL PostgreSQL
PostgreSQL PostgreSQL PostgreSQL -
26 © Copyright 2015 Pivotal. All rights reserved. Natural Language
Processing in-database Business Problem: Want to understand what is being discussed in millions of documents and whether authors feel positive about us Topic Modelling: Characterise documents based on topics contained within Sentiment Analysis: Score documents based on ‘sentiment’ (positive or negative) Natural Language ToolKit (NLTK) -
27 © Copyright 2015 Pivotal. All rights reserved. Topic and
Sentiment Analysis Pipeline Documents Load into database Parallel Parsing of JSON using PL/Python Topic Modelling Sentiment Analysis D3.js http://vimeo.com/79558274 NLTK -
Cloud Applications Haiku Here is my source code Run it
on the cloud for me I do not care how. - Onsi Fakhouri @onsijoe -
What is Cloud Foundry? http://cloudfoundry.org Open Source Multi-Cloud Platform Simple
App Deployment, Scaling & Availability -
33 © Copyright 2015 Pivotal. All rights reserved. Simple Flask
App Demo Simple one page “Hello World” web app Video: https://www.youtube.com/watch?v=QOfD6tnoAB8 Demonstrates: – Installation of requirements – Scaling properties Need to Provide: – App files – Dependencies listed in requirements.txt file – Optional manifest.yml file with configuration for deployment -
C F R O! U! T! E! R 2. Set
up domain Cloud Controller Instance 1. Upload code 4. Copy app into containerised instances 3. Install Python & Dependencies 5. Start app and accept connections Send request to URL WHAT JUST HAPPENED? Source Code Instance $ cf push Browser 5. Load balance between instances -
35 © Copyright 2015 Pivotal. All rights reserved. Python on
Cloud Foundry First class language (with Go, Java, Ruby, Node.js, PHP) Automatic app type detection – Looks for requirements.txt or setup.py Buildpack takes care of – Detecting that a Python app is being pushed – Installing Python interpreter – Installing packages in requirements.txt using pip – Starting web app as requested (e.g. python myapp.py) -
36 © Copyright 2015 Pivotal. All rights reserved. Official Python
Buildpack ü Great for simple pip based requirements ü Well tested and officially maintained ü Covers both Python 2 and 3 ✗ Suffers from the Python Packaging Problem: - Hard to build packages with C, C++ or Fortran extensions - Complicated local configuration of libraries and paths needed - Takes a long time to build main PyData packages from source -
37 © Copyright 2015 Pivotal. All rights reserved. Using conda
for package management http://conda.pydata.org Benefits: – Uses precompiled binary packages – No fiddling with Fortran or C compilers and library paths – Known good combinations of main package versions – Really simple environment management (better than virtualenv) – Easy to run Python 2 and 3 side-by-side Go try it out if you haven’t already! -
38 © Copyright 2015 Pivotal. All rights reserved. How to
use the conda buildpack https://github.com/ihuston/python-conda-buildpack Specify as a custom buildpack when pushing app with manifest or -‐b command line option. Export your current environment to a environment.yml file Or write requirements.txt (pip) and conda_requirements.txt Send me feedback & pull requests! -
R E S T A P I Send data as
JSON Data Ingest Model Create Model Redis Kicking off periodic retraining Save training data Save model object Send JSON data without label Receive prediction from trained model instance Deployed at:! http://dsoncf.cfapps.io! Code: https://github.com/pivotalsoftware/ds-cfpylearning PREDICTION API ARCHITECTURE $ cf create-‐service rediscloud PLAN_NAME INSTANCE_NAME -
41 © Copyright 2015 Pivotal. All rights reserved. Show off
your data science related Cloud Foundry apps: Twitter: @dsoncf http://dsoncf.com -
42 © Copyright 2015 Pivotal. All rights reserved. Resources
PyData.org PL/Python – see PostgreSQL docs CloudFoundry.org We’re hiring in Dublin & London: pivotal.io/careers Kevin Olsen [email protected] -
C F R O! U! T! E! R 2. Set
up domain Cloud Controller Instance 1. Upload code 4. Copy app into containerised instances 3. Install Python & Dependencies 5. Start app and accept connections Send request to URL WHAT JUST HAPPENED? Source Code Instance $ cf push Browser 5. Load balance between instances -
46 © Copyright 2015 Pivotal. All rights reserved. What just
happened? 1. Application code is uploaded to CF 2. Domain URL is set up ready for routing 3. Cloud controller builds application in container: – Python interpreter selected – Dependencies installed with pip 4. Container is replicated to provide instances 5. App starts and Router load balances requests -
47 © Copyright 2015 Pivotal. All rights reserved. Containers vs
Buildpacks runtime layer OS image application layer Container (e.g. Docker) system brings fixed host OS Kernel * Devs may bring a custom buildpack runtime layer* OS image application layer Buildpack App container System Provides Dev Provides system brings fixed host OS Kernel