# Mathematica-vs-R: Deep learning examples

## Introduction

This MathematicaVsR at GitHub project is for the comparison of the Deep Learning functionalities in R/RStudio and Mathematica/Wolfram Language (WL).

The project is aimed to mirror and aid the talk "Deep Learning series (session 2)" of the meetup Orlando Machine Learning and Data Science.

The focus of the talk is R and Keras, so the project structure is strongly influenced by the content of the book Deep learning with R, [1], and the corresponding Rmd notebooks, [2].

Some of Mathematica’s notebooks repeat the material in [2]. Some are original versions.

WL’s Neural Nets framework and abilities are fairly well described in the reference page "Neural Networks in the Wolfram Language overview", [4], and the webinar talks [5].

The corresponding documentation pages [3] (R) and [6] (WL) can be used for a very fruitful comparison of features and abilities.

Remark: With "deep learning with R" here we mean "Keras with R".

Remark: An alternative to R/Keras and Mathematica/MXNet is the library H2O (that has interfaces to Java, Python, R, Scala.) See project’s directory R.H2O for examples.

## The big picture

Deep learning can be used for both supervised and unsupervised learning. In this project we concentrate on supervised learning.

The following diagram outlines the general, simple classification workflow we have in mind.

Here is a corresponding classification monadic pipeline in Mathematica:

## Code samples

R-Keras uses monadic pipelines through the library `magrittr`. For example:

``````model <- keras_model_sequential()
model %>%
layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>%
layer_dropout(rate = 0.4) %>%
layer_dense(units = 128, activation = 'relu') %>%
layer_dropout(rate = 0.3) %>%
layer_dense(units = 10, activation = 'softmax')``````

The corresponding Mathematica command is:

``````model =
NetChain[{
LinearLayer[256, "Input" -> 784],
ElementwiseLayer[Ramp],
DropoutLayer[0.4],
LinearLayer[128],
ElementwiseLayer[Ramp],
DropoutLayer[0.3],
LinearLayer[10]
}]``````

## Comparison

### Installation

• Mathematica

• The neural networks framework comes with Mathematica. (No additional installation required.)

• R

• Pretty straightforward using the directions in [3]. (A short list.)

• Some additional Python installation is required.

TBD…

TBD…

### Encoders and decoders

The Mathematica encoders (for neural networks and generally for machine learning tasks) are very well designed and with a very advanced development.

The encoders in R-Keras are fairly useful but not was advanced as those in Mathematica.

[TBD: Encoder correspondence…]

## References

[1] F. Chollet, J. J. Allaire, Deep learning with R, (2018).

[2] J. J. Allaire, Deep Learing with R notebooks, (2018), GitHub.

[3] RStudio, Keras reference.

[4] Wolfram Research, "Neural Networks in the Wolfram Language overview".

[5] Wolfram Research, "Machine Learning Webinar Series".

[6] Wolfram Research, "Neural Networks guide".

# Applying Artificial Intelligence and Machine Learning to Finance and Technology

## Introduction

In this blog post I try to provide some further context for the panel discussion:

which was part of the conference "Data Science Salon Miami 2018" held in Miami on February 8 and 9.

The blog post can be read independently, but my intent is to provide a brief review of the discussion and further context to (some of) the answers. (It is probably better to see discussion’s recording first.)

You can also read the post by panel’s discussion host, Irma Becerra.

This blog post is not written by someone particularly enamored by Artificial Intelligence (AI), Data Science (DS), or Machine Learning (ML). I do like working in those disciplines, but I do think there are more interesting and fascinating mathematical disciplines than them. Also, I think AI, DS, and ML should be seen through the lens of Operations Research, which gives the most fruitful perspectives of their utilization.

The conference "Data Science Salon Miami 2018" included approximately 300 attendants. (I was told that there were ~60% data scientist and data analysts, and ~40% managers.)

## The panel people

Here is a list of the people participating in the panel (Irma was the host):

## The panel questions

Here are the main questions asked during the panel session:

1. What was your path to Data Science?

2. What are some misconceptions about AI? What do you see as being the future of AI?

3. How is artificial intelligence helping us engage with customers?

4. What techniques can we expect to see in terms of informing our marketing strategy so we can build predictive models to support our businesses? (backup question)

5. What can we do make advancements in Data Science more accessible to the public?

Here are some of the questions from the audience:

1. How to apply AI or Machine Learning to process automation?

2. What is going to happen if an adopted AI technology fails?

## On the main panel questions

### What was your path to Data Science?

All of the people in the panel became data scientists later in their career. Each of us at first was studying or doing something else.

