Pages

Slides and Video from my talk about Big Data with Python in Portuguese

Thursday, July 4, 2013




Hi all,

It has been a while since my last technical posts. But it's for a great cause! I am writing the current book about recommender systems and it is taking some dedicated time to work on it! But great posts are coming to the blog.

I'd like to publish an on-line talk that I gave in June' 18 at #MutiraoPython, a great initiative that I started with my startup PyCursos, an learning school for teaching Python and applications on-line. It's like a Coursera MOOC's for Programming in portuguese!  This talk was part of a series of keynotes that are happening every week on-line for free using the Hangout on Air!



I gave a lecture for about two hours about Big Data with Python and presentend some tools used for data analysis. I know that I missed to explore more Pandas, Ipython, Scikit-learn. However, I decided to explore the Hadoop Architecture and MapReduce Paradigm and some code examples with Python.

It's in portuguese! But all the content is available for free! I hope you enjoy!

Video and code







Review about the book Learning IPython for Interactive Computing and Data Visualization

Monday, June 17, 2013



Hi all,

I was invited to review a copy of the book recently released titled "Learning IPython for Interactive Computing and Data Visualization" by the author Cyrille Rossant.  The book focus on one of the best tools for working with Python with the interactive incremented shell IPython.  By the way, it was the time to the tool receive a special book about it.


Learning IPython for Interactive Computing and Data Visualization

IPython is covered through the six chapters using several basic examples related to scientific computing  along with another Python tools such as Matplotlib, Numpy, Pandas, etc.  The first chapters explore the IPython basics such as installation, basic commands to get used with the tool.

The next chapters introduces NumPy and Pandas basics with the IPython shell active. Don't expect advanced examples with those tools. The idea is a simple demonstration of what we can do at IPython.

There is a chapter to discuss the visualization data with graphs, plottings with IPython Notebook. However I missed more details abot IPython notebook. It lacks more deep examples related to the topic.  

I really liked the chapter 5 when they showed some basics of MPI (Message Passing Theme), although the topic wasn't vasted explored. But the introduction gives a greate potential of usefulness to the more advanced books about IPython.

The last chapter shows how to create pluggins to IPython, for instance, create an simple extension that introduces a new cell magic (write C++ code directly in the cell, and it will be automatically compiled and executed).

My conclusion about the book is that it achieves the expected goal: a technical introduction to IPython. If you want a book to explore scientific computing or a advanced stuff to IPython, this is not the the book yet. I can say that this book is a first start for much more topics about the use of IPython.  MPI, IPython notebook, etc.  I recommend the book for start exploring the IPython as reference! :D


Regards,

Marcel

Review of the book Learning Scipy for Numerical and Scientific Computing

Monday, April 15, 2013


Hi all,

I've finished reading the book "Learning Scipy for Numerical and Scientific Computing".  This book comes to the scientific python series that PacktPub are bringing to the Python Developers! Congratulations!  As the title informs: it includes Scipy, Numpy and Matplotlib.  I only missed some further information about IPython, but it wasn't the goal of the book, so it goes well even leaved out.





It covers several important topics that are not as commonly covered, specially with several snippets illustrating special functions presented at Scipy library. For the developers it will be another great reference book to complement the native docs that comes with the library.  I enjoyed the author focused more on numerical analysis functions, it is one of the most used functions at the library.  

The bool also brings chapters on more specific applications: signal processing, data mining and computational geometry.  There is an extra chapter about the integration with another languages, but I found it not dense enough to explain those integrations. I really missed more start-off examples showing how to install the f2py or how to use Scipy with C/C++. 

Overall the Learning Scipy for Numerical and Scientific Computing book is a good book on Scipy covering  lots of mathematics with examples in Python. The book has a good size and it helps the scientists and scientific developers (by the way the non-developers will face some difficulties due to the heavy math that comes with the examples) to have a good overview on the library before exploring the reference material.


Thanks Kenny for the invitation to review this book, and congratulations to Francisco for bringing one more technical book for scientific python computing to the series!

Regards,

Marcel Caraciolo


Slides for Scientific Computing Meeting: Benchy and GeoMapper Visualization

Sunday, April 7, 2013



Hi all,

Yesterday it happened the XXVI local meeting of the Python Users Group at Pernambuco (PUG-PE).  In the occasion I had the opportunity to present two talks about scientific computing with python.


The first one was the lightweight framework for benchmark analysis on Python Scripts called Benchy, which I developed for about one week to help me on checking performance of several algorithms that I developed in Python.  I covered the framework at my last post which can be found here.


Here are the slides for the presentation:




The second talk was about a new type of visualization that I developed for social network analysis in order to check the degree of connections between the users at the socialnetwork using their geolocation data to present in a map.

The result was beautiful plots using this new type of visualization.  Amazing!

The slides are available here:



I hope you enjoy the slides, any further information feel free to comment!

Regards,

Marcel Caraciolo

Performing runtime benchmarks with Python Monitoring Tool Benchy

Friday, March 22, 2013


