[英]How to model data for tensorflow?
我有以下形式的數據:
A B C D E F G
1 0 0 1 0 0 1
1 0 0 1 0 0 1
1 0 0 1 0 1 0
1 0 1 0 1 0 0
...
1 0 1 0 1 0 0
0 1 1 0 0 0 1
0 1 1 0 0 0 1
0 1 0 1 1 0 0
0 1 0 1 1 0 0
A,B,C,D
是我的輸入, E,F,G
是我的輸出。 我使用TensorFlow在Python中編寫了以下代碼:
from __future__ import print_function
#from random import randint
import numpy as np
import tflearn
import pandas as pd
data,labels =tflearn.data_utils.load_csv('dummy_data.csv',target_column=-1,categorical_labels=False, n_classes=None)
print(data)
# Build neural network
net = tflearn.input_data(shape=[None, 4])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 3, activation='softmax')
net = tflearn.regression(net)
# Define model
model = tflearn.DNN(net)
#Start training (apply gradient descent algorithm)
data_to_array = np.asarray(data)
print(data_to_array.shape)
#data_to_array= data_to_array.reshape(6,9)
print(data_to_array.shape)
model.fit(data_to_array, labels, n_epoch=10, batch_size=3, show_metric=True)
我收到的錯誤是:
ValueError:無法為
'InputData/X:0'
提供形狀值(3, 6)
,其形狀為'(?, 4)'
我猜這是因為我的輸入數據有7列(0 ... 6),但我希望輸入層只將前四列作為輸入,並預測數據中的最后3列作為輸出。 我該如何建模呢?
如果數據采用numpy格式,則前4列采用簡單切片:
data[:,0:4]
:
表示“所有行”, 0:4
是值0,1,2,3
的范圍,前4列。
如果數據不是numpy格式,只需將其轉換為numpy格式,以便您可以輕松切片。
這是關於numpy切片的相關文章: Numpy - 從數組中切割2d行或列向量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.