多变量/特征的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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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