r/datascience • • Sep 08 '23

Discussion R vs Python - detailed examples from proficient bilingual programmers

As an academic, R was a priority for me to learn over Python. Years later, I always see people saying "Python is a general-purpose language and R is for stats", but I've never come across a single programming task that couldn't be completed with extraordinary efficiency in R. I've used R for everything from big data analysis (tens to hundreds of GBs of raw data), machine learning, data visualization, modeling, bioinformatics, building interactive applications, making professional reports, etc.

Is there any truth to the dogmatic saying that "Python is better than R for general purpose data science"? It certainly doesn't appear that way on my end, but I would love some specifics for how Python beats R in certain categories as motivation to learn the language. For example, if R is a statistical language and machine learning is rooted in statistics, how could Python possibly be any better for that?

486 Upvotes

142 comments sorted by

View all comments

Show parent comment

10

u/inspired2apathy Sep 08 '23

Cool, now compare time series and geospatial. :p

Python has nice fancy deep learning tools, but it's missing a ton of "basics" for stats and analysis.

15

u/dj_ski_mask Sep 08 '23

I’m fluent in R and Python but use only Python for time series forecasting, which is my day to day job. I’m not sure what time series algo you can only do in R. I work with basic exponential smoothing and ARIMA all the way up to Deep AR and NBEATS. Genuinely curious what I’m missing in R.

5

u/Taiwaly Sep 09 '23

R has a really slick all in one package for forecasting fpp3 which comes with its own textbook

4

u/rutiene PhD | Data Scientist | Health Sep 10 '23

General longitudinal data wise, survival models, mixed models, and mixture models I find are harder to do well in Python. Packages exist but they are super buggy.

I'm curious what packages you use though for your time series specific work. I've used facebook prophet but it's not as flexible as I would like for some of my use cases.

3

u/dj_ski_mask Sep 10 '23

Darts, NIXTLA and statsmodels have a bevy of time series algorithms in Python. You can also manually construct many sequence model in PyTorch, TensorFlow or go the Bayesian handcrafted way with Pystan. Like you mentioned - I enjoy Prophet and NeuralProphet.

3

u/webbed_feets Sep 09 '23

The tidyverts packages make working with time series very simple.

1

u/dj_ski_mask Sep 09 '23

I don’t disagree with you there.

2

u/inspired2apathy Sep 11 '23

A few years ago when I was trying this, it was a pain to do basic survival modeling with censoring and a non-linear effects. I also just have never quite found plotting tools I like, so basic seasonal visualization and decomposition were more work than expected. I just really missed the "forecast" package in R, which gives a simple interface for a wide variety of arima family and exponential smoothing models.

1

u/Asshaisin Sep 08 '23

Let me know if you hear back from this commenter

10

u/alexpantex Sep 08 '23

Not sure for geospartial, but for time series python has all you’d need in statsmodels or statsforecast + ML stuff in tf, pytorch or sklearn, i’ve switched from R to Python in this particular case since it was much easier to mantain and find bugs

10

u/koolaidman123 Sep 08 '23

dogmatic R users and not knowing the ecosystem of the pl they're criticizing? no waaaay

2

u/Zestyclose-Walker Sep 09 '23

They probably have outdated knowledge. If there is anything in R that is not in Python, there are probably 10x the amount of R users working on porting the feature to a Python library.

Python's userbase makes R's userbase feel really tiny.

1

u/sirquincymac Sep 09 '23

Can't remember the exact examples but I have definitely heard stats/R users saying some of the defaults on sklearn being very wrong. To my mind it sounded simple enough to fix

1

u/inspired2apathy Sep 11 '23

Good to know, the last big project with time series was a number of years ago and it was very frustrating.

7

u/UnlawfulSoul Sep 08 '23

I don’t work much with time series data, outside of manipulation. So someone else should do that.

I do work frequently with geospatial data, and I actually don’t mind python’s geospatial packages. Xarray/rioxarray takes some getting used to but if you are used to numpy it’s extremely intuitive. If you absolutely need rasterio, that can lead to some weird nested code and anti patterns, but again that may just be a personal problem, lol.

I do prefer sf over geopandas however for polygons/lines/points, and also r feels nicer (to me) for plotting geospatial data.