Python, R or Scala - Which Programming Language Is Better in 2020

Python, R or Scala - Which Programming Language Is Better in 2020

This is my personal view and usage of the languages (R, Scala, and Python)

I recently answered the above question. I didn't phrase the question, but it's a good starting point. I typically stay away from language debates, but this one really interested me, as I have debated the question with myself a lot. I was researching this specific question because I wanted to know which language to use for my next data project. Here are my personal insights. Please let me know what you think!

I use R, Scala, and Python based on which is better-suited for my specific use cases. This is my personal view and usage of the languages.

Use R as a replacement for a spreadsheet. Together with RStudio, it makes a killer statistics, plotting, and data analytics application. You can take log files, parse them, graph them, pivot table them, filter them, etc. — and all with great support from RStudio. It’s a killer data analysis language and workspace. You should consider it as a replacement for spreadsheet workings.

Do you want to grep some lines from a text file? No problem! Just use dateLines <- grep(x = mylog, pattern = "--", value = TRUE). It’s a backfiring arrow and is easy to write once you know the command you need to use. It’s often very difficult to figure out the correct command to use; practice and note-taking are key. This requires time. Consider whether you have the time to commit to it. If not, just use it as your spreadsheet from time to time until you get better with it. Save a note or doc with useful R commands. You will find that with a few plotting commands, you can be a small king in its realm. This example of grep is only one of a million of abilities; RStudio will have you doing analytics like crazy on data.

If you have no time for the above, I still highly recommend that you install RStudio, use it from time to time, and get the hang of it. There is nothing like it that I know of that is so good for quick data analysis and statistics. Just give it a shot and try to replace your routine calculations and quick data manipulations tasks with it.

You can also move on and do machine learning in R. It has extremely powerful libraries for this (i.e. rpart, caret, e1071), and by all means, if you and your teams are fluent with it, feel free to use it. But personally, I would only use it for speculations and quick analysis or modeling. I stop there. It can be very quick, but this is when I turn to language #2: Python.

Use Python for small- to medium-sized data processing applications. Python introduced some type-checking in recent releases, which is awesome. Also, it's an interpreted language, so you have the great benefit of speed of programming. You just write your code and run. However, the caveat is that you don’t have the amazing compiler and features (the good ones, not the kitchen sink one) from Scala. As long as your project is small- to medium-sized, Python is a suitable option.

It's going to be very helpful as you utilize NLTK, matplotlib, numpy, and pandas — and you will have a great time using them. This will take you on the fast route to machine learning, with great examples bundled into the libraries.

I’m not saying you can't do this with R or Scala with great success — I’m just saying that for my personal use, this is the most intuitive way to do what I use it for.

Let's say that I want a quick analysis of CSV: I turn to R. If I want a bulletproof fast app to scale quickly, I use Scala. If my project is expected to be big and to involve many developers, I turn to language/framework #3: Java/Scala.

Use Scala or Java for larger robust projects to ease maintenance. While many would argue that Scala is bad for maintenance, I would argue that this is not necessarily the case. Java and Scala, with their mostly super-strongly typed and compiled features, are great languages for large-scale projects. You have Spark OpenNLP libraries for machine learning and big data. They are robust and they work at scale. It’s true that it will take you a longer time to code in them than in Python, but the maintenance and onboarding of new data will be easier — at least in my experience.

Data is modeled with case classes. It has proper function signatures, proper immutability, and proper separation of concerns.

While the above could be applied in any of these languages, it’s more natural with Scala/Java.

But if you don’t have the time or desire to work with them all, this is what I would do:

  • R: Good for research, plotting, and data analysis.

  • Python: Good for small- or medium-scale projects to build models and analyze data, especially for fast startups or small teams.

  • Scala/Java: Good for robust programming with many developers and teams; it has fewer machine learning utilities than Python and R, but it makes up for it with increased code maintenance.

