Tensorflow DNN多重分类

我试图用Tensorflow在Python 3.5中创建一个DNN,将元组分类到3个类中的一个。

# 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(和X_test)由7个数字列组成。 y_train(和y_test)由1个作为响应变量的数字列组成[0或1或2]。

当我用上述模型进行预测时,我的准确性非常差(准确率为50-70%)。

似乎我已经想出了为什么 - 我的模型预测新输入的类为0或2 ...所以它实际上丢失了所有类1的记录。

有人可以给我一个提示,为什么这是什么? 我读过softmax可能是解决方案......如果是这样,我很困惑为什么Tensorflow文档(章节入门/ Iris分类)中描述了为什么会有类似的DNN。

编辑:我当然试过这个不同的超参数。

干杯

伦纳特

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

上一篇: Tensorflow DNN Multiple Classification

下一篇: Parsing CSV Features into Tensorflow for ANN