0
剛學習機器學習和tflearn/tensorflow試圖按照tflearn(泰坦之一)的快速入門教程。Python Tflearn - ValueError:無法爲Tensor u'InputData/X:0'提供形狀爲(',2)'的形狀(16,1)的值'
修改它來滿足我的需要我得到這個代碼:
from __future__ import print_function
import numpy as np
import tflearn
# Load CSV file, indicate that the first column represents labels
from tflearn.data_utils import load_csv
data, labels = load_csv('nowcastScaled.csv', target_column=1, n_classes=2)
# Preprocessing function
def preprocess(data):
return np.array(data, dtype=np.float32)
# Preprocess data
data = preprocess(data)
# Build neural network
net = tflearn.input_data(shape=[None, 2])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,
loss='categorical_crossentropy')
# Define model
model = tflearn.DNN(net)
# Start training (apply gradient descent algorithm)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)
但我得到這個錯誤:
ValueError: Cannot feed value of shape (16, 1) for Tensor u'InputData/X:0', which has shape '(?, 2)'
我的CSV文件由2列,一個是指數(因爲這只是一次測試,我只限於100次輸入),另一次是擁塞分數(我試圖預測的是0到200之間),兩者都是數值。
我有點明白,我試圖給它一個不好的價值(或至少是他沒有等待的東西),但我看不出如何糾正它。