It’s a challenge to learn them all. I’m still in this challenge, and it’s a true headache, but at the end, you benefit. If you want only one of them, I would consider the following:

  1. Am I managing a project with many teams and many workers, where speed is not the top priority, but stability? **Go with **Java/Scala.
  2. Am I managing few personal projects that require quick results, or quick machine learning for a startup? Go with Python.
  3. Do I just want to hack into my laptop data analysis and enhance my spreadsheet data analysis and machine learning skills? Go with Python or R.

Thanks for reading!

From ‘R vs Python’ to ‘R and Python’

From ‘R vs Python’ to ‘R and Python’

In this article, you'll learn to leverage the best of both ‘Python and R’ in a single project.

In this article, you'll learn to leverage the best of both ‘Python and R’ in a single project.

If you are into Data Science, the two programming languages that immediately come to mind are R and Python. However, instead of considering them as two options, more often than not, we end up comparing the two. R and Python, are excellent tools in their own right but are very often conceived as rivals. If you type R vs Python , in your Google search bar, you instantly get a plethora of resources on topics which talk about the supremacy of one over the other.

One of the reasons for such an outlook is because people have divided the Data Science field into camps based on the choice of the programming language they use. There is an R camp and a Python camp and history is a testimony to the fact that camps cannot live in harmony. Members of both the camps fervently believe that their choice of language is superior to the other. So, in a way, divergence doesn’t lie with the tools but with the people using those tools.

Why not use Both?

There are people in the Data Science community who are using both Python and R, but their percentage is small. On the other hand, there are a lot of people who are committed to only one programming language but wished they had access to some of the capabilities of their adversary. For instance, R users sometimes yearn for the object-oriented capacities that are native to Python and similarly, some Python users long for the wide range of the statistical distributions that are available within R.

The figure above shows the results of the survey conducted by Red Monk in the third quarter of 2018. These results are based on the popularity of the languages on Stack Overflow as well as on Github and clearly show that both R and Python are rated quite high. Therefore, there is no inherent reason as to why we cannot work with both of them on the same project. Our ultimate goal should be to do better analytics and derive better insights and choice of a programming language should not be a hindrance in achieving that.

Overview of R and Python

Let’s have a look at the various aspects of these languages and what’s good and not so good about them.

Python

Since its release in 1991, Python has been extremely popular and is widely used in data processing. Some of the reasons for its wide popularity are:

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

However, Python doesn’t have specialized packages for statistical computing, unlike R.

R

R’s first release came in 1995 and since then it has gone on to become one of the most used tools for data science in the industry.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

Performance wise R is not the fastest language and can be a memory glutton sometimes when dealing with large datasets.

Leveraging the best of Both Worlds

Could we utilize the statistical prowess of R along with the programming capabilities of Python? Well, when we can easily embed SQL code within either R or Python script, why not blend R and Python together?

There are basically two approaches by which we can use both Python and R side by side in a single project.

R within Python

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

PypeR provides a simple way to access R from Python through pipes. PypeR is also included in Python’s Package Index which provides a more convenient way for installation. PypeR is especially useful when there is no need for frequent interactive data transfers between Python and R. By running R through pipe, the Python program gains flexibility in sub-process controls, memory control, and portability across popular operating system platforms, including Windows, GNU Linux and Mac OS

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

pyRserve uses Rserve as an RPC connection gateway. Through such a connection, variables can be set in R from Python, and also R-functions can be called remotely. R objects are exposed as instances of Python-implemented classes, with R functions as bound methods to those objects in a number of cases.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

rpy2 runs embedded R in a Python process. It creates a framework that can translate Python objects into R objects, pass them into R functions, and convert R output back into Python objects. rpy2 is used more often since it is one which is being actively developed.

One advantage of using R within Python is that we would able to use R’s awesome packages like ggplot2, tidyr, dplyr et al easily in Python. As an example let’s see how we can easily use ggplot2 for mapping in Python.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

