Tensorflow DNN Multiple Classification

I'm trying to create a DNN in Python 3.5 with Tensorflow for classifying a tuple into one of 3 classes.

# define initial hyperparameters
batch_size = 100
train_steps = 5000
hidden_units=[10,20,10]

# build model
dnn = tf.contrib.learn.DNNClassifier(hidden_units=hidden_units,  feature_columns=feature_cols, n_classes=3)
input_fn = tf.estimator.inputs.pandas_input_fn(x=X_train, y=y_train, 
                                           batch_size=batch_size, 
                                           num_epochs=None, 
                                           shuffle=True)
# fit model to the data
dnn.fit(input_fn = input_fn, steps=train_steps)

# predict new data
predict_input_func = tf.estimator.inputs.pandas_input_fn(x=X_test,
                                                     batch_size=len(X_test), 
                                                     shuffle=False)
preds = dnn.predict_classes(input_fn=predict_input_func)

X_train (and X_test) consists of 7 numerical column. y_train (and y_test) consists of 1 numerical column acting as the response variable, [0 or 1 or 2].

When I predict with the above model, I get really bad accuracy (50 - 70% Accuracy).

It seems I have figured out why - my model predicts the class for new input to be either 0 or 2...so it loses all records which are class 1 actually.

Can someone give me please a hint why that is? I've read that softmax might be the solution...if so, I'm confused why there is a similiar DNN for 3 classes described in the Tensorflow docu (Chapter Get Started/Iris Classification).

Edit: I have of course tried this for different hyperparameters.

Cheers

Lennart

链接地址: http://www.djcxy.com/p/32118.html

上一篇: 如何加速张量流速的训练速度?

下一篇: Tensorflow DNN多重分类