我正在尝试使用Tensorflow编写一个相当简单的分类器。分类器将采用128个元素向量并输出2个类别的响应。
以下是代码:
import tensorflow as tf
import numpy as np
import pandas
import time
# Data sets
TRAINING = "james/data/tensorflow/matching/training.csv"
TEST = "james/data/tensorflow/matching/testing.csv"
# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv_with_header(
filename=TRAINING,
target_dtype=np.int,
features_dtype=np.float32
)
test_set = tf.contrib.learn.datasets.base.load_csv_with_header(
filename=TEST,
target_dtype=np.int,
features_dtype=np.float32)
# Specify that all features have real-value data
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=128)]
# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
hidden_units=[256,128,64, 32, 8],
n_classes=2,
)
print(training_set.target)
print(training_set.data)
# Fit model.
classifier.fit(x=training_set.data,
y=training_set.target,
max_steps=10000
)
该代码完全基于Tensorflow网站上的代码。
我可以看到training_set.data
和training_set.target
都已正确解析。
在分类器阶段,我收到错误:
ValueError Traceback (most recent call last)
ipython-input-9-aae84e4745a3 in module()
35 classifier.fit(x=training_set.data,
36 y=training_set.target,
---> 37 max_steps=10000
38 )
39
我也在跟踪底部出现错误:
ValueError: Shapes (?, 1) and (?,) are incompatible
我正在使用IPython Notebook进行编程,安装了最新的TensorFlow库(昨晚每晚构建)。