[https://rpy2.github.io/doc/latest/html/graphics.html#geometry](https://rpy2.github.io/doc/latest/html/graphics.html#geometry](https://rpy2.github.io/doc/latest/html/graphics.html#geometry) "https://rpy2.github.io/doc/latest/html/graphics.html#geometry](https://rpy2.github.io/doc/latest/html/graphics.html#geometry)")

Resources

You may want to have a look at the following resources for more in-depth review of rpy2:

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

Python with R

We can run R scripts in Python by using one of the alternatives below:

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

This package implements an interface to Python via Jython. It is intended for other packages to be able to embed python code along with R.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

rPython is again a Package Allowing R to Call Python. It makes it possible to run Python code, make function calls, assign and retrieve variables, etc. from R.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

SnakeCharmR is a modern overhauled version of rPython. It is a fork from ‘rPython’ which uses ‘jsonlite’ and has a lot of improvements over rPython.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

PythonInR makes accessing Python from within R very easy by providing functions to interact with Python from within R.

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

The reticulate package provides a comprehensive set of tools for interoperability between Python and R. Out of all the above alternatives, this one is the most widely used, more so because it is being aggressively developed by Rstudio. Reticulate embeds a Python session within the R session, enabling seamless, high-performance interoperability. The package enables you to reticulate Python code into R, creating a new breed of a project that weaves together the two languages.

The reticulate package provides the following facilities:

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

Resources

Some great resources on using the reticulate package are:

  • Object-oriented language
  • General Purpose
  • Has a lot of extensions and incredible community support
  • Simple and easy to understand and learn
  • packages like pandas, numpy and scikit-learn, make Python an excellent choice for machine learning activities.

Conclusion

Both R and Python are quite robust languages and either one of them is actually sufficient to carry on the Data Analysis task. However, there are definitely some high and low points for both of them and if we could utilize the strengths of both, we could end up doing a much better job. Either way, having knowledge of both will make us more flexible thereby increasing our chances of being able to work in different environments.

References:

Interfacing R and Python — Andrew Collier

http://blog.yhat.com/tutorials/rpy2-combing-the-power-of-r-and-python.html

Learn More

An A-Z of useful Python tricks

A Complete Machine Learning Project Walk-Through in Python

A Feature Selection Tool for Machine Learning in Python

Machine Learning: how to go from Zero to Hero

Learning Python: From Zero to Hero

Introduction to PyTorch and Machine Learning

NumPy Tutorial for Beginners

Python Tutorial for Beginners (2019) - Learn Python for Machine Learning and Web Development

Machine Learning A-Z™: Hands-On Python & R In Data Science

Python for Data Science and Machine Learning Bootcamp

Data Science, Deep Learning, & Machine Learning with Python

Deep Learning A-Z™: Hands-On Artificial Neural Networks

Machine Learning, Data Science and Deep Learning with Python

Machine Learning, Data Science and Deep Learning with Python

Complete hands-on Machine Learning tutorial with Data Science, Tensorflow, Artificial Intelligence, and Neural Networks. Introducing Tensorflow, Using Tensorflow, Introducing Keras, Using Keras, Convolutional Neural Networks (CNNs), Recurrent Neural Networks (RNNs), Learning Deep Learning, Machine Learning with Neural Networks, Deep Learning Tutorial with Python

Machine Learning, Data Science and Deep Learning with Python

Complete hands-on Machine Learning tutorial with Data Science, Tensorflow, Artificial Intelligence, and Neural Networks

Explore the full course on Udemy (special discount included in the link): http://learnstartup.net/p/BkS5nEmZg

In less than 3 hours, you can understand the theory behind modern artificial intelligence, and apply it with several hands-on examples. This is machine learning on steroids! Find out why everyone’s so excited about it and how it really works – and what modern AI can and cannot really do.

In this course, we will cover:
• Deep Learning Pre-requistes (gradient descent, autodiff, softmax)
• The History of Artificial Neural Networks
• Deep Learning in the Tensorflow Playground
• Deep Learning Details
• Introducing Tensorflow
• Using Tensorflow
• Introducing Keras
• Using Keras to Predict Political Parties
• Convolutional Neural Networks (CNNs)
• Using CNNs for Handwriting Recognition
• Recurrent Neural Networks (RNNs)
• Using a RNN for Sentiment Analysis
• The Ethics of Deep Learning
• Learning More about Deep Learning

At the end, you will have a final challenge to create your own deep learning / machine learning system to predict whether real mammogram results are benign or malignant, using your own artificial neural network you have learned to code from scratch with Python.

Separate the reality of modern AI from the hype – by learning about deep learning, well, deeply. You will need some familiarity with Python and linear algebra to follow along, but if you have that experience, you will find that neural networks are not as complicated as they sound. And how they actually work is quite elegant!

This is hands-on tutorial with real code you can download, study, and run yourself.

Python Tutorial - Learn Python for Machine Learning and Web Development

Python Tutorial - Learn Python for Machine Learning and Web Development

Python tutorial for beginners - Learn Python for Machine Learning and Web Development. Can Python be used for machine learning? Python is widely considered as the preferred language for teaching and learning ML (Machine Learning). Can I use Python for web development? Python can be used to build server-side web applications. Why Python is suitable for machine learning? How Python is used in AI? What language is best for machine learning?

Python tutorial for beginners - Learn Python for Machine Learning and Web Development

TABLE OF CONTENT

  • 00:00:00 Introduction
  • 00:01:49 Installing Python 3
  • 00:06:10 Your First Python Program
  • 00:08:11 How Python Code Gets Executed
  • 00:11:24 How Long It Takes To Learn Python
  • 00:13:03 Variables
  • 00:18:21 Receiving Input
  • 00:22:16 Python Cheat Sheet
  • 00:22:46 Type Conversion
  • 00:29:31 Strings
  • 00:37:36 Formatted Strings
  • 00:40:50 String Methods
  • 00:48:33 Arithmetic Operations
  • 00:51:33 Operator Precedence
  • 00:55:04 Math Functions
  • 00:58:17 If Statements
  • 01:06:32 Logical Operators
  • 01:11:25 Comparison Operators
  • 01:16:17 Weight Converter Program
  • 01:20:43 While Loops
  • 01:24:07 Building a Guessing Game
  • 01:30:51 Building the Car Game
  • 01:41:48 For Loops
  • 01:47:46 Nested Loops
  • 01:55:50 Lists
  • 02:01:45 2D Lists
  • 02:05:11 My Complete Python Course
  • 02:06:00 List Methods
  • 02:13:25 Tuples
  • 02:15:34 Unpacking
  • 02:18:21 Dictionaries
  • 02:26:21 Emoji Converter
  • 02:30:31 Functions
  • 02:35:21 Parameters
  • 02:39:24 Keyword Arguments
  • 02:44:45 Return Statement
  • 02:48:55 Creating a Reusable Function
  • 02:53:42 Exceptions
  • 02:59:14 Comments
  • 03:01:46 Classes
  • 03:07:46 Constructors
  • 03:14:41 Inheritance
  • 03:19:33 Modules
  • 03:30:12 Packages
  • 03:36:22 Generating Random Values
  • 03:44:37 Working with Directories
  • 03:50:47 Pypi and Pip
  • 03:55:34 Project 1: Automation with Python
  • 04:10:22 Project 2: Machine Learning with Python
  • 04:58:37 Project 3: Building a Website with Django

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading

Complete Python Bootcamp: Go from zero to hero in Python 3

Machine Learning A-Z™: Hands-On Python & R In Data Science

Python and Django Full Stack Web Developer Bootcamp

Complete Python Masterclass

Python Programming Tutorial | Full Python Course for Beginners 2019 👍

Top 10 Python Frameworks for Web Development In 2019

Python for Financial Analysis and Algorithmic Trading

Building A Concurrent Web Scraper With Python and Selenium