问题描述
我现在很无助,虽然我找了几天的答案,但找不到合适的。我也看到了,有人问了类似的问题,但我还是找不到解决我的维度问题的方法。
我的目标是预测电影院的票价。我将数据拆分为训练数据和测试数据。 直到“创建神经网络”部分一切顺利。 我是初学者。请帮忙!
ValueError: 形状 (8457,13) 和 (1,) 未对齐:13 (dim 1) != 1 (dim 0)
data_perc= data_filtered.head(int(len(data_filtered)*(10/100)))
y=data_perc.ticket_price
x=data_perc.drop('ticket_price',axis=1) # 1=colums und 0=rows
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
x_train.head()
x_train.shape
inputs = x_train
outputs = y_train
class NeuralNetwork:
# intialize variables in class
def __init__(self,inputs,outputs):
self.inputs = inputs
self.outputs = outputs
# initialize weights as .50 for simplicity
self.weights = np.array([.50])
self.error_history = []
self.epoch_list = []
#activation function ==> S(x) = 1/1+e^(-x)
def sigmoid(self,x,deriv=False):
if deriv == True:
return x * (1 - x)
return 1 / (1 + np.exp(-x))
# data will flow through the neural network.
def Feed_forward(self):
self.hidden = self.sigmoid(np.squeeze(np.dot(self.inputs,self.weights)))
# going backwards through the network to update weights
def backpropagation(self):
self.error = self.outputs - self.hidden
delta = self.error * self.sigmoid(self.hidden,deriv=True)
self.weights += np.dot(self.inputs.T,delta)
# train the neural net for 25,000 iterations
def train(self,epochs=25000):
for epoch in range(epochs):
# flow forward and produce an output
self.Feed_forward()
# go back though the network to make corrections based on the output
self.backpropagation()
# keep track of the error history over each epoch
self.error_history.append(np.average(np.abs(self.error)))
self.epoch_list.append(epoch)
# function to predict output on new and unseen input data
def predict(self,new_input):
prediction = self.sigmoid(np.dot(new_input,self.weights))
return prediction
# create neural network
NN = NeuralNetwork(inputs,outputs)
# train neural network
NN.train()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)