11
WWW.THEDATAINCUBATOR.COM THE DATA INCUBATOR

R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

  • Upload
    lyquynh

  • View
    216

  • Download
    3

Embed Size (px)

Citation preview

Page 1: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

W W W . T H E D A T A I N C U B A T O R . C O M

Ranked: 16 R packages for Machine Learning

T H E D A T A I N C U B A T O R  

Page 2: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

Who We Are 

Michael Li- Co-Author & Founder of The Data Incubator 

Paul  Paczuski- CO-Author & The Data Incubator Fellow  

Like any good report, The Data Incubator Rankings will take into consideration a wide number of factors to showcase trends, and provide a sense of clarity as to programming biases, and preferred methods of the data science community. 

Disagree with our findings? Great, feel free to drop us a line- we love a good debate.

At The Data Incubator we pride ourselves on having the latest data science curriculum. Much of our curriculum is based on feedback from corporate and government partners about the technologies they are looking to learn.

However, we wanted to develop a more data-driven approach to what we should be teaching in our data science corporate training and our free fellowship for masters and PhDs looking to enter data science careers in industry. 

This report is the first in a series analyzing data science related topics. We thought it would be useful to the data science community to rank and analyze a variety of topics related to the profession in a simple, easy to digest cheat sheet, rankings or reports.

This first report ranks R packages for machine learning, and we're hoping to stir the pot a bit and get our colleagues to join the discussion. Our discoveries here aren't final, but rather serve to showcase the depth, and the breadth, of knowledge available to the data science community.  

Page 3: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The Rankings 

This project began  as a ranking of the top packages for all data scientists, but we soon found that the scope was too broad. Data scientists do many different things, and you can classify almost any R package as helping a data scientist.

For this ranking The Data Incubator focused on a number of criteria including an exhaust list of ML packages, and three objective metrics- total downloads, GitHub stars, and the number of Stack Overflow questions. 

One of the most repeatedly asked questions by the data scientists we train is "what is the best programming language for machine learning?"

The resulting discussion, depending on the day, either ends in a hotly contested debate between R, Python, and MATLAB fans, or a full on WWE wrestling match. 

Ultimately the programming language of choice for machine learning comes down to three criteria

- The type of problem the data scientist is working with  - Personal programming preferences - The type of machine learning they're looking to perform

In other words, it depends.

However, R is the leading choice among data professionals who want to understand data, using statistical methods and graphs. It has several machine learning packages and advanced implementations for the top machine learning algorithms. R is also open source.

Page 4: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The Rankings 

1 2 3 4 5 6 7 8 9

10 11 12 13 14 15 16

caret

randomforest

e10171

rpart

nnet

glmnet

tree

party

arules

rocr

gbm

RWeka

Rattle

earth

h2o

kernlab

Page 5: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The Rankings 

What are the most popular machine learning packages? We took a look at a ranking based on package downloads and social website activity.

The ranking is based on average rank of CRAN (The Comprehensive R Archive Network) downloads and Stack Overflow activity. CRAN downloads are from the past year.

Stack Overflow ranks the number of results based on package name in a question body, along with a tag 'R'.

GitHub ranking is based on the number of stars for the repository. See below for methodological details.

*All data was downloaded on January 19, 2017. CRAN download counts were from the past 365

days: January 19, 2016 to January 19, 2017.

Page 6: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The Insights 

Package details Its easy to see why caret is the leading R package, since it's generally used for creating machine learning workflow. 

Following caret are the implementation specific machine learning algorithims: random forests (randomForest), support vector machines (e1071), classification and regression Trees (rpart), and regularized regression models (glmnet).nnet implements neural networks, while the tree package also implements trees.

Perhaps not surprisingly, caret is on top. It's a general package for creating machine learning workflows, and it integrates well with some algorithm-specific packages, which come next in the ranking.

These include e1071 (for SVMs), rpart (trees), glmnet (regularized regressions), and, perhaps surprisingly for R, neural networks (nnet). See details on all of these packages below.

The ranking reveals the fragmentation of the R package community. Several of the top packages, such as rpart and tree, implement the same algorithms, which contrasts with the uniformity - and breadth - of Python's scikit-learn.

Still, if you're loving R's for its data manipulation capabilities (as in the tidyverse), then you can use these packages to perform some powerful modeling, instead of switching to Python. Further, as more features are added to modelr, a tidy tool, we may soon see it included in this list.

Caret on top. neural nets feature strongly among other algorithm heavyweights

Page 7: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The Insights  party is for recursive partitioning and visualization of binary trees, and arules is for association mining. SVMs and other kernel methods are implemented in kernlab.

The h2o package is for scalable machine learning, and is part of the larger H2O project. ROCR is for model evaluation, including ROC curves, while gbm implements gradient boosting. More partitioning algorithms can be accessed with RWeka, while rattle is an R GUI for data mining.

