In [8]:
# Importing libraries

import pandas as pd

import numpy as np

import theano
import theano.tensor as T

import cPickle

In [11]:
# Loading data

df = pd.read_csv('../data/test.csv')
df = df.astype(np.float64)

In [16]:
# Loading model

from logistic_regression_model import *

my_model_file = file('models/log_reg.model', 'rb')
my_model = cPickle.load(my_model_file)
my_model_file.close()

In [23]:
# Predicting categories

raw_pred = my_model.predict(df)
pred = [np.argmax(raw_pred[i,:]) for i in xrange(raw_pred.shape[0])]
print pred[0:10]


[2, 0, 9, 2, 3, 7, 0, 3, 0, 3]

In [24]:
# Storing prediction in a csv file

with open('results.csv', 'w') as of:
    of.write("ImageId,label\n")
    for x in enumerate(pred, start=1):
        of.write("%s,%s\n" % x)