Sharing a link to the KDNuggets article with thoughts provided by a few data scientists on main 2016 developments and what the trends for 2017 look like. Reinforcement Learning is mentioned more than once!
A brand new idea for my blog in 2017 is a monthly Did You Know That digest where I am going to share with you m things (where m<=3) that I recently learnt and found to be useful. I am going to keep such digests short and simple, as not to overwhelm you with verbiage and unnecessary details. This month’s top 3 Did you know that? are:
- scikit-learn SGDClassifier – one learner, many tricks up its sleeve;
- GraphViz is integrated in scikit-learn – no need no import it separately!
- Zeppelin notebook from Apache – worth a look if you are into Python notebooks;
This is a multi-classifier module that implements stochastic gradient descent. The loss parameter controls which model is used to train and perform classification. For example, loss=hinge will give a linear SVM, and loss=log will give a logistic regression. When should you use it? When your training data set does not fit into memory. Note that SGD also allows mini-batch learning.
GraphViz is Integrated in scikit-learn Decision Trees
If you read all my blog post, you may have come across this one where I put together some code to train a binary decision tree to recognize a hand in poker. The code is available on my github space. If you read the code, you will see that I defined graph_decision_tree method with all the hula-loops to graph and save the images. But did you know that you don’t need to do all this work since sklearn.tree has export_graphviz module? If dsTree is an instance of DecisionTreeClassifier, then one can simply do:
from sklearn.tree import export_graphviz export_graphviz(dsTree, out_file='dsTree.dot', feature_names=['feature1', 'feature2'])
The .dot file can be converted to a .png file (if you have installed GraphViz) like this:
dot -Tpng tree.dot -o tree.png
Zeppelin Notebook from Apache
If you are using Apache Spark you may be glad to learn that Apache has a notebook to go along with it. Zeppelin notebook offers similar functionality to Jupyter in terms of data visualization, paragraph writing and notebook sharing. I recommend that you to check it out.
Sharing a KDNuggets article on some examples of how PCA, Monte Carlo and linear regression are used in quantitative finance and risk management:
Greetings, my blog readers!
In this post I will tackle the link between the cost function and the maximum likelihood hypothesis. The idea for this post came to me when I was reading Python Machine Learning by Sebastian Raschka; the chapter on learning the weights on logistic regression classifier. I like this book and strongly recommend it to anyone interested in the field. It has solid Python coding example, many practical insights and a good coverage of what scikit-learn has to offer.
So, in chapter 3, section on Learning the weights of the logistic cost function, the author seamlessly moves from the need to minimize the sum-squared-error cost function to maximizing the (log) likelihood. I think that it is very important to have a clear intuitive understanding on why the two are equivalent in case of regression. So, let’s dive in!
Sum of Squared Errors
Using notation from , if is a training input variable, then is the target class predicted by the learning hypothesis . It is clear that we want to minimize the distance between the predicted and the actual class value , thus the sum-squared-error is defined as . The 1/2 in front of the sum is added to simplify the 1st derivative, which is taken to find the coefficients of regression when performing gradient descent. But one could easily define the cost function without the 1/2 term.
The sum-squared error is a cost function. We want to find a classifier (alternatively, a learning hypothesis) that minimizes this cost. Let’s call it . This is a very intuitive optimal value problem describing what we are after. It is like asking TomTom to find the shortest route to Manchester from London to save money on fuel. No problems! Done. A gradient descend (batch or stochastic) will produce a vector of weights , which when multiplied into the matrix of training input variables gives the optimal solution. So, the meaning of equation below should now be, hopefully, clear:
The MAP Hypothesis
The MAP hypothesis is a maximum a posteriori hypothesis. It is the most probable hypothesis given the observed data (note, I am using material from chapter 6.2 from  for this section). Out of all the candidate hypotheses in , we would like to find the most probable hypothesis that fits the training data well.
It should become intuitively obvious that, in case of a regression model, the most probable hypothesis is also the one that minimizes . In (2) we have a conditional probability. Using Bayes theorem, we can further develop it as:
is the probability of observing the training data. We drop this term because it is a constant and is independent of . is a prior probability of some hypothesis. If we assume that every hypothesis in is equally probable, then we can drop term from (3) as well (as it also becomes a constant). We are left with a maximum likelihood hypothesis, which is a hypothesis under which the likelihood of observing the training data is maximized:
How did we go from looking for a hypothesis given the data to the data given the hypothesis? A hypothesis that results in the most probable frequency distribution for the training data is also the one that is the most accurate about it. Being the most accurate implies having the best fit (if we were to generate new data under MAP, it would fit the training data best, among all other possible hypotheses). Thus, MAP and ML are equivalent here.
Bringing in the Binary Nature of Logistic Regression
Under the assumption of independent n training data points, we can rewrite (4) as a product over all observations:
Because logistic regression is a binary classification, each data point can be either from a positive or a negative target class. We can use Bernoulli distribution to model this probability frequency:
Let’s recollect that in logistic regression the hypothesis is a logit function that takes a weighted sum of predictors and coefficients as input. Also, a single hypothesis consists of a set of coefficients and the objective of is to find the coefficients that minimize the cost function. The problem here is that logit function is not smooth and convex and has many local minimums. In order to be able to use an optimal search procedure like gradient descend, we need to make the cost function convex. This is often done by taking the logarithm. Taking the log and negating (6) gives the familiar formula for the cost function J, which can also be found in chapter 3 of :
In this post I made an attempt to show you the connection between the usually seen sum-of-squared errors cost function (which is minimized) and the maximum likelihood hypothesis (which is maximized).
 Tom Mitchel, Machine Learning, McGraw-Hill, 1997.*
 Sebastian Raschka, Python Machine Learning, Packt Publishing, 2015.
* If there is one book on machine learning that you should read, it should be this one.
A great post from KDnuggets.com: