多变量/特征的Tensorflow

我想使用多层Keras来对人的身高进行分类,如果身高超过170应该返回1,而低于170则返回0

data_input = [[0,165], [0,166], [0,167], [0,172], [0,173]]data_output = [0,0,0,1,1]model = keras.Sequential([  keras.layers.Flatten(input_shape=(1,)),  keras.layers.Dense(2, activation=tf.nn.relu),  keras.layers.Dense(2, activation=tf.nn.softmax)])model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])model.fit(data_input, data_output, epochs=5)predictions = model.predict([0,184])print(predictions)

但它给了我一个错误“ValueError: Input arrays should have the same number of samples as target arrays. Found 2 input samples and 5 target samples.”


回答:

你应该使用Numpy来包装你的输入

data_input = np.array(data_input).reshape(5 ,2)data_output = np.array(data_output).reshape(5)

顺便问一下,为什么你要用机器学习来处理这样一个简单的条件分类问题?

Related Posts

在使用k近邻算法时,有没有办法获取被使用的“邻居”?

我想找到一种方法来确定在我的knn算法中实际使用了哪些…

Theano在Google Colab上无法启用GPU支持

我在尝试使用Theano库训练一个模型。由于我的电脑内…

准确性评分似乎有误

这里是代码: from sklearn.metrics…

Keras Functional API: “错误检查输入时:期望input_1具有4个维度,但得到形状为(X, Y)的数组”

我在尝试使用Keras的fit_generator来训…

如何使用sklearn.datasets.make_classification在指定范围内生成合成数据?

我想为分类问题创建合成数据。我使用了sklearn.d…

如何处理预测时不在训练集中的标签

已关闭。 此问题与编程或软件开发无关。目前不接受回答。…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注