Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tensorflow:将n“U类更改为2个收益率”;ValueError:形状(?,1)和(?,)不兼容&引用;_Python_Machine Learning_Neural Network_Tensorflow_Python 3.4 - Fatal编程技术网

Python tensorflow:将n“U类更改为2个收益率”;ValueError:形状(?,1)和(?,)不兼容&引用;

Python tensorflow:将n“U类更改为2个收益率”;ValueError:形状(?,1)和(?,)不兼容&引用;,python,machine-learning,neural-network,tensorflow,python-3.4,Python,Machine Learning,Neural Network,Tensorflow,Python 3.4,我在教程中使用了我自己的数据。他们使用Iris数据集;我有我自己的数据,这是虚构的,但它应该仍然有效。我收到一个不兼容的形状错误 错误: Traceback (most recent call last): File "./kidTraining_stripped.py", line 36, in <module> classifier.fit(x = training_set.data, y = training_set.target, steps = 2000) #####

我在教程中使用了我自己的数据。他们使用Iris数据集;我有我自己的数据,这是虚构的,但它应该仍然有效。我收到一个不兼容的形状错误

错误:

Traceback (most recent call last):
  File "./kidTraining_stripped.py", line 36, in <module>
classifier.fit(x = training_set.data, y = training_set.target, steps = 2000)  ########## THROWS UP HERE.
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py", line 435, in fit
max_steps=max_steps)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 333, in fit
max_steps=max_steps)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 662, in _train_model
train_op, loss_op = self._get_train_ops(features, targets)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 963, in _get_train_ops
_, loss, train_op = self._call_model_fn(features, targets, ModeKeys.TRAIN)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 944, in _call_model_fn
return self._model_fn(features, targets, mode=mode, params=self.params)
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py", line 258, in _dnn_classifier_model_fn
weight=_get_weight_tensor(features, weight_column_name))
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/contrib/losses/python/losses/loss_ops.py", line 329, in sigmoid_cross_entropy
logits.get_shape().assert_is_compatible_with(multi_class_labels.get_shape())
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_shape.py", line 750, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (?, 1) and (?,) are incompatible
这些数据在我看来并不好笑;我已经把它拆分成4列,使浮点数只有2个小数点长,等等,尝试重塑张量,但似乎没有任何效果。当我在到达classifier.fit之前打印出形状时,它们看起来是兼容的,(18,11)和(18,)。但是当我运行fit函数时,错误显示形状是?。当我粘贴数据时,它变得不可理解,但举个例子,这里是训练数据的前3行:

18.11新界区建筑署

0 132 1 15.28333 2.66667 3.48333 2.26667 3.33333 1.2 0.98333 1.35 0

0 138 19.95 1.25 2.73333 0.83333 1.95 0.83333 1 1.35 0

有18行数据,只有2个类和11列(不包括末尾的标签)。测试数据类似,只有我只有6个样本,所以第一行的第一列包含6个样本

怎么了?我需要不同形状的数据吗?我需要重塑它吗?根据我的输入数据,程序中是否有不正确的条目?希望有人能帮忙

=======
编辑:我知道这与n_课程有关;它似乎接受任何大于2的值,除了我只有2个类,所以我希望我的模型实际使用正确的参数

似乎是一只虫子。你能检查一下是否有帮助的解决方法吗?呃,是的,看起来是相同的错误。我所做的是将n_类改为3类,这也是klpickrell的建议。谢谢你的链接。有没有一种方法可以帮你判断正确?如果你想试试的话,我想另一种解决方案是升级到最近的版本。在短期内可能会比它的价值更麻烦。实际上,我有点害怕从Git的主分支中提取一个过渡。我宁愿升级到一个真正的版本。似乎是一个bug。你能检查一下是否有帮助的解决方法吗?呃,是的,看起来是相同的错误。我所做的是将n_类改为3类,这也是klpickrell的建议。谢谢你的链接。有没有一种方法可以帮你判断正确?如果你想试试的话,我想另一种解决方案是升级到最近的版本。在短期内可能会比它的价值更麻烦。实际上,我有点害怕从Git的主分支中提取一个过渡。我宁愿升级到“真正的”版本。
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import numpy as np

# Data sets
KID_TRAINING = "kid_data_training_nn.csv"
KID_TEST = "kid_data_test_nn.csv"

# load datasets
training_set = tf.contrib.learn.datasets.base.load_csv_with_header(filename = KID_TRAINING, target_dtype = np.int, features_dtype=np.float32)

test_set = tf.contrib.learn.datasets.base.load_csv_with_header(filename=KID_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=11)]

# build 3 layer DNN with 10, 20, 10 units respectively
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns, hidden_units=[10, 20, 10], n_classes=2, model_dir="./kid_model")

# Fit model
print("It blows up here, so this is x and y:")
print(training_set.data)
print(training_set.data.dtype)
print(training_set.data.shape)

# (18, 11)

print(training_set.target)
print(training_set.target.dtype)
print(training_set.target.shape)
# (18,)

classifier.fit(x = training_set.data, y = training_set.target, steps = 2000)  ########## THROWS UP HERE.