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
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]:
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]:
The above confirms our intuition that pixels near the center of the image are more important for classification.