In [1]:
#Import dependancies 
import tflearn
import pandas as pd
from sklearn.model_selection import train_test_split
from tflearn.data_utils import to_categorical, pad_sequences
import tensorflow as tf

In [2]:
#Gaming dataset
data = pd.read_csv("ign.csv")

# data = pd.to_numeric(data)
# data['score'] = data['score'].apply(lambda x: str(x))
data['editors_choice'] = data['editors_choice'].replace('N', 0)
data['editors_choice'] = data['editors_choice'].replace('Y', 1)

X = data[['platform', 'score', 'genre', 'score_phrase', 'release_year', 'genre']]
y = data[['editors_choice']]

In [3]:
#Split data into test and train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

y_test = y_test.values.tolist()
y_train = y_train.values.tolist()

In [4]:
#Data preprocessing
#Sequence padding

trainX = pad_sequences(X_train, maxlen=None, dtype='str')
testX = pad_sequences(X_test, dtype='str')
# Converting labels to binary vectors
trainY = to_categorical(y_train, nb_classes=2)
testY = to_categorical(y_test, nb_classes=2)

In [6]:
# Network building
net = tflearn.input_data([None, 100])
net = tflearn.embedding(net, input_dim=10000, output_dim=128)
net = tflearn.lstm(net, 128, dropout=0.8)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,
                         loss='categorical_crossentropy')

# Training
col = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
for x in col:
    tf.add_to_collection(tf.GraphKeys.VARIABLES, x)

model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(trainX, trainY, validation_set=(testX, testY), show_metric=True,
          batch_size=128)


WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.py:149 in __init__.: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
---------------------------------
Run id: HV5TAO
Log directory: /tmp/tflearn_logs/
WARNING:tensorflow:Error encountered when serializing data_augmentation.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
'NoneType' object has no attribute 'name'
WARNING:tensorflow:Error encountered when serializing data_preprocessing.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
'NoneType' object has no attribute 'name'
WARNING:tensorflow:Error encountered when serializing summary_tags.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
'dict' object has no attribute 'name'
---------------------------------
Training samples: 12478
Validation samples: 6147
--
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-2dcdd04801a7> in <module>()
     14 model = tflearn.DNN(net, tensorboard_verbose=0)
     15 model.fit(trainX, trainY, validation_set=(testX, testY), show_metric=True,
---> 16           batch_size=128)

/usr/local/lib/python2.7/dist-packages/tflearn/models/dnn.pyc in fit(self, X_inputs, Y_targets, n_epoch, validation_set, show_metric, batch_size, shuffle, snapshot_epoch, snapshot_step, excl_trainops, validation_batch_size, run_id, callbacks)
    212                          excl_trainops=excl_trainops,
    213                          run_id=run_id,
--> 214                          callbacks=callbacks)
    215 
    216     def predict(self, X):

/usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.pyc in fit(self, feed_dicts, n_epoch, val_feed_dicts, show_metric, snapshot_step, snapshot_epoch, shuffle_all, dprep_dict, daug_dict, excl_trainops, run_id, callbacks)
    312                                                        (bool(self.best_checkpoint_path) | snapshot_epoch),
    313                                                        snapshot_step,
--> 314                                                        show_metric)
    315 
    316                             # Update training state

/usr/local/lib/python2.7/dist-packages/tflearn/helpers/trainer.pyc in _train(self, training_step, snapshot_epoch, snapshot_step, show_metric)
    772         tflearn.is_training(True, session=self.session)
    773         _, train_summ_str = self.session.run([self.train, self.summ_op],
--> 774                                              feed_batch)
    775 
    776         # Retrieve loss value from summary string

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
    764     try:
    765       result = self._run(None, fetches, feed_dict, options_ptr,
--> 766                          run_metadata_ptr)
    767       if run_metadata:
    768         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
    941                 'Cannot feed value of shape %r for Tensor %r, '
    942                 'which has shape %r'
--> 943                 % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
    944           if not self.graph.is_feedable(subfeed_t):
    945             raise ValueError('Tensor %s may not be fed.' % subfeed_t)

ValueError: Cannot feed value of shape (128, 12) for Tensor u'InputData/X:0', which has shape '(?, 100)'

In [ ]:


In [ ]: