Shaping data for linear regression with TFlearn

爱⌒轻易说出口 提交于 2019-12-07 00:09:26

I tried to do the same. I made these changes to get it to work

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

My guess is that with features >1 you cannot use tflearn.single_unit(). You can add additional fully_connected layers, but the last one must have only 1 neuron because Y.shape=(?,1)

You have 21 features. Therefore, you cannot use linear = tflearn.single_unit(input_)

Instead try this: linear = tflearn.fully_connected(input_, 21, activation='linear')

The error you get is because your labels, i.e., Y has a shape of (1054,). You have to first preprocess it.

Try using the code given below before # linear regression graph:

Y = np.expand_dims(Y,-1)

Now before regression = tflearn.regression(linear, optimizer='sgd', loss='mean_square',metric='R2', learning_rate=0.01), type the below code:

linear = tflearn.fully_connected(linear, 1, activation='linear')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!