Of course, that is to be expected since the term "data science" and the related occupation came into fashion relatively recently.

(Although apparently the term itself is fairly old.)

### What are some misconceptions about AI? What do you see as being the future of AI?

This is of course a long and fruitful topic.

Here — and during the panel session — I want to concentrate of what kind of thinking processes generate those misconceptions. (Obviously this is a less laborious task than enumerating and discussing the different concrete misconceptions.)

#### Weak AI

I side with the so called "Weak AI". Here are some summarizing points.

• Weak AI has a goal to adequately do certain mental tasks by humans. In general, Weak AI does not try to replicate the human approaches, methods, and algorithms for those tasks.

• All algorithms are based on 0s and 1s, so generally, I find "AI" misleading and "Strong AI" an interesting thing to think about, but far from practical use.

• Classifiers are just complicated if-statements.

• Derived with deep learning or other algorithms.

• Also, classification problems belong to the conceptually simplest ML branch (Supervised learning.)

Generally, my personal opinions on "AI" come from living through at least one AI winter, and being a subject in the AI effect.

#### The ingredients of coming to wrong ideas about AI

Study the following mind-map, "AI misconceptions reasons".

I think the major ingredients of getting the wrong AI ideas are two.

1. Confusion of high performance with competence.
• Often, confusion of high performance in some narrow problem domain with competence in an enclosing more general problem domain.
2. Exponential growth extrapolation of AI’s advances.

My favorite analogy to point 1 above is the following.

There are two principal ways to fish: (i) with bait and a fishing rod, and (ii) by draining the lake and picking the fish you want. Any other way of fishing is something in between. (For example, using a net or a bomb.)

So, the high performance of draining the lake can be confused with the ability of bait selection and fishing-spot picking. (And yes, not knowing how the AI algorithms work is a big misconception maker too.)

As an illustration of "draining the lake" approach to interesting puzzles humans play with, review (skim over) this article: "Solving Sudoku as an integer programming problem".

• We "drain the lake" by formulating an integer optimization problem with 729 variables and 1089 constraints. By solving the integer programming problem we "pick the fish."

• Note, that this is not even considered AI now. Granted, we do need a symbolic computations system like Mathematica, which is a very advanced system. (And yes, a good symbolic manipulation system can be seen as AI, especially 4-5 decades ago.)

### How is artificial intelligence helping us engage with customers?

I specialize in making recommenders and conversational agents.

For items that require significant investment in time (movies, books) or money (houses, automobiles, freelancers) recommenders have to make very good explanations of the recommendations. This is usually based on similarities to items consumed in the past or stated preferences.

For items that can be easily tried on and discarded (songs) we are better off making prediction algorithms that predict the "survival" of the item in customer’s mind. (How long a song is going to be in a playlist?)

The recommenders I developed in the past tend to be very agile : fast, easy to tune, with clear "recommendation proofs." Very often the agility of the recommender system is more important that giving good or precise recommendations "out of the box."

Customer engagement through conversational agents is much more about envisioning of the right work-flow and mind-flow of the customer. Although clarity and simplicity are important, I like the idea of using grammar rules and agent names that are challenging or intriguing. (Like, "Will they kill me?" or "I wanna eat!".)

### What techniques can we expect to see in terms of informing our marketing strategy so we can build predictive models to support our businesses?

In many ways the application of AI to Finance is somewhat easier, since financial data tends to be well-curated.

For example,

• in healthcare different patient health data can be messy (and incomplete) and generally speaking human body is inherently complex;

• health insurance financial data, though, is well-curated (since people need to get payed) and fairly simple.

To clarify, if we have records with four columns:

``   claim ID, claim total amount, transaction amount, timestamp``

then we are already in a position to do a fair amount of modeling and prediction.

### What can we do make advancements in Data Science more accessible to the public?

1. it is important to be able to communicate AI and ML concepts, ideas, and functionalities to stakeholders in business projects and, generally, to curious people, but

2. from the other hand, some of the underlying algorithms require mastery of multiple computer science and mathematical disciplines.

In other words:

1. of course the data scientist knowing his stuff should be able to explain the AI and ML functionalities to laypersons, but

2. from the other hand, "art is for the educated."

I would like to point out that technology itself has already democratized and popularized the AI and ML advancements. Everyone is familiar with, say, content recommendations, search queries completion, and optical character recognition. Few decades ago these functionalities would have been considered science fiction or part of Strong AI.

## Some afterthoughts

• The main panel questions and the questions from the audience made me want to discuss a general classification of the AI application — study the following mind-map "Application of AI and ML".