2017-06-26 53 views
1

我試圖通過增加列數到21整形數據

from trafficdata import X,Y 

import tflearn 

print(X.shape) #(1054, 21) 
print(Y.shape) #(1054,) 

# Linear Regression graph 
input_ = tflearn.input_data(shape=[None,21]) 
linear = tflearn.single_unit(input_) 
regression = tflearn.regression(linear, optimizer='sgd', loss='mean_square', 
           metric='R2', learning_rate=0.01) 
m = tflearn.DNN(regression) 
m.fit(X, Y, n_epoch=1000, show_metric=True, snapshot_epoch=False) 

print("\nRegression result:") 
print("Y = " + str(m.get_weights(linear.W)) + 
     "*X + " + str(m.get_weights(linear.b))) 

然而擴大the tflearn example for linear regression,tflearn抱怨:

Traceback (most recent call last): 
    File "linearregression.py", line 16, in <module> 
    m.fit(X, Y, n_epoch=1000, show_metric=True, snapshot_epoch=False) 
    File "/usr/local/lib/python3.5/dist-packages/tflearn/models/dnn.py", line 216, in fit 
    callbacks=callbacks) 
    File "/usr/local/lib/python3.5/dist-packages/tflearn/helpers/trainer.py", line 339, in fit 
    show_metric) 
    File "/usr/local/lib/python3.5/dist-packages/tflearn/helpers/trainer.py", line 818, in _train 
    feed_batch) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 789, in run 
    run_metadata_ptr) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 975, in _run 
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) 
ValueError: Cannot feed value of shape (64,) for Tensor 'TargetsData/Y:0', which has shape '(21,)' 

我發現的形狀( )來自tflearn.regression()的默認批量大小。

是否需要轉換標籤(Y)?以什麼方式?

謝謝!

回答

0

我試圖做同樣的事情。我做了這些改變,以得到它的工作

# linear = tflearn.single_unit(input_) 
linear = tflearn.fully_connected(input_, 1, activation='linear') 

我的猜測是,隨着功能> 1,則不能使用tflearn.single_unit()。您可以添加額外的完全連接圖層,但最後一個圖層只能有1個神經元,因爲Y.shape =(?, 1)