2

I am using the Tensorflow DNNClassifier for my dataset that has 25 features, and 12 class labels.

My code right now is:

def main():
    training_set = tf.contrib.learn.datasets.base.load_csv_without_header(filename=TRAINING,target_dtype=np.int,features_dtype=np.float32)
    test_set = tf.contrib.learn.datasets.base.load_csv_without_header(filename=TEST,target_dtype=np.int,features_dtype=np.float32)
    feature_columns = [tf.contrib.layers.real_valued_column("", dimension=25)]
    classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,activation_fn = tf.nn.relu,hidden_units=[50, 50, 50, 50, 50,50, 50, 50, 50, 50],optimizer=tf.train.AdamOptimizer(0.01),n_classes=12, model_dir="./model/")
    def get_train_inputs():
        x = tf.constant(training_set.data)
        y = tf.constant(training_set.target)
        return x, y
    classifier.fit(input_fn=get_train_inputs, steps=1000)
    def get_test_inputs():
        x = tf.constant(test_set.data)
        y = tf.constant(test_set.target)
        return x, y

    accuracy_score = classifier.evaluate(input_fn=get_test_inputs,steps=1)["accuracy"]
    print("\n\nTest Accuracy: {0:f}\n".format(accuracy_score))
    def new_samples():
        with open(PREDICT,"r") as f:
            contents = f.readlines()
        arr = []
        for c in contents:
            arr.append([float(x.strip()) for x in c.split(",")])
        return np.array(arr, dtype=np.float32)
    predicted_classes = list(classifier.predict(input_fn=new_samples))
    print("Predicted class: {}\n".format(predicted_classes))
    probabilities = list(classifier.predict_proba(input_fn=new_samples))
    print("Predictions probability: ", probabilities)
    probabs = np.array(probabilities)

The accuracy on both the training and test data is less than 0.2

I have tried more epochs, changing the learning rate, activation function and optimizer, but the accuracy is not increasing.

According to my knowledge, my network is underfitting severely. In which case adding more nodes and layers should work, but increasing the nodes and layers barely increases the accuracy and it is still below 0.2

Can anyone please point out mistakes in my code, if any?

skooly
  • 21
  • 2

0 Answers0