# Using Python for building machine learning application

I'm currently using R to find the best approach to solving a machine learning problem. Once I've got the approach sorted, I will need to build this into an application which can be used by end users. My background is as a .NET developer. I see there are a few questions related to this, but my question is more about what I should use to build an end user product which incorporates machine learning.

From what I've seen so far, R is very powerful but does not integrate very well with other programming languages (and even less well with .NET).

So I'm trying to figure out the best approach for building the app. I see that Python is widely used by the ML community. Is this a good choice for building an app which will be delivered to users, or is it better as a scripting tool for prototyping etc? One benefit I can see is the range of machine learning libraries available, whereas .NET does not have a large range of libraries available. Performance concerns me given that it is interpreted.

Is Python my best choice, or would it be better to build the algorithms I need from scratch in C++, C# etc.?

• That sounds like a question that would be better suited to Stack Overflow, because it has to do with building a program and delivering a product to an end user. – chl May 15 '12 at 10:13
• A good course of action may be to leave this question open on stats for a while, due to its specialized nature, and then (if it gets no answers or no great accepted answer) migrate it to SO for further attention. Migration can be accomplished by community vote and/or by flagging the question for moderator attention. – whuber May 15 '12 at 11:34
• may be helpful: Machine Learning using Python – steffen May 16 '12 at 13:45
• I see two questions here: 1) library in python or do it yourself in C#/++ ? and 2) which language supports both ML libraries and plays well with C# ? Answer to first question is to use a library because more users => less bugs. The second question => we are not exactly experts for c#-to-other-language-bridges here ;) => stackoverlow – steffen May 16 '12 at 13:53

In my view, Python is a good choice for building the machine learning part (you don't say anything about the rest of your application, so I can't comment of that).

NumPy is powerful and mature, and has lots of numerical packages built on top of it.

For example, SciKits is a suite of such packages. It incorporates scikit-learn, which is

a Python module integrating classic machine learning algorithms in the tightly-knit scientific Python world (numpy, scipy, matplotlib). It aims to provide simple and efficient solutions to learning problems, accessible to everybody and reusable in various contexts: machine-learning as a versatile tool for science and engineering

With regards to performance, native NumPy operations are on par with their BLAS counterparts (they basically are wrappers around BLAS). Thus, NumPy code that can be expressed in terms of vector/matrix operations tends to be as fast as comparable C/Fortran code.

On the flip side, code expressed as Python loops can be slow. Additionally, it is hard to speed things up by using multiple threads. However, there are ways around both of these shortcomings: using multiprocessing instead of threading, numexpr, Cython and so on.

• However, it is mostly possible to speed up python code using multiple processes. The multiprocessing and futures module make it easy to do that. – bayerj May 17 '12 at 18:28
• Thank you for your answer, that will really help me to evaluate whether Python is the appropriate choice. – chrisb May 18 '12 at 15:01

Yes, python is a good choice for building a machine learning application. The primary scientific libraries, numpy and scipy, use C and Fortran for core loops, so they are often as fast as libraries in other languages.

Note that a drawback of python is that each python process can only utilize a single core for computation (because of the GIL) and python performance suffers if you try to have multiple cpu-intense threads running simultaneously.

• The GIL is mostly irrelevant for machine learning. The reason is that all heavy computation will be in C extensions (as numpy/scipy) and these can run on multiple cores anyway. – bayerj May 17 '12 at 18:25