简单神经网络值错误-形状未对齐

时间:2019-12-11 09:29:16

标签: python numpy neural-network

对此我是菜鸟,但我开始学习神经网络。 我想用PythonNumpy做简单的NN。我已经看了一个关于Youtube的教程,但是我做的一切都一样,但是我得到一个错误:

    output = sigmoid(np.dot(input_layer, weights))
ValueError: shapes (13,3) and (13,1) not aligned: 3 (dim 1) != 13 (dim 0)

我知道我的输出数组应该看起来像一维数组,但是由于某种原因我无法做到这一点。 我在做什么错

import numpy as np
import pandas as pd

df = pd.DataFrame({'input 1':[0.5, 0.3, 0, 0.1, 0.4, -0.4, 0.4, -0.1, -0.6, 0.2, 0.6, 0, 0.2],
                   'input 2':[0.3, 0.5, -0.4, -0.2, 0.9, 0, 0.35, -0.4, -0.9, 0.4, 0.3, -0.1, 0.1],
                   'input 3':[0, 0.4, 0, -0.1, 0.4, -0.2, 0.4, -0.3, -0.1, 0.1, 0.3, 0, 0.5],
                   'result':[1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1]})

print(df)

def sigmoid(x):

    return 1 / (1 + np.exp(-x))

features = np.array(df.iloc[:,:-1])
results =  np.array(df.iloc[:,-1:]).T

np.random.seed(10)

weights = 2 * np.random.random((13,1)) - 1

print('These are my random weights:\n')
print(weights)


for iteration in range(1):

    input_layer = features

    output = sigmoid(np.dot(input_layer, weights))

print('\nOutput result:\n', output)

1 个答案:

答案 0 :(得分:0)

我设法找到了结果:

$.ajax({
  url: example/foler,
  data: data,
  success: success(data)
});

function success(data) {
  // data = <div id='paypal-button-container'></div>
  paypal.Buttons().render('#paypal-button-container');

  // Display "Button Loading..."
  // Find out if button has completely rendered, then turn off "button loading..."
}