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,)的值
答案 0 :(得分:0)
如果我将标签从1-D更改为2-D,则看不到该错误。
target = list(data['y'])
a = np.array(target)
target = np.reshape(a , (-1,1))