## how to compute true/false positives and true/false negatives in python for binary classification problems

Here’s how to compute true positives, false positives, true negatives, and false negatives in Python using the Numpy library.

Note that we are assuming a binary classification problem here. That is a value of `1` indicates a positive class, and a value of `0` indicates a negative class. For multi-class problems, this doesn’t really hold.

## Deep Dreams and a Neural Algorithm of Artistic Style – slides and explanations

Perhaps you saw an earlier post I wrote about deep dreaming Prague pictures, and you said to your self, “self, I wish I knew more about the techniques to make those crazy looking pictures.”

Well you are in luck since I’ve now posted the slides where I attempted to explain these two works to our reading group: 1) Google’s DeepDream, and 2) A Neural Algorithm of Artistic Style.

## How to debug a Jupyter/iPython notebook

Here’s how to debug your code when using a Jupyter/iPython notebook.

Use `Tracer()()`. Here’s an example using a simple function (based on this lucid explanation).

```  def test_debug(y): x = 10 # One-liner to start the debugger here. from IPython.core.debugger import Tracer; Tracer()() x = x + y   for i in range(10): x = x+i   return x   test_debug(10)```

When the debugger reaches the `Tracer()()` line, a small line to type in commands will appear under your cell.

Simply type in the variable names to check the values or run other commands. Below I’ve listed some practical Python PBD commands. More can be found here.
Continue reading “How to debug a Jupyter/iPython notebook”

## Napoleon: A Life – by Andrew Robert – audiobook review and notes

I recently finished the audiobook, “Napoleon: A Life” by Andrew Roberts. As you may expect from the title, this hefty audiobook (nearly 33 hours) gives great detail on the life of Napoleon Bonaparte.

What struck me most about the life of Napoleon was his ability to cope – no, more than cope, he thrived – in such an environment of confrontation. Napoleon waged wars against the strongest powers in Europe, and even when in massive confrontations, he wrote obsessive letters to people on seemingly trivial topics, detailing their marriages and affairs. Even when opposed by with such great forces, he did not shut down, he did not seek escapism, except perhaps for brief periods with his mistresses.

## The Signal and the Noise (book/audiobook review, summary and notes)

During an odd phase of fascination with American politics (I’m Canadian), I stumbled across Nate Silver’s website’s (fivethirtyeight.com) political coverage of the 2016 Idaho primary. Their cold, analytical coverage of the election appealed to me. It turns out Nate also wrote a book about prediction, which luckily for me, is also in audiobook format.

The core idea
The takeaway from this book is essentially this: prediction is really hard and most people (and machines) suck at it (expect for weather forecasters). More concerningly (is that a word?), most people don’t even know that they suck at it. Oh, and you should use Bayesian statistics to give probabilistic estimates and update your probabilities when you get new information.

This book encouraged me to take a hard look at my own predictions. Do I suck at it? Do I actually understand Bayes theorem?

## gae python – importerror: no module named webapp2

Scenario:
– Google app engine with Python on Ubuntu
– Running the local development server.

If you start getting this error:

`"importerror: no module named webapp2"`

after running,
`\$ dev_appserver.py helloworld/`

You might want to go back to an earlier version for local development.

After downloading “`google_appengine_1.9.37.zip`

I got errors with `import webapp2`

So I deleted 1.9.37. And used 1.9.34 instead.

Maybe this will work for you.

## Prague travel pictures and deep dreaming

Here is a combined short summary on my travels to the city of Prague in the Czech Republic along with corresponding images created using Google’s DeepDreams.

What is this DeepDreams you speak of?

Basically, DeepDream is a deep neural network that was trained to recognize objects from millions of images. A deep neural network is composed of a stack of layers. Basically, these layers learn image filters that when applied to an image classify the image (e.g., is this an image of a cat or a dog?).

You give DeepDream an image and specify a layer in the neural network. The original image is then slightly perturbed to create a modified image that causes the specified layer in the neural network to be more activated.

Early layers in the neural network are sensitive to low level concepts like the edges and textures in the image. So if you specify an early layer, your image will be modified to have edges and textures that most activate the early selected layer.

Later (or deeper) layers in the neural network are activated when they see higher level concepts such as faces. So any areas in the original image that slightly look like a face, will be modified to look more like a face.

Okay, but now you might ask, but what about Prague? How was your trip? Did you like the city?

Yeah it was nice! Thanks for asking. Did you want to see some pictures? Here’s one of an old building.

Let’s try some deep dreaming on this. We’ll use the neural network known as VGG16 (it’s a famous neural network that performs very well on competitions). We’ll start by telling VGG16 (the neural network) to modify this image so that one of it’s middle layers becomes more activated. Specifically, we will activate layer `conv3_1` from VGG16 (if you don’t know what conv3_1 means, that’s okay – it’s just a technical detail specifying what layer to use). This gives us this:

Now if we activate a deeper layer, `conv5_2`, we get this crazy looking image,

## How to run an IPython/Jupyter Notebook on a remote machine

Here’s how to run an IPython/Jupyter Notebook on a remote Linux machine without using VNC. I expanded on these instructions.

Let’s assume you have two machines:
`local-machine` that you are physically working on
`remote-machine` that you want to run code on.

And you want to work in the browser on your `local-machine`, but execute the code on the `remote-machine`.

Here are the important lines you’re probably looking for:

`jupyter notebook --no-browser --port=8898`
`ssh -N -f -L 127.0.0.1:8898:127.0.0.1:8898 jer@remote-machine`
`http://127.0.0.1:8898/`

If you want complete and detailed steps, keep reading below!

## Deep features to classify skin lesions – summary and slides

We presented our work, “Deep Features to Classify Skin Lesions” at ISBI 2016 in Prague! And I’m happy to report that our work was awarded runner-up for the Best Student Paper Award ðŸ™‚

In this work, we looked at how to classify skin lesions from images captured with a digital camera (i.e., non-dermoscopy). Our approach was able to distinguish among 10 different types of skin diseases over 1300 images and achieved an accuracy higher than what was previously reported over the same dataset. We did this by applying deep learning (i.e., pretrained convolutional neural networks) to melanoma and non-melanoma skin images.