Getting Started with Machine Learning the Pragmatic Way

Qiang Xue
Capital One Tech
Published in
8 min readSep 13, 2017

As machine learning is being adopted to solve more and more interesting — yet more and more challenging — problems, the demand for people who can develop machine learning applications is ever-increasing. Companies across diverse industries are snatching up machine learning experts; causing a significant shortage of such talent on the job market for the foreseeable future. Fortunately, machine learning is no longer just for experts and you don’t need to have a PhD to learn it. Taking a pragmatic approach, a normal software engineer can learn to become a contributing machine learning engineer in a relatively short amount of time.

How I Got into Machine Learning

Over the past three months, I have been involved in a project to apply some of the latest machine learning techniques to improve text recognition on photographed documents. Unlike traditional Optical Character Recognition (OCR) technologies which work best on flat scanned documents, machine learning has the potential to find solutions for more complex scenarios such as poor lighting conditions, folded documents, intervening line strokes on the text, etc. For our project, we adopted some sophisticated deep learning algorithms (deep learning being part of a broader family of machine learning methods), including Convolutional Neural Network (CNN) and Recurrent Neural Network (RNN), and were able to demonstrate very satisfactory results at the end of the three-month period.

After years of effort from both academia and industry, the barrier to entry in machine learning has never been so low. You can find numerous resources that can help you get into this field more easily, including free courses and books online, open source projects that implement nearly every well-known machine learning algorithm, various public training datasets, and inexpensive and elastic cloud computing infrastructure. Looking back at my learning experience on this project, I believe that most software engineers can learn machine learning and make significant contributions to their machine learning projects. In this article, I will share my personal experience on how to achieve this goal.

Getting Your Hands Dirty

Like learning any other engineering subject, the best way to get started with machine learning is to get your hands dirty by setting up an environment and trying some existing machine learning applications. This will not only facilitate your study of the machine learning theories later, but also help you develop some machine learning intuition which is extremely important when you start working on real projects.

Languages and Libraries

First, you should install and learn Python (congratulations if you’re already a Python developer) which is the most popular language for machine learning. People do use other languages in the field such as Java, R, JavaScript, C++, Julia, Scala, Lua, etc, but as a beginner in machine learning you will find far more machine learning projects and examples written in Python.

TIP: If you are working on Mac OS and are new to Python, you may want to install virtualenv, which is a virtual Python environment isolated from other Python development. It will save you a lot of time trying to work against Mac OS which may prevent you from upgrading some Python packages needed by many machine learning libraries.

If you’re planning to work in Python, you will need to install the NumPy package and learn its usage. NumPy is a fundamental package for scientific computing that empowers many machine learning libraries. It lets you use some very succinct syntax to express complex matrix computations commonly seen in machine learning algorithms. People who have experience with R or MatLab will find similarities to NumPy.

TIP: There are many great Python and NumPy tutorials and books. As a newbie to Python, I took an afternoon reading through the Python Numpy Tutorial from the popular Stanford CS231n online course.

I also highly recommend installing Jupyter Notebook. This is a Web application that allows you to interactively write and execute Python code and visualize the execution results. In machine learning, people often spend a lot of time experimenting with different algorithm parameters and observing how they affect the results. Jupyter Notebook is perfect for such interactive experimentation needs.

And finally, you should install and learn to use some machine learning libraries to avoid building everything from scratch. There are many great choices in this area. Scikit-learn is probably the most popular entry point into machine learning, with many off-the-shelf algorithms, such as SVMs, Random Forests, Logistic Regression, etc. For deep learning, TensorFlow provides many low-level GPU-enabled building blocks and particularly excels in large-scale distributed machine learning. As a machine learning beginner, you may want to choose a library that fits your project, has a large community, and good documentation so you can easily seek help when encountering problems.

GPUs

GPUs are your friend when running machine learning algorithms that involve tremendous amounts of parallelizable computations. For such computations, GPUs often offer performance that is a magnitude better than CPUs.

With some good GPUs, either on premise or cloud-based, you need to install their drivers and GPU-enabled libraries so your machine learning algorithms can run on the GPUs. For example, if your GPUs are CUDA-compatible, you should install both CUDA and cuDNN; and if you plan to use TensorFlow, you should install its GPU-enabled version.

Running the First Example

Once you have an environment with Python, Numpy, and a suitable machine learning library, you can start to run some exciting machine learning applications. If you use TensorFlow, I would recommend you start with the MNIST example, the “Hello World” of machine learning. The example basically reads MNIST, a database of handwritten digits, uses the data to train a very simple classification algorithm with the goal of recognizing a digit from an image, and tests the algorithm to find out its classification accuracy. Initially you may be daunted by the math and terminologies used in the example tutorial. However, you can skip them temporarily and focus on making the example to run in your environment. After this example, you may try the deep learning version of MNIST or switch to other more interesting examples.

