我收到以下错误...
ValueError:无法为Tensor' TargetsData / Y:0'提供形状值(16,),它具有形状'(?,16)'
我知道这与我的Y
变量的形状有关,在这种情况下变量labels
,但我不确定如何更改形状以使我的形状变为CSV
模特的工作。
基本上,我有一个pandas
文件,我使用data = pd.read_csv('Speed Dating Data.csv')
保存到变量中...
# Target label used for training
labels = np.array(data["age"], dtype=np.float32)
经过一些预处理,我决定提取我的目标类......
data
接下来,我从# Data for training minus the target label.
data = np.array(data.drop("age", axis=1), dtype=np.float32)
变量...
net = tflearn.input_data(shape=[None, 32])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 16, activation='softmax')
net = tflearn.regression(net)
# Define model.
model = tflearn.DNN(net)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)
然后我决定设置我的模型......
labels
如果我运行这个,我会得到上面的错误。由于我的(16,)
似乎是(?, 16)
,但我需要labels = labels[np.newaxis, :]
,我尝试了以下代码......
labels
但这又给出了另一个错误。我想我不确定我的目标类int p = 0, r = SEIZE-1, i, j, k;
int q = (p + r)/2;
int n1 = q-p+1, n2 = r-q;
float A[SEIZE] = { 125.6, 67.2, 3.21, 422, 54, 87 }, L[n1], R[n2];
printf("{ ");
for( k = 0 ; k < SEIZE ; k++ ){
printf("%.1f ", A[k]);
}
printf(" }\n");
for( i = 0 ; i < n1 ; i++ ){
L[i] = A[p+i];
}
for( j = 0 ; j < n2 ; j++ ){
R[j] = A[q+j+1];
}
L[n1] = '\0';
R[n2] = '\0';
i = 0;
j = 0;
for( k = p ; k <= r; k++ ){
if( L[i] <= R[j] ){
A[k] = L[i];
i = i+1;
}
else{
A[k] = R[j];
j = j+1;
}
}
printf("{ ");
for( k = 0 ; k < SEIZE ; k++ ){
printf("%.1f ", A[k]);
}
printf(" }\n");
应该是什么形式。我该如何解决这个问题?
答案 0 :(得分:1)
根据以下内容重塑标签,
label= np.reshape(label,(-1,16)) # since you have 16 classes
将标签重塑为(?,16)。
希望这有帮助。
根据您的要求进行了更新。并为更改添加了评论。
labels = np.array(data["age"], dtype=np.float32)
label= np.reshape(label,(-1,1)) #reshape to [6605,1]
data = np.array(data.drop("age", axis=1), dtype=np.float32)
net = tflearn.input_data(shape=[None, 32])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 1, activation='softmax') #Since this is a regression problem only one output
net = tflearn.regression(net)
# Define model.
model = tflearn.DNN(net)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)