Skip to content Skip to sidebar Skip to footer

Improving Accuracy Of A Tensorflow Neural Network- Python

This is a continuation of my first question: Receiving random cost output on tensorflow regression- python I am using a multi-layered perceptron ANN to predict the Phyla of bacteri

Solution 1:

I figured it out! In order to improve accuracy, it is necessary to break the train and test batches into random samples, else the network will not process necessary data and will fail. I have implemented this by rewriting the data formatting section as such:

df = pd.read_csv('/Users/zach/desktop/export.csv')
data_ = df.drop(['ID','Species'], axis=1)


n_classes = data_["Phylum"].nunique()

dim = 18learning_rate = 0.0001display_step = 10n_hidden_1 = 2000n_hidden_2 = 1500n_hidden_3 = 1000n_hidden_4 = 500X = tf.placeholder(tf.float32, [None, dim])

train_set = data_.sample(frac=0.75) #THIS ADDITION SPLITS THE DATA RANDOMLY AND TAKE 75% FOR TRAININGtest_set = data_.loc[~data_.index.isin(train_set.index)] #THIS TAKES THE REMAINING DATA FOR TESTINGtrain_size = train_set.size

inputY_test = pd.get_dummies(test_set['Phylum'])
inputY_train = pd.get_dummies(train_set['Phylum'])

train_X = train_set.iloc[:train_size, :-1].as_matrix()
train_X = pd.DataFrame(data=train_X)
train_X = train_X.fillna(value=0).as_matrix()

train_Y = inputY_train.as_matrix()
train_Y = pd.DataFrame(data=train_Y)
train_Y = train_Y.fillna(value=0).as_matrix()

test_X = test_set.iloc[:, :-1].as_matrix()
test_X = pd.DataFrame(data=test_X)
test_X = test_X.fillna(value=0).as_matrix()

test_Y = inputY_test.as_matrix()
test_Y = pd.DataFrame(data=test_Y)
test_Y = test_Y.fillna(value=0).as_matrix()

With these edits a simple run of 50 epochs, taking about 2 minutes, predicted the correct result with an accuracy of 91.4%

Post a Comment for "Improving Accuracy Of A Tensorflow Neural Network- Python"