You don’t need to understand the example code at this stage. The main goal of this practice is to familiarize yourself with the typical tools, environments, and workflow that a machine learning application requires. Hopefully, after trying out some examples, you will be motivated to learn the theories behind these examples.

Learning the Theories

It requires some machine learning expertise to design new algorithms or understand existing ones. As machine learning is a very broad subject, to better use your time you should first learn some machine learning basics, and then focus on the topics relevant to your project. To make the theoretical study more effective, you should utilize the environment that you just set up to practice what you are learning about.

Math Prerequisites

There are some prerequisites to understanding machine learning theories including linear algebra, statistics and probability, and calculus. You don’t need to master them all — a quick review of the relevant parts is sufficient. If time is limited or you’re new to these subjects, I would recommend familiarizing yourself with basic matrix computations, including matrix dimensions, matrix addition and multiplication, etc., as you will need them later while implementing algorithms.

Mindset

I recommend taking at least one introductory course about machine learning. This will give you a global picture of the subject so that you can have some rough idea about what machine learning can do and which direction you should focus on for your project. This will also help you build up your machine learning vocabulary to better communicate with other people in the field.

There are many free online courses available on places such as Coursera, Udacity, Stanford. I personally spent an intensive whole week taking the course given by Andrew Ng and found it is extremely helpful. While the course does not contain up-to-date machine learning algorithms, it balances very well between breadth and depth. A large portion of this course explains the mathematics behind machine learning — it’s perfectly fine to skip them if you have a hard time grasping them and focus on understanding the general concepts and techniques.

If you prefer to learn by reading books, there are also a lot of free machine learning books available. For example, Deep Learning, a book written by three experts in the field, covers both mathematical background and deep learning techniques used by practitioners in industry; An Introduction to Statistical Learning, another award-winning machine learning book, gives a very comprehensive introduction to statistical learning methods.

Developing More Specific Expertise

Now that you have some basic knowledge and working experience with machine learning, you can dive more deeply into the machine learning topics that are most relevant to your project, through consulting with machine learning experts, reading the latest papers, and evaluating various open source projects, etc.

For the OCR project, my team was able to identify a related problem in the House Number Identification in Street View which Google solved using the CNN (Convolutional Neural Network) algorithm. Having learned the basics of machine learning and identified the specific topic I needed to delve into, I took the Stanford online course about CNN (which I highly recommend if your problem can be solved by CNN) and read a lot of papers about state-of-the-art CNN algorithms. These learnings helped me build a better understanding about CNN algorithms and how we could tweak them for our project.

TIP: If you are not sure which topics you should choose, this is the perfect time to consult with machine learning experts or find a mentor in the field. Go to your local machine learning meetups, attend conferences, or even enter a machine learning competition to find the experts who can help you.

Starting to Contribute

You are now in good shape to start contributing to a machine learning project.

Remember that instead of writing everything from scratch, you should first check to see if there’s an existing implementation of the algorithm most relevant to your project. Have you checked open source options? There are implementations for nearly every known machine learning algorithm and chances are you will find one that works for your project. For example, the aforementioned scikit-learn library provides many out-of-box machine learning solutions, and the TensorFlow library contains many examples of popular deep learning algorithms.

For the OCR project, my team used the deep-npr project as a starting point. After developing some intuition with the initial experiments, we switched to another open source project called crnn which is based on a combination of CNN and RNN and proved to be effective for our problem.

With a chosen algorithm, much of your time may be spent in optimizing the so-called hyperparameters, such as learning rate, regularization, dropout, etc. You may also face problems, such as deciding whether you should collect more training data or use a deeper neural network. For these problems, machine learning experts may offer a lot of insightful advice. I would also strongly recommend the presentation Nuts and Bolts of Applying Deep Learning which contains very practical advice applicable to many machine learning projects.

Staying Excited

I still remember how excited I was while learning about machine learning, an experience that has only occurred a few times in my life. Machine learning is an extremely powerful tool that every software engineer should, and can, master. Whether you studied the math prerequisites in school or not, whether you have experience with Python or not, these things can be developed on the job and with the supplemental help of outside tutorials, classes, and expert advice. So fellow developers — act now, get prepared to be surprised by the power of machine learning, and wow your team with the machine learning skills you can bring to your projects.

--

--

Qiang Xue
Capital One Tech

Distinguished Engineer @CapitalOne, Creator of @yiiframework