【问题标题】:ValueError: Cannot feed value of shape (10,) for Tensor 'TargetsData/Y:0', which has shape '(?, 1)'ValueError:无法为具有形状“(?,1)”的张量“TargetsData/Y:0”提供形状(10,)的值
【发布时间】:2018-07-20 18:26:33
【问题描述】:
import os
import json
import datetime
import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.formula.api as sm

import tflearn
import tensorflow as tf 

data = pd.read_csv("line.csv")

data.columns = ['total', 'saved', 'lines' , 'inv']
target = list(data['saved'])


#function filter out the columns we wont be using to train the machine 
def preprocess(data, columns_to_ignore):
    data = data.drop(columns=columns_to_ignore)
    return data 

ignore = ['saved' , 'inv']

data = preprocess(data, ignore)

train = [list(l) for l in zip(data['total'], data['lines'])]

# Build neural network
net = tflearn.input_data(shape=[None, 2])
net = tflearn.fully_connected(net, 16)
net = tflearn.fully_connected(net, 16)
net = tflearn.fully_connected(net, 1, activation='softmax')
net = tflearn.regression(net)

# Training Neural Network
model = tflearn.DNN(net)

# Start Training using tensorflow gradient descent algorithim 
model = model.fit(train, target, n_epoch=10, batch_size=10, show_metric=True)

我一直遇到这个错误。我认为形状应该是: None , 2 因为程序中有 2 个功能。 csv 文件有 4 个特征。其中一个被过滤掉了。一个被读取为目标。我应该怎么做才能摆脱这个错误?

ValueError: 无法为形状为“(?, 1)”的张量“TargetsData/Y:0”提供形状 (10,) 的值

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    如果我将标签从 1-D 更改为 2-D,我不会看到该错误。

    target = list(data['y'])
    a = np.array(target)
    target = np.reshape(a , (-1,1))
    

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 2018-08-03
      • 2020-03-27
      • 2019-09-22
      相关资源
      最近更新 更多