Showing posts with label comparison. Show all posts
Showing posts with label comparison. Show all posts

Wednesday, September 11, 2019

Typed Functional Languages 2019

This post is a brief status of the state of typed functional languages in late 2019.

Typed functional languages like Clean, Haskell and OCaml were developed within academia in the 1990s. Around 2010, languages like F# and Scala were gaining some acceptance in industry. Today there are many great typed functional languages, several used in industry. I will give a brief side by side introduction to the following languages:

  • F#
  • F*
  • Haskell
  • OCaml
  • Rust
  • Scala
  • TypeStript
Concepts from typed functional languages have also spread into object oriented languages like C++, C# and Java. The distinction between OOP and typed functional is fluid, so that list might seem a little arbitrary.

These languages are best of breed so the point of this article is not to compare them by merits, but to explore what language to use for what purpose. Follow up post covers F# vs Scala.


F# (F Sharp)


F Sharp


F# is a mature, open source, cross-platform, functional-first programming language. 
  • Core: Strict, strong, inferred, hybrid
  • Popularity: Some use in industry and backed by Microsoft
  • Complexity: Easy to learn, but part of a big ecosystem
  • Maturity: It is 14 years old and part of the .NET, so quite mature
  • Tooling: Very good
  • Cross platform: with Mono and .NET Core and JavaScript
  • IDE: Visual Studio, VS Code

Strengths

Simple, open source, cross platform with good integration with the whole .NET universe.
Well suited for backend programming, Azure, web-serving and finance.
Type providers give easy typed access to a lot of different data sources.

Issues

IDE, GUI programming and LINQ is not as well developed as for C#.


F* (F Star)


F Star

F* is a general-purpose functional programming language with effects aimed at program verification.

  • Core: Strict, dependently typed, tactical theorem prover, constraint solver, refinement type, algebraic effect tracking
  • Popularity: Research language with very few users
  • Complexity: Quite complex
  • Maturity: Several researchers are working on it, but it is not used a lot
  • Tooling: Not super polished, but build on top of good tooling in OCaml and F#
  • Cross platform: OCaml, F#, C, WASM and ASM
  • IDE: Support for Emacs

Strengths

F* has implemented a lot of powerful and interesting ideas that you can try and actually use. It is a very well developed dependently typed language.
Good for validating highly sensitive security programs, encryption protocols.

Issues

There is little adaptation and it has not stood the test of time yet.


Haskell


Haskell

Haskell is an advanced purely-functional programming language.
  • Core: Lazy, pure, effect tracking using effect monads
  • Popularity: Prestigious research language with some industry adoption. Number 19 on Red Monk June 2019 list
  • Complexity: Very complex language
  • Maturity: It has been around for 30 years, used in industry, used for research
  • Tooling: New build tool Stack is quite nice
  • Cross platform: Runs on OS X, Linux and Windows
  • IDE: Several decent plugins for: VSCode, emacs, Spacemacs, SpaceVim and IntelliJ

Strengths

Very influential research language, test bed for a lot of language research and development.
It has been optimized for years and has some use in industry.
Type classes are built into the language so you can reuse code very broadly.
Aesthetically pleasing if you love math or category theory.

Issues

It is a very complex language and tracking effect in non pure computations is quite hard.
It has some use in industry, but is still very much a research language.


OCaml



 OCaml is a strictly evaluated functional language with some imperative features.
  • Core: Strict, strong, inferred, hybrid
  • Popularity: Used as teaching language and by a few big companies
  • Complexity: It is a simple language to learn
  • Maturity: It has been around for 20 years and is used in industry so quite mature
  • Tooling: Recently it got a good build tool and package manager
  • Cross platform: Runs on a lot of different operating system, hardware
  • IDE: Language server with good integration with Eclipse, VS Code, Emacs and Vim

Strengths

Great REBL, very fast compiler, makes it suited for tooling. Facebook using it for web tooling.
Popular in theorem provers.

Issues

Concurrency is not great.


Rust


Rust
TM Mozilla

Rust is a multi-paradigm system programming language focused on safety, especially safe concurrency.
  • Core: Inferred, linear type, nominal, static, strict, strong, build around concurrency
  • Popularity: Quite popular and raising. No 21 on Red Monk June 2019 list
  • Complexity: Somewhat complex language
  • Maturity: Pretty new language, but used in Firefox and by AWS Firecracker
  • Tooling: Excellent build tool and package manager
  • Cross platform: Work on many different OSs
  • IDE: Good VS Code support

Strengths

Rust is a combination of ideas from OCaml, Haskell, C++, linear types and low level imperative control. It is very fast and well suited for system programming and secure programming. There is no garbage collector and no runtime, this makes Rust great for writing libraries and WebAssembly. Rust has started to make inroads in cloud infrastructure.

Issues

Getting rid of the garbage collector makes the language harder to understand and program in.
It is a pretty new language, still developing, and there are fewer libraries.


Scala


Scala

