Calling back to the wise.io platform: MNIST demo

In this example, predicting which digit was written in a postage stamp, we've already build models on the wise.io machine intelligence platform. We'd like to predict on the testing data and see how well we do.

(c) wise.io 2012-2013

First, let's connect to the platform using our user credentials. You'll need to have the wise.io stack installed locally:

pip install wise

see http://docs.wise.io for complete API documentation.


In [11]:
import wise
# Connect to the MNIST project
mnist = wise.project("/wiseio/mnist", user="wiseio", address="http://beta.wise.io",password=open("pw","r").read().strip())
%pylab inline


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

above, the project is "wiseio/mnist" and the password is taken from a file ("pw") on the local machine.


In [12]:
# Grab a random sample from the testing data and predict the digit
import random
sample = mnist.select("test.csv", rows=random.randint(0,20000))

# Download and show the digit image
im = sample.ix[0].values.reshape((28,28))
figure(figsize=(2,2))
imshow(im, interpolation="nearest", cmap="gray");


The 'model_100' model is trained on the 784 pixel values of the training set images.


In [13]:
mnist.predict("model_100", sample)


Out[13]:
0 1 2 3 4 5 6 7 8 9
0 0 0 0 0.95 0 0.03 0 0 0.01 0.01

In [14]:
# Show variable importances from the model as an image
model = mnist.model("model_100")
imp_im = array(model.importances).reshape((28,28))
figure(figsize=(3,3))
imshow(sqrt(imp_im), interpolation="nearest", cmap="gray")


Out[14]:
<matplotlib.image.AxesImage at 0x10b03f550>

The above confirms our intuition that pixels near the center of the image are more important for classification.