A few packages feature strongly on Github only: mlr and SuperLearner are 2 other meta-packages that offer similar functionality to caret, while ranger offers C++ implementations of random forests.

Last, OneR is number one on Stack Overflow, but the SO API often auto-corrects this to "one" so the result is unreliable.

Some Packages FeatureStrongly on GitHub & Stack Overflow Only 

Page 8: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The methodology 

A previous thought was to use Google to look up lists of "top R ML packages" and then trying to scrape all the package names, combine them, and use that list as a starting point. But setting aside the engineering task, we also found that the currently available lists were of poor quality relative to our needs. Many were outdated, didn't clearly specify methods, and were often quite subjective.

Upon realizing this it became clear that our ranking would prove to be useful to the data science community.

From the beginning, we envisioned our ranking being built on package downloads in combination with Stack Overflow and GitHub activity.

We knew that APIs existed that would provide us with these metrics. However, obtaining an initial list of all the R packages for Machine Learning was a tougher task. This list needed to be exhaustive, objective, and up-to-date. A bad initial list would affect our ranking dramatically.

Asking around helped. A friend pointed us to the "CRAN Task View: Machine Learning & Statistical Learning" which has a great list at the bottom, and is easy to scrape.

Its advantages are that the package list comes from an authoritative source (CRAN is the "official" R package repository) and it is regularly updated (last update: January 6, 2017). Kudos to the author, Torsten Hothorn, who is also very responsive via email.

Step 1: Create An Exhaustive List Of machine learning packages

Page 9: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The methodology 

GitHub

Initially, we looked for the packages' GitHub page by querying GitHub's search API for the package name, perhaps with "language:R", but this proved unreliable. It was sometimes hard to pick out the correct GitHub repo, and not all R packages are implemented using the R language (the "language:R" parameter in the search API seems to refer to the most popular language that the repository is written in).

Instead, we went back to CRAN to find these urls. Each package has an official CRAN page, which includes useful information, including source code links. This is where we got the packages' GitHub repository location.

After that, obtaining the GitHub stars was easy through their API.

Any good ranking  will need a clear definition of what "best" means, and needs to be constructed with good metrics.

We defined "best" as "most popular". This doesn't necessarily mean the packages are widely-loved (users could be frequently searching Stack Overflow because the API is horrible).

We chose three components for our ranking:

Downloads: number of downloads from a CRAN mirror GitHub: number of stars for package on its main repository page Stack Overflow: number of questions containing the package name and tagged with 'R'

CRAN Downloads

There are a few CRAN mirrors, and we used the R-Studio mirror since it has a convenient API. RStudio must be the most widely used IDE for R, but it is not the only one. Our ranking could be improved (though maybe not significantly) if we aggregated downloads from other CRAN mirrors.

Step 2: Determine Objective Metrics 

Page 10: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The methodology 

This project started as a ranking of the top packages for data science, but we soon found that the scope was too broad.

Data scientists do many different things, and you can classify almost any R package as helping a data scientist. Should we include string manipulation packages? How about packages to read data from databases?

A longer project, for another day, could be to use even more "Data Science" to come up with a ranking of the top R packages for doing "Data Science."

Stack Overflow

Getting useful results from Stack Overflow was tricky. Some R package names like tree and earth present obvious difficulties: Stack overflow results may not be filter to results just for the R package, so we first added an 'r' string to the query, which helped immensely.

A good (optimal?) strategy was to look for the package's name in the question body, and then add an 'r' tag (which is different from adding the 'r' string).

Building the ranking

We simply ranked the packages within each of the 3 metrics, and took the average ranking. Nothing fancy.

Conclusion: Top R Packages For Data Science?

Page 11: R Packages For Data Science - Blog | The Data Incubatorblog.thedataincubator.com/wp-content/uploads/2017/03/R-Packages... · G r ea t , feel fr ee t o dr op us a l i ne- w e l

T H E D A T A I N C U B A T O R  

The Resources

Become a Data Scientist

Source code is available on The Data Incubator's Github: https://github.com/thedataincubator/data-science-blogs/

If you're interested in learning more, consider taking a look at the following:

Data Incubator Links 

Connect with us on LinkedIn

Comprehensive R Archive Network (CRAN): https://cran.r-project.org/ 

modelr package: https://github.com/hadley/modelr 

CRAN Task View- Machine Learning & Statistical Learning: https://cran.r- project.org/web/views/MachineLearning.html

Torsten Hothorn: http://user.math.uzh.ch/hothorn/

Hire a Data ScientistTrain a Data Scientist

Join the conversation on Facebook Follow us on Twitter

Get The Data Science Fundamentals