Scala combines object-oriented and functional programming in one concise, high-level language.

  • Core: Strict and lazy, nominal and structural, hybrid, implicits for IoC
  • Popularity: Very popular. No 13 on Red Monk June 2019 list. Spark is written in Scala
  • Complexity: It is a quite complex language, but it is easy to get started with
  • Maturity: Very stable. Run on JVM, well integrated with JVM ecosystem
  • Tooling: Great build tool and package managers
  • Cross platform: JVM and JS. Also early work on native / LLVM version
  • IDE: IntelliJ, VS Code, Eclipse

Strengths

Back-end programming, data engineering, web serving.
It is a great all around language. A lot of work has gone into creating language constructs that makes Scala work well with Java libraries. In Scala 2.0 this was not the case.
Spark is a cornerstone in data engineering.

Issues

There is quite a lot of complexity: Implicits, macros,  type classes / ad hoc polymorphism is possible but it takes some work.
Not super easy to set up a small project.
GUI programming support is not that great.


TypeStript


TypeScript

TypeScript brings you optional static type-checking along with the latest ECMAScript features.
  • Core: Gradually typed, structural, many new sophisticated type constructs, data language
  • Popularity: Very popular. No 10 on Red Monk June 2019 list
  • Complexity: Pretty complex
  • Maturity: A lot of money has gone into JavaScript, it is improving but it still feels wonky
  • Tooling: NPM. There are a lot of tools in the Nodes ecosystem, too many
  • Cross platform: Runs in every browser and on Node.js
  • IDE: Amazing support in VS Code

Strengths

Typescript makes big JavaScript codebases a lot more robust.
It is really easy to process semi structured data in json.
Starting to see some use of TS in machine learning e.g. with TensorFlow.js.

Issues

The JavaScript modules seem simple like in Python or Java, but there are many different module systems and it is pretty complicated. There are a lot of NPM packages but it still feels less mature. Getting setup with a small project with unit tests is more work than it should be.
Concurrency: Async await dramatically simplified call back style of programming, but still not great.


Golden Age Programming Languages


For many years I was puzzled about why language evolution seems to favor bloated and hacky development, while ignoring more principled computer science ideas. Twenty years ago I got very excited to read about these new functional languages with strong types. Unfortunately they were only popular in academia.

We are finally living in the golden age of programming languages. It just took some time. Development is moving quickly now and not slowing down.

Apologies in advance for omissions, outdated information and other mistakes.

Friday, April 26, 2019

Benefits of Different Python Distributions on Mac

There are at least 5 popular ways to install Python on OS X / Mac.

  • OS X default Python installation, currently Python 2.7.10
  • Use brew install python
  • Use brew install pyenv
  • Anaconda
  • Python pkg installer from python.org

I have used all of these distributions. They are all high quality and easy to install, but you run into conflicts later. You think that you are installing a library into one Python distribution but it get installed into another distribution so you cannot use it. This causes many frustrating errors.

Every time I install a Mac I have to decide what is the best Python distribution for my use case and there is no simple choice. It has been hard to find good documentation on the trade offs between the Python distributions. I have a compiled a short list of benefits and issues and where I think that the different distribution make sense.


OS X Default Python Installation


  • You don't have to install anything
  • If you only want to have one Python distribution this will be the one
  • It is a pretty recent version of Python 2.7 currently 2.7.10

Issue

  • Not supporting Python 3 which is now in common use

If you only are doing light Python 2 scripting this is probably the easiest choice.


brew install python


  • Brew is the de facto package manager on OS X so most software is installed with brew
  • Very up to date versions of Python 2 and Python 3
  • Works well when you want to install many Python libraries
  • Python 3 is the default, but brew install python@2 will install Python 2
  • It takes precedence over the OS X default Python by being in earlier on PATH env
  • Brew will probably install Python as a requirement for other packages so you get it whether you want it or not

Good for more demanding programming and installing libraries.


brew install pyenv 


  • pyenv is a tool to have different versions of Python to chose from
  • It has no dependencies on either Python 2 or 3 but manipulate PATH env
  • It can co exists with brew install python 
  • It can also work with virtual environments

Issues

  • You have to install other libraries say gzip before you can install this
  • Python is compiled from scratch and you easily run into compile problems

Good if you are a serious programmer who need many different versions of Python possibly with conflicting versions of libraries.


Use Anaconda


  • Anaconda installs different version of Python with high quality curated packages specialized for data science libraries
  • It can be hard to get data science libraries working with manual installs
  • It is a whole ecosystem of software 
  • Includes good Python GUI called Spyder
  • Great support for Jupyter notebook
  • Has good built in support for Python's virtual environments 

Issue

  • It is a pretty heavy distribution taking up around 3GB

I usually need the data science libraries so I install Anaconda but also end up with the brew version of Python.


Python pkg Installer From python.org


  • It is the official Python distribution
  • You can always get the newest version of Python
  • Self contained installer

