ML Programming Essentials
You might be an expert in TensorFlow or PyTorch, but you must take advantage of these open-source Python libraries to succeed
As you know, every machine learning application, including deep learning applications, follows a standard pipeline structure consisting of several steps. Over the years, most of these steps are also standardized in step level for the most part. Since the nature of the workload has become standard, researchers began to build frameworks, which provide solutions for repetitive tasks. The frameworks such as TensorFlow and PyTorch already offers us several modules for all these steps.
Even though deep learning frameworks are very powerful for model building, training, evaluation, and prediction tasks, they fail to compete with specialized complementary data libraries. Therefore, we still need these libraries for specific tasks, especially for data preparation and visualization. Although the potential libraries you may use in a deep learning pipeline may vary to a great extent, the most popular complementary libraries are as follows:
- NumPy for Array Processing
- SciPy for Scientific Computing
- Pandas for Array Processing & Data Analysis
- Matplotlib for Data Visualization
- Seaborn for Data Visualization
- Scikit Learn for Machine Learning
- Flask for Deployment
I am not very certain on the PyTorch side. However, on the TensorFlow side, especially after version 2.0 (released in October 2019), we started to see more data preparation, visualization, and other relevant capabilities added to TensorFlow. However, these capabilities cannot yet be compared to what these dedicated libraries have to offer.
Let me briefly introduce each of these libraries below
NumPy (i.e., Numerical Python) is a very popular open-source numerical Python library created by Travis Oliphant. NumPy provides multidimensional arrays along with a significant number of useful functions for mathematical operations.
NumPy acts as a wrapper around the corresponding library implemented in C. So; it offers the best of two worlds: (i) Efficiency of C and (ii) Ease-of-Use of Python. NumPy arrays are easy-to-create and efficient objects for (i) storing data and (ii) fast matrix operations. With NumPy, you can quickly generate arrays with random numbers, perfect for an enhanced learning experience and Proof-of-Concept tasks. The Pandas library, which we will cover later on, heavily relies on NumPy objects and almost works as a NumPy extension.
Thanks to NumPy arrays, we can process data in large volumes and do advanced mathematical operations with ease. Compared to built-in Python sequences, NumPy’s ndarray object executes much faster and more efficiently with less code. There are a growing number of libraries that rely on NumPy arrays for processing data, which shows the power of NumPy. Since deep learning models are usually trained with millions of data points, the size and speed superiority of NumPy arrays are essential for the machine learning experts.
Useful Information About NumPy:
SciPy is an open-source Python library that contains a collection of functions used for mathematical, scientific, and engineering studies. SciPy functions are built on the NumPy library. SciPy allows users to manipulate and visualize their data with an easy-to-use syntax. SciPy is a library that boosts developers’ data processing and system-prototyping capabilities and makes Python as effective as the rival systems such as MATLAB, IDL, Octave, R-Lab, and SciLab. Therefore, SciPy’s collection of data processing and prototyping functions strengthens Python’s already established superiority as a general-purpose programming language even further. SciPy’s vast collection of functions is organized into domain-based sub-packages:
Useful Information About SciPy:
Pandas is a Python library that offers flexible and expressive data structures suitable for performing fast mathematical operations. Python is a comprehensive and easy-to-use data analysis library, and it aims to become the leading open-source language-neutral data analysis tool.
1-dimensional Series and 2-dimensional DataFrames are the two main data structures in pandas. Since it extends the capabilities of NumPy and is built on top of NumPy, Pandas almost operates as a NumPy extension. Pandas also offers several data visualization methods, which are very useful to derive insights from the datasets.
You can analyze your data and perform several calculation tasks with Pandas. Here is a non-exhaustive list of the things you can do with Pandas:
Since pandas is a de facto extension of NumPy, which improves its capabilities, we take advantage of pandas more often than NumPy. But there are cases where we have to rely on NumPy due to limitations of other complementary libraries.
Useful Information About Pandas:
Matplotlib is a Python data visualization library for creating static, animated, and interactive graphs and plots. You can produce high-quality plots for academic publications, blogs, and books, and you can also derive insights from large datasets using matplotlib. In addition to deriving insights with your Google Colab notebook, you can also use the object-oriented API of matplotlib for embedding plots into applications.
The things you can do with matplotlib may be listed as follows:
Useful Information About Matplotlib
Besides vanilla matplotlib, Third-party packages are widely used for increasing the capabilities of matplotlib. One of the useful data visualization libraries built on top of matplotlib is Seaborn. Seaborn is a data visualization library based on matplotlib. It provides a high-level interface for extending the capabilities of matplotlib. You can reduce the time required to generate insightful graphs with seaborn.
Useful Information About Seaborn:
Scikit-learn is a powerful open-source machine learning library for Python, initially developed by David Cournapeau as a Google Summer of Code project. You can use scikit-learn as a stand-alone machine learning library and successfully build a wide range of traditional machine learning models. Besides being able to create machine learning models, Scikit Learn –built on top of NumPy, SciPy, & matplotlib– provides a simple and efficient predictive data analysis tool. There are six main functionalities of scikit-learn, which are listed below:
Classification
Scikit-learn offers several algorithms to identify which category an object belongs to, such as Support Vector Machines, logistic regression, k-nearest neighbors, decision trees, and many more.
Regression
Several algorithms offered by Scikit-learn can predict a continuous-valued response variable associated with an object, such as linear regression, gradient boosting, random forest, decision trees, and many more.
Clustering
Scikit-learn also offers clustering algorithms used for automated grouping of similar objects into clusters, such as k-means clustering, spectral clustering, mean-shift, and many more.
Dimensionality Reduction
Scikit-learn provides several algorithms to reduce the number of explanatory variables to consider, such as PCA, feature selection, non-negative matrix factorization, and many more.
Model Selection
Scikit-learn can help with model validation and comparison, as well as it can help choose parameters and models. You can compare your TensorFlow models with Scikit-learn’s traditional machine learning models. Grid search, cross-validation, and metrics are some of the tools used for model selection and validation functionality.
Preprocessing
With preprocessing, feature extraction, and feature scaling options, you can transform your data where TensorFlow falls short.
Scikit-learn is especially useful when we want to compare our deep learning models with other machine learning algorithms. Besides, with scikit-learn, we can preprocess our data before feeding it into our deep learning pipeline.
Useful Information About Scikit Learn:
As opposed to the libraries mentioned above, Flask is not a data science library, but it is a Python micro web framework. It is considered a microframework because it is not packaged with the components that the other web frameworks deem essential such as database abstraction layer and form validation. These components can be embedded in a Flask application with powerful third-party extensions. This characteristic makes Flask simple and light-weighted and reduces development time. Flask is a perfect option if you want to serve your trained deep learning models and don’t want to spend too much time on web programming.
Flask is easy to learn and to implement as opposed to Django. Django is a very well documented and popular web framework for Python. But due to its large size with many built-in extension packages, Django would be a better choice for large projects. At the moment, Flask has more stars on its GitHub repo than any other web framework for Python and is voted the most popular web framework in the Python Developers Survey 2018.
Useful Information About Flask:
In this post, we make an introduction to the most commonly used libraries complementary to TensorFlow. For basic projects, we are now capable of getting away with just using a deep learning framework such as PyTorch or TensorFlow, thanks to their growing number of modules addressing developers’ needs at every step of the pipeline. However, we still have to rely on these top 7 data libraries for more complex operations, especially when we need to gain insights from our dataset or conduct advanced data preprocessing operation and visualization tasks.
While NumPy and Pandas are compelling data processing libraries, matplotlib and Seaborn are useful for any data visualization task. SciPy helps us with complex mathematical operations, whereas Scikit Learn comes in handy for advanced preprocessing operations and validation tasks. Finally, Flask is the web framework of our choice to serve our trained models quickly. In fact, although not a deep learning project, I built a data visualization app using Flask. To learn more about this app, check out my post:
If you would like to have access to the codes of my other tutorial posts on Google Colab, and have early access to my latest content, consider subscribing to the mailing list:✉️
If you are interested in deep learning, also check out the guide to my content on artificial intelligence:
Since you are reading this article, I am sure that we share similar interests and are/will be in similar industries. So let’s connect via Linkedin! Please do not hesitate to send a contact request! Orhan G. Yalçın — Linkedin