Hi all,

I've been working on in the last weeks at a little project that I developed called benchy.  The goal of benchy is answer some trivial questions about which code is faster ?  Or which algorithm consumes more memory ?  I know that there are several tools suitable for this task, but I would like to create some performance reports  by myself using Python.   

Why did I create it ?  Since the beginning of the year I decided to rewrite all the code at Crab, a python framework for building recommender systems.  And one of the main components that required some refactoring was the pairwise metrics such as cosine, pearson, euclidean, etc.  I needed to unit test the performance of several versions of code for those functions. But doing this manually ? It's boring. That's why benchy came for!


What benchy can do ?

Benchy is a lightweight Python library for running performance benchmarks over alternative versions of code.  How can we use it ?

Let's see the cosine function, a popular pairwise function for comparing the similarity between two vectors and matrices in recommender systems.




Let's define the benchmarks to test:



With all benchmarks created, we could test a simple benchmark by calling the method run:


The dict associated to the key memory represents the memory performance results. It gives you the number of calls repeat to the statement, the average consumption usage in units . In addition, the key 'runtime' indicates the runtime performance in timing results. It presents the number of calls repeat following the average time to execute it timing in units.

Do you want see a more presentable output ? It is possible calling the method to_rst with the results as parameter:


Benchmark setup
import numpy
X = numpy.random.uniform(1,5,(1000,))

import scipy.spatial.distance as ssd
X = X.reshape(-1,1)
def cosine_distances(X, Y):
    return 1. - ssd.cdist(X, Y, 'cosine')
Benchmark statement
cosine_distances(X, X)
namerepeattimingloopsunits
scipy.spatial 0.8.0318.3610ms


Now let's check which one is faster and which one consumes less memory. Let's create a BenchmarkSuite. It is referred as a container for benchmarks.:

Finally, let's run all the benchmarks together with the BenchmarkRunner. This class can load all the benchmarks from the suite and run each individual analysis and print out interesting reports:



Next, we will plot the relative timings. It is important to measure how faster the other benchmarks are compared to reference one. By calling the method plot_relative:




As you can see the graph aboe the scipy.spatial.distance function is 2129x slower and the sklearn approach is 19x. The best one is the numpy approach. Let's see the absolute timings. Just call the method plot_absolute:



You may notice besides the bar representing the timings, the line plot representing the memory consumption for each statement. The one who consumes the less memory is the nltk.cluster approach!

Finally, benchy also provides a full repport for all benchmarks by calling the method to_rst:




Performance Benchmarks

These historical benchmark graphs were produced with benchy.
Produced on a machine with
  • Intel Core i5 950 processor
  • Mac Os 10.6
  • Python 2.6.5 64-bit
  • NumPy 1.6.1

scipy.spatial 0.8.0

Benchmark setup
import numpy
X = numpy.random.uniform(1,5,(1000,))

import scipy.spatial.distance as ssd
X = X.reshape(-1,1)
def cosine_distances(X, Y):
    return 1. - ssd.cdist(X, Y, 'cosine')
Benchmark statement
cosine_distances(X, X)
namerepeattimingloopsunits
scipy.spatial 0.8.0319.1910ms

sklearn 0.13.1

Benchmark setup
import numpy
X = numpy.random.uniform(1,5,(1000,))

from sklearn.metrics.pairwise import cosine_similarity as cosine_distances
Benchmark statement
cosine_distances(X, X)
namerepeattimingloopsunits
sklearn 0.13.130.18121000ms

nltk.cluster

Benchmark setup
import numpy
X = numpy.random.uniform(1,5,(1000,))

from nltk import cluster
def cosine_distances(X, Y):
    return 1. - cluster.util.cosine_distance(X, Y)
Benchmark statement
cosine_distances(X, X)
namerepeattimingloopsunits
nltk.cluster30.010241e+04ms

numpy

Benchmark setup
import numpy
X = numpy.random.uniform(1,5,(1000,))

import numpy, math
def cosine_distances(X, Y):
    return 1. -  numpy.dot(X, Y) / (math.sqrt(numpy.dot(X, X)) *
                                     math.sqrt(numpy.dot(Y, Y)))
Benchmark statement
cosine_distances(X, X)
namerepeattimingloopsunits
numpy30.0093391e+05ms

Final Results

namerepeattimingloopsunitstimeBaselines
scipy.spatial 0.8.0319.1910ms2055
sklearn 0.13.130.18121000ms19.41
nltk.cluster30.010241e+04ms1.097
numpy30.0093391e+05ms1

Final code!

I might say this micro-project is still a prototype, however  I tried to build it to be easily extensible. I have several ideas to extend it, but feel free to fork it and send suggestions and bug fixes.  This project was inspired by the open-source project vbench, a framework for performance benchmarks over your source repository's history. I recommend!

For me, benchy will assist me to test several pairwise alternative functions in Crab. :)  Soon I will publish the performance results that we got with the pairwise functions that we built for Crab :)

I hope you enjoyed,

Regards,

Marcel Caraciolo