It is an easy way to get the last versions of Python installed.

Tuesday, September 29, 2015

Practical Scala, Haskell and Category Theory

Functional programming has moved from academia to industry in the last few years. It is theoretical with a steep learning curve. I have worked with strongly typed functional programming for 4 years. I took the normal progression, first Scala then Haskell and ended with category theory.

What practical results does functional programming give me?

I typically do data mining, NLP and back end programming. How does functional programming help me with NLP, AI and math?

    Scala

    Scala is a complex language that can take quite some time to learn. For a couple of years I was unsure if it really improved my productivity compared to Java or Python.

    After 2 years my productivity in Scala went up. I find that Scala is an excellent choice for creating data mining pipelines because it is:
    • Fast
    • Stable
    • Has lot of quality libraries
    • Has a very advanced type system
    • Good DSL for Hadoop (Scalding)

    Natural Language Processing in Scala

    Before Scala I did NLP in Python. I used NLTK the Natural Language Toolkit for 3 years.

    NLTK vs. ScalaNLP


    NLTK

    • Easy to learn and very flexible
    • Gives you a lot of functionality out of the box
    • Very adaptable, handles a lot of different structured file formats

    What I did not like about NLTK was:
    • It had a very inefficient representation of a text features as a Dictionary
    • The file format readers were not producing exactly matching structures and this did not get caught by the type system
    • You have to jump between Python, NumPy and C or Fortran for low level work

    ScalaNLP

    ScalaNLP merged different Scala numeric and NLP libraries. It is a very active parent project of Breeze and Eric.

    ScalaNLP Breeze

    Breeze is a full featured, fast numeric library that uses the type system to great effect.
    • Linear algebra
    • Probability Distribution
    • Regression algorithms
    • You can drop down to the bottom level without having to program in C or Fortran

    ScalaNLP Eric

    Eric is the natural language processing part of ScalaNLP. It has become a competitive NLP library with many algorithms for several human languages:
    • Reader for text corpora
    • Tokenizer
    • Sentence splitter
    • Part-of-speech tagger
    • Named entity recognition
    • Statistical parser


    Video lecture by David Hall the Eric lead

    Machine Learning in Scala

    The most active open source Scala machine learning library is MLib which is part of the Spark project.
    Spark now has data frames like R and Pandas.
    It is easy to set up machine learning pipelines, do cross validation and optimization of hyper parameters.

    I did text classification and set it up in Spark MLib in only 100 lines of code. The result had satisfactory accuracy.

    AI Search Problem in Scala vs. in Lisp

    I loved Lisp when I learned it at the university. You could do all these cool Artificial Intelligence tree search problems. For many years I suffered from Lisp envy.

    Tree search works a little differently in Scala, let me illustrate by 2 examples.

    Example 1: Simple Tree Search for Bird Flu

    You have an input HTML page and parsed into a DOM tree. Look for the word bird and flu in a paragraph that is not part of the advertisement section.
    I can visualize what a search tree for this would look like.

    Example2: Realistic Bird Flu Medication Search

    The problems I deal with at work are often more complex:
    Given a list of medical websites, search for HTML pages with bird flu and doctor recommendations for medications to take. Then do a secondary web search to see if the doctors are credible.

    Parts of Algorithm for Example 2

    This is a composite search problem:
    • Search HTML pages for the words bird and flu close to each other in DOM structure
    • Search individual match to ensure this is not in advertisement section
    • Search for Dr names
    • Find what Dr name candidates could be matched up with the section about bird flu
    • Web search for Dr to determine popularity and credentials
    Visualizing this as a tree search is hard for me.

    Lazy Streams to the Rescue

    Implementing solutions to the Example 2 bird flu medication problem takes:
    • Feature extractors
    • Machine learning on top of that
    • Correlation of a disease and a doctor
    This lends itself well to using Scala's lazy streams. Scala makes it easy to use the lazy streams and the type system gives a lot of support, especially when plugging together various streams.

    Outline of Lazy Streams Algorithm for Example 2

    1. Stream of all web pages
    2. Stream of tokenized trees
    3. Steam of potential text matches e.g. avian influenza, H5N1
    4. Filter Stream 3 if it is an advertisement part of the DOM tree, (no Dr Mom)
    5. Stream of potential Dr text matches from Stream 2
    6. Stream of good Dr names. Detected with machine learning
    7. Merge Stream 3 and Stream 6 to get bird flu and doctor name combination
    8. Web search stream for the doctor names from Stream 7 for ranking of result

    AI Search Problem in Lisp

    Tree search is Lisp's natural domain. Lisp could certainly handle Example 2 the more complex bird flu medication search. Even using a similar lazy stream algorithm.

    Additionally, Lisp has the ability to do very advanced meta programming:
    Rules that create other rules or work on multiple levels. Things I do not know how to do in Scala.

    Lisp gives you a lot of power to handle open ended problems and it is great for knowledge representation. When you try to do the same in Scala you end up either writing Lisp or Prolog style code or using RDF or graph databases.

    Some Scala Technical Details

    Here are a few observations on working with Scala.

    Scala's Low Rent Monads

    Monads are a general way to compose functionality. They are a very important organizing principle in Scala. Except is not really monads it is just syntactic sugar.

    You give us a map and a flatMap function and we don't ask any questions.

    Due to the organization of the standard library and subtyping you can even combine an Option and a List, which should strictly not be possible. Still this give you a lot of power.
    I do use Scala monads with no shame.

    Akka and Concurrency

    Scala's monads make it convenient to work with two concurrency constructs: Futures and Promises.

    Akka is a library implementing an Erlang style actor model in Scala.
    I have used Akka for years and it is a good framework to organize a lot of concurrent computation that requires communication.

    The type system does not help you with the creation of parent actors so you are not sure that they exist. This makes it hard to write unit tests for actors.

    Akka is good but the whole Erlang actor idea is rather low level.

    Scalaz and Cake Patterns

    Scalaz is a very impressive library that implements big parts of Haskell’s standard library in Scala.
    Scalaz’s monad typeclass is invariant, which fixes the violations allowed in the standard library.

    Cake Patterns allows for recursive modules, which make dependency injection easier. This is used in the Scala compiler.

    Both of these libraries got me into trouble as a beginner Scala programmer. I would not recommend them for beginners.

    How do you determine if you should use this heavy artillery?
    Once you feel that you are spending a lot of time repeating code due to insufficient abstraction you can consider it. Otherwise:

    Keep It Simple.

    Dependent Types and Category Theory in Scala

    There are many new theoretical developments in Scala:
    • Dotty - a new compiler built on DOT a new type-theoretic foundation of Scala
    • Cats library - a simplified version of Scalaz implementing concepts from category theory
    • Shapeless library for dependent types. I am using this in my production code since Shapeless is used in Slick and Parboiled2


    Haskell

    Haskell is a research language from 1990. In 2008 its popularity started to rise. You can now find real jobs working in Haskell. Most publicized is that Facebook wrote their spam filter in Haskell.



    Why is Haskell so Hard to Learn?

    It took me around 2 years to learn to program in Haskell, which is exceptionally long. I have spoken to other people at Haskell meetups who have told me the same.

    Mathematical Precision

    Python effectively uses the Pareto principle: 20% of the features will give give you 80% of the functionality; Python has very few structures in the core language and reuses them.

    Haskell uses many more constructs. E.g. exception handling can be done in many different ways each with small advantages. You can chose the optimal exception monad transformer that has least dependencies for your problem.

    Cabal Hell and Stack

    Haskell is a fast developing language with a very deep stack of interdependent libraries.
    When I started programming in it, it was hard to set up even a simple project since you could not get the libraries to compile with versions that were compatible with each other.
    The build system is called cabal, and this phenomenon is called Cabal Hell.
    If you have been reading mailing list there are a lot of references to Cabal Hell.

    The Haskell consulting company FPComplete first released Stackage a curated list of libraries that works together. In 2015 they went further and released Stack which is a system that installs different versions of Haskell to work with Stackage versions.

    This has really made Haskell development easier.

    Dependently Typed Constructs in Haskell

    Dependently typed languages are the next step after Haskell. In normal languages the type system and the objects of the language are different systems. In dependently typed languages the objects and the types inhabits the same space. This gives more safety and greater flexibility but also makes it harder to program in.
    The type checker has to be replaced with a theorem-prover.

    You have to prove that the program is correct, and the proofs are part of the program and first order constructs.

    Haskell has a lot of activities towards emulating dependently typed languages.
    The next version of the Haskell compiler GHC 8 is making a big push for more uniform handling of types and kinds.

    Practical Haskell

    Haskell is a pioneering language and still introducing new ideas. It has clearly shown that it is production ready by being able to handle Facebook's spam filter.

    Aesthetically I prefer terse programming and like to use Haskell for non work related programming.

    There is a great Haskell community in New York City. Haskell feels like a subculture where Scala has now become the establishment. That said I do not feel Haskell envy when I program in Scala on a daily basis.

    Learning Haskell is a little like running a marathon. You get in good mental shape.


    Category Theory

    Category theory is often called Abstract Nonsense both by practitioners and detractors.
    It is a very abstract field of mathematics and its utility is pretty controversial.

    It abstracts internal properties of objects away and instead looks at relations between objects.
    Categories require very little structure and so there are categories everywhere.  Many mathematical objects can be turned into categories in many different ways. This high level of abstraction makes it hard to learn.

    There is a category Hask of Haskell types and functions.


    Steve Awodey lecture series on category theory

    Vector Spaces Described With a Few String Diagrams

    To give a glimpse of the power of category theory: In this video lecture John Baez shows how you can express the axioms of finite dimensional vector spaces with a few string diagrams.

    Video lecture by John Baez

    With 2 more simple operations you can extend it to control theory.

    Quest For a Solid Foundation of Mathematics

    At the university I embarked on a long quest for a solid scientific foundation. Fist I studied chemistry and physics. Quantum physics drove me to studying mathematics for more clarity. For higher clarity and a solid foundation I studied mathematical logic.
    I did not find clarity in mathematical logic. Instead I found:

    The Dirty Secret About the Foundation of Mathematics

    My next stop was the normal foundation for modern mathematics: ZFC, Zermelo–Fraenkel set theory with the axiom of choice.

    This was even less intuitive than logic. There were more non intuitive axioms. This was like learning computer science from a reference of x86 assembly: A big random mess. There were also an uncertain connection between the axioms of logic and the axioms set theory.

    ZFC and first order logic makes 2 strong assumptions:
    1. Law of Excluded Middle
    2. Axiom of Choice
    Law of Excluded Middle is saying that every mathematical sentence is either true or false. This is a very strong assumption that was not motivated at all. And it certainly does not extend to other sentences.

    Constructive Mathematics / Intuitionistic Logic

    There was actually a debate about what should be a foundation for mathematics at the beginning of the 20th century.
    A competing foundation of mathematics was Brouwer's constructive mathematics. In order to prove something about a mathematical object you need to be able to construct it and via the Curry-Howard correspondence this is equivalent to writing a program constructing a particular type.

    This was barely mentioned at the university. I had one professor who once briefly said that there was this other thing called intuitionistic logic, but it was so much harder to prove things in it, why should we bother.

    Recently constructive mathematics have had a revival with Homotopy Type Theory. HoTT is based on category theory, type theory, homotopy theory and intuitionistic logic.
    This holds a lot of promise and is another reason why category theory is practical for me.


    Robert Harper's lectures on type theory
    end with an introduction to HoTT

    Future of Intelligent Software

    There are roughly 2 main approaches to artificial intelligence
    • Top down or symbolic techniques e.g. logic or Lisp
    • Bottom up or machine learning techniques e.g. neural networks
    The symbolic approach was favored for a long time but did not deliver on its promise. Now machine learning is everywhere and has created many advances in modern software.

    To me it seems obvious that more intelligent software needs both. But combining them has been an elusive goal since they are very different by nature.

    Databases created a revolution in data management. They reduce data retrieval to simplified first order logic, you just write a logic expression for what you want.

    Dependently typed language is the level of abstraction where programs and logic merge.
    I think that intelligent software of the future will be a combination of dependently typed languages and machine learning.
    A promising approach is: Discovery of Bayesian network models from data. This finds causality in a form that can be combined with logic reasoning.

    Conclusion

    I invested a lot of time in statically typed functional languages and was not sure how much this would help me in my daily work. It helped a lot, especially with reuse and stability.

    Scala has made it substantially easier to create production quality software.

    MLib and ScalaNLP are 2 popular open source projects. They show me that Scala is a good environment for NLP and machine learning.

    I am only starting to see an outline of category theory, dependently typed languages and HoTT. It looks like computer science and mathematics are not mainly done, but we still have some big changes ahead of us.

    Thursday, June 24, 2010

    Orange, R, RapidMiner, Statistica and WEKA

    Review of open source and cheap software packages for Data Mining

    This blog posting is comparing the following tools, after working with them for 2 months and using them for solving a real data mining problem:
    • Orange
    • R
    • RapidMiner
    • Statistica 8 with Data Miner module
    • WEKA
    Statistica is commercial, all the other are open source. There is also a brief mention of the following Python libraries: mlpy, ffnet, NLTK.

    Summary of first impression

    This is a follow up on my previous post R, RapidMiner, Statistica, SSAS or WEKA describing my impression of the following software packages after using them for a couple of days each:
    • R
    • RapidMiner
    • SciPy
    • SQL Server Analysis Services, Business Intelligence Development Studio
    • SQL Server Analysis Services, Table Analysis Tool for Excel
    • Statistica 8 with Data Miner module
    • WEKA
    Let me summarize what I found:

    SciPy did not have what I needed. However I found a few other good Python-based solutions: Orange, mlpy, ffnet and NLTK.

    The SSAS-based solutions held promise due to their close integration with Microsoft products, but I found them to be too closely tied to data warehouses so I postponed exploring them.

    Statistica and RapidMiner had a lot of functionality and were polished, but the many features were overwhelming.

    R was harder to get started with and WEKA was less polished, so I did not spend too much time on them.

    Comparison matrix

    In order to compress my current findings I am summarizing it in this matrix. This metric is only based on limited work with the different software packages and is not very accurate. The categories are:
    Documentation; GUI and graphics; how polished the package is; ease of learning; controlling package from a script or program; how many machine learning algorithms that are available:

    DocGUIPolishedEaseScriptingAlgorithms
    Orange232332
    Python libs111332
    R322132
    RapidMiner232223
    Statistica333223
    WEKA222323

    Criteria for software package comparison

    The comparison is based on a real data mining task that is relatively simple:
    • Supervised learning for categorization.
    • Over 200 attributes mainly numeric but 2 categorical / text.
    • One of the categorical attributes is the most important predictor.
    • Data is clean, so no need to clean outliers and missing data.
    • Accuracy is a good metric.
    • GUI with good graphic to explore the data is a plus.

    General observations

    The most popular data mining packages in the industry are SAS and SPSS, but they are quite expensive. Orange, R, RapidMiner, Statistica and WEKA all can be used for doing real data mining work. While some of them are unpolished.

    There was a similar learning curve for most of the programs. Most programs took me a few days to get working, between the documentation and experimenting.

    I had to reformulate my original problem. Neural network models did not work well on my categorical / text attributes. Statistica produced an accuracy of 90%, while RapidMiner produced an accuracy of 82%.
    I replaced the 2 categorical attributes with a numeric attribute and accuracy of the best model increased to around 97%, and was much more uniform between the different tools.

    Orange

    Orange is an open source data mining package build on Python, NumPy, wrapped C, C++ and Qt.
    • Works both as a script and with an ETL work flow GUI.
    • Shortest script for doing training, cross validation, algorithms comparison and prediction.
    • I found Orange the easiest tool to learn.
    • Cross platform GUI.
    Issues:
    • Not super polished.
    • The install is big since you need to install QT.

    Python libs: ffnet, NumPy, mlpy, NLTK

    A few Python libs deserve to be mentioned here: ffnet, NumPy, mlpy and NLTK.
    • If you do not care about the graphic exploration, you can set up an ffnet neural network in few lines of code.
    • There are several machine learning algorithms in mlpy.
    • The machine learning is NLTK is very elegant if you have a text mining or NLP problem.
    • The libraries are self contained.
    Issues:
    • Limited list of machine learning algorithms.
    • Machine learning is not handled uniformly between the different libraries.

    R

    R is an open source statistical and data mining package and programming language.
    • Very extensive statistical library.
    • It is a powerful elegant array language in the tradition of APL, Mathematica and MATLAB, but also LISP/Scheme.
    • I was able to make a working machine learning program in just 40 lines of code.
    Issues:
    • Less specialized towards data mining.
    • There is a steep learning curve, unless you are familiar with array languages.

    R vs. Orange written in Python

    Python and R have a lot in common: they are both elegant, minimal, interpreted languages with good numeric libraries. Still they have a different feel. So I was interested in seeing how they compared.
    Orange / Python advantages
    • R is quite different from common programming languages.
    • Python is easier for most programmers to learn.
    • Python has better debugger.
    • Scripting data mining categorization problems is simpler in Orange.
    • Orange also has an ELT work flow GUI.
    R advantages
    • R is even more minimal than Python.
    • Numerical programming is better integrated in R, in Python where you have to use external packages NumPy and SciPy.
    • R has better graphics.
    • R is more transparent since the Orange are wrapped C++ classes.
    • Easier to combine with other statistical calculations.
    I made small script to solve my data mining problem in both Orange and R. This was my impression:

    If all you want to do is to solve a categorization problem I found Orange to be simpler. You have to become very familiar with how Orange read the spreadsheet, the different attribute types, notably the Meta attribute.

    Import and export of data from spreadsheet is easier in R, spreadsheet are stored in a data frames that the different machine learning algorithms are operating on. Programming in R really is very different, you are working on a higher abstraction level, but you do lose control over the details.

    RapidMiner

    RapidMiner is an open source statistical and data mining package written in Java.
    • Solid and complete package.
    • It easily reads and writes Excel files and different databases.
    • You program by piping components together in a graphic ETL work flows.
    • If you set up an illegal work flows RapidMiner suggest Quick Fixes to make it legal.
    Issues:
    • I only got it to works under Windows, but others have gotten it to work in other environments, see comment below.
    • There are a lot of different ETL modules; it took a while to understand how to use them.
    • First I had a hard time making a comparison between different models. Eventually I found a way: You chose a cross validation and select different models one by one. When you run the model the will all be stored on the result page and you can do comparison there.

    Statistica 8

    Statistica is a commercial statistics and data mining software package for Windows.
    There is a 90 day trial for Statistica 8 with data miner module in the textbook:
    Handbook of Statistical Analysis and Data Mining Applications. There is also a free 30 day trial.
    • Generally very polished and good at everything, but it is also the only non open source program.
    • High accuracy even when I gave it bad input.
    • You can script everything in Statistica in VB.
    • Cheap compared to SPSS and SAS.
    Issues:
    • So many options that it was hard to navigate the program.
    • The most important video about Data Miner Recipes is the very last out of 36.
    • Cost of Statistica is not available on their website.
    • It is cheap in a corporate setting, but not for private use.

    WEKA

    WEKA is an open source statistical and data mining library written in Java.
    • A lot of machine learning algorithms.
    • Easy to learn and use.
    • Good GUI.
    • Platform independent.
    Issues:
    • Worse connectivity to Excel spreadsheet and non Java based databases.
    • CSV reader not as robust as in RapidMiner.
    • Not as polished.

    RapidMiner vs. WEKA

    The most similar data mining packages are RapidMiner and WEKA. There have many similarities:
    • Written in in Java.
    • Free / open source software with GPL license.
    • RapidMiner includes many learning algorithms from WEKA.
    My first thought what that RapidMiner has everything that WEKA has, plus a lot of other functionality and is more polished. Therefore I did not spend too much time on WEKA. For the sake of completeness I took a second look at WEKA and I have to say that it was a lot easier to get WEKA to work. Sometimes less is more. Depending on what is more important functionality or ease of use.

    Conclusion

    There are several good and very different solutions. Let me finish by listing the strongest aspect of each tool:

    Orange has elegant and concise scripting and can also be run in an ETL GUI mode.
    R has elegant and concise scripting integrated with a vast statistical library.
    RapidMiner has a lot of functionality, is polished and has good connectivity.
    Statistica is the most polished product, and generally performed well in all categories. It gave good result when I gave it bad input.
    WEKA is the easiest GUI to learn and use.

    -Sami Badawi

    Friday, April 30, 2010

    R, RapidMiner, Statistica, SSAS or WEKA

    Choosing cheap software packages to get started with Data Mining

    You have a data mining problem and you want to try to solve it with a data mining software package. The most popular packages in the industry are SAS and SPSS, but they are quite expensive, so you might have a hard time convincing your boss to purchase them before you already have produced impressive results.

    When I needed data mining or machine learning algorithms in the past, I would program it from scratch and integrate it in my Java or C# code. But recently I needed a more interactive graphics environment to help with what is called Data Understanding phase in the CRISP-DM. I also wanted a way to compare the predictive accuracy of a broad array of algorithms, so I tried out several packages:
    • R
    • RapidMiner
    • SciPy
    • SQL Server Analysis Services, Business Intelligence Development Studio
    • SQL Server Analysis Services, Table Analysis Tool for Excel
    • Statistica 8 with Data Miner module
    • WEKA

    Disclaimer for review

    Here is a review of my first impression of these packages. First impression is not the best indicator for what going to work for you in the long run. I am sure that I have missed many features. Still I hope this can save you some time finding a solution that will work for your problem.

    R

    R is an open source statistical and data mining package and programming language.
    • Very extensive statistical library.
    • Very concise for solving statistical problems.
    • It is a powerful elegant array language in the tradition of APL, Mathematica and MATLAB, but also LISP/Scheme.
    • In a few lines you can set up an R program that does data mining and machine learning.
    • You have full control.
    • It is easier to integrate this into a work flow with your other programs. You just spawn an R program and pass input in and read output from a pipe.
    • Good plotting functionality.
    Issues:
    • Less interactive GUI.
    • Less specialized towards data mining.
    • Language is pretty different from current mainstream languages like C, C#, C++, Java, PHP and VB.
    • There is a learning curve, unless you are familiar with array languages.
    • R was created in 1990.
    Link: Screencast showing how a trained R user can generate a PMML neural network model in 60 seconds.

    RapidMiner

    RapidMiner is an open source statistical and data mining package written in Java.
    • Lot of data mining algorithms.
    • Feels polished.
    • Good graphics.
    • It easily reads and writes Excel files and different databases.
    • You program by piping components together in a graphic ETL workflows.
    • If you set up an illegal workflows RapidMiner suggest Quick Fixes to make it legal.
    • Good video tutorials / European dance parties. *:o)
    Issues:
    • I only got it to works under Windows, but others have gotten it to work in other environments.
    • Harder to compare different algorithms than WEKA.

    SciPy

    SciPy is an open source Python wrapper around numerical libraries.
    • Good for mathematics.
    • Python is a simple, elegant and mature language.
    Issues:
    • Data mining part is too immature.
    • Too much duct tape.

    SQL Server Business Intelligence Development Studio

    Microsoft SQL Server Analysis Services comes with data mining service.
    If you have access to SQL Server 2005 or later with SSAS installed, you can use some of the data mining algorithms for free. If you want to scale it can become quite expensive.
    • If your are working with the Microsoft stack this integrate well.
    • Good data mining functionality.
    • Organized well.
    • Comes with some graphics.
    Issues:
    • The machine learning is closely tied to data warehouses and cubes. This makes the learning curve steeper and deployment harder.
    • Documentation about using the BIDS GUI was hard to find. I looked in several books and several videos.
    • I need to do my data mining from within a web server or a command line program. For this you need to access the models using: Analysis Management Objects (AMO). Documentation for this was also hard to find.
    • You need good cooperation from your DBA, unless you have your own instance of SQL Server.
    • If you want to evaluate the performance of your predictive model, cross-validation is available only in SQL Server 2008 Enterprise.
    Link: Good screencast about data mining with SSAS.

    SQL Server Analysis Services, Table Analysis Tool Excel

    Microsoft Excel data mining plug-in is dependent on SQL Server 2008 and Excel 2007.
    • This takes less interaction with the database and DBA than the Development Studio.
    • A lot of users have their data in Excel.
    • There is an Analysis ribbon / menu that is very simple to use. Even for users with very limited understanding of data mining.
    • The Machine Learning ribbon has more control over internals of the algorithms.
    • You can run with huge amount of data since the number crunching is done on the server.
    Issues:
    • This also needs a connection to a SQL Server 2008 with Analysis Services running. Despite the data mining algorithms being relatively simple.
    • You need a special database inside Analysis Services that you have write permissions to.

    Link: Excel Table Analysis Tool video

    Statistica 8

    Statistica is a commercial statistics and data mining software package.
    There is a 90 day trial for Statistica 8 with data miner module in the textbook:
    Handbook of Statistical Analysis and Data Mining Applications. There is also a free 30 day trial.
    • Statistica is cheaper than SAS and SPSS.
    • Six hours of instructional videos.
    • Data Miner Recipes wizard is the easiest tool for a beginner.
    • Lot of data mining algorithms.
    • GUI with a lot of functionality.
    • You program using menus and wizards.
    • Good graphics.
    • Easy to find and clean up outliers and missing data attributes.
    Issues:
    • Overwhelming number of menu items.
    • The most important video about Data Miner Recipes is the very last.
    • Cost of Statistica is not available on their website.
    • It is cheap in a corporate setting, but not for private use.

    WEKA

    WEKA is an open source statistical and data mining library written in Java.
    • Many machine learning packages.
    • Good graphics.
    • Specialized for data mining.
    • Easy to work with.
    • Written in pure Java so it is multi platform.
    • Good for text mining.
    • You can train different learning algorithms at the same time and compare their result.
    RapidMiner vs WEKA:
    The most similar data mining packages are RapidMiner and WEKA. There have many similarities:
    • Written in in Java.
    • Free / open source software with GPL license.
    • RapidMiner includes many learning algorithms from WEKA.
    Therefore the issues with WEKA is really how it compares to RapidMiner.
    Issues compared to RapidMiner:
    • Worse connectivity to Excel spreadsheet and non Java based databases.
    • CSV reader not as robust.
    • Not as polished.

    Criteria for software package comparison

    My current data mining needs are relatively simple. I do not need the most sophisticated software packages. This is what I need now:
    • Supervised learning for categorization.
    • Over 200 features mainly numeric but 2 categorical.
    • Data is clean so no need to clean outliers and missing data.
    • Not important to avoiding mistakes.
    • Equal cost for type 1 and type 2 errors.
    • Accuracy is a good metric.
    • Easy to export model to production environment.
    • Good GUI with good graphic to explore the data.
    • Easy to compare a few different models e.g. boosted trees, naive bayes, neural network, random forest and vector support machine.

    Summary

    I did not have time to test all the tools enough for a real review. I was only trying to determine what data mining software packages to try first.
    Try first list
    1. Statistica: Most polished, easiest to get started with. Good graphics and documentation.
    2. RapidMiner: Polished. Simplest and most uniform GUI. Good graphics. Open source.
    3. WEKA: A little unpolished. Good functionality for comparing different data mining algorithms.
    4. SSAS Table Analysis Tool, Data Mining ribbon: Showed promise, but I did not get it to do what I need.
    5. SSAS BIDS: Close tie to cube and data warehouse. Hard to find documentation about AMO programming. Could possibly give best integration with C# and VB.NET.
    6. SSAS Table Analysis Tool, Analysis ribbon: Simple to use but does not have the functionality I need.
    7. R: Not specialized towards data mining. Elegant but different programming paradigm.
    8. SciPy: Data mining library too immature.
    Both RapidMiner and Statistica 8 do what I need now. So far I have found it easier to find functions using Statistica's menus and wizards, than RapidMiner's ETL workflows, but RapidMiner is open source. Still I would not be surprised if ended up using one or more than one package.

    Preliminary quality comparison of Statistica and RapidMiner

    I ran my predictive modeling task in both Statistica and RapidMiner. In the first match the model that preformed best in Statistica was neural network, with an error rate of approximately 10%.

    I ran the neural network in RapidMiner the error rate was approximately 18%. I was surprised about the big difference. The reason is probably that one of my most important attributes is categorical with many values, and neural network does not work well with that. Statistica might have preformed better due to more hidden layers.

    Second time I ran my predictive model, Statistica was having some numeric overflow for neural network and there were missing prediction values. This also surprised me I would expect that there could be problems with the training of the neural network, but not the calculation of and input on a trained model.

    These problems can easily be the result of me being unfamiliarity with the software packages, but this was my first impression.

    Link to my follow up post that is based on solving an actual data mining problem in Orange, R, RapidMiner, Statistica and WEKA after working with them for 2 months.

    -Sami Badawi