Python Tensorflow DNN多重分类
我试图用Tensorflow在Python3.5中创建一个DNN,用于将元组分类为3类之一Python Tensorflow DNN多重分类,python,tensorflow,neural-network,classification,Python,Tensorflow,Neural Network,Classification,我试图用Tensorflow在Python3.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
# 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_列(和X_测试)由7个数字列组成。
y_序列(和y_测试)由1个数字列组成,作为响应变量[0或1或2]
当我用上面的模型预测时,我得到了非常糟糕的准确率(50-70%的准确率)
似乎我已经找到了原因——我的模型预测新输入的类为0或2……因此它丢失了所有实际上是类1的记录
有人能给我一个提示吗?我已经读到softmax可能是解决方案……如果是这样,我不明白为什么Tensorflow docu(入门/虹膜分类一章)中描述的3个类有类似的DNN
编辑:我当然对不同的超参数进行了尝试。我可能已经找到了解决方案。类的分布不均匀,例如,50%的对象为类1,40%的对象为类2,且仅