python numpy:ValueError:shapes(14,)和(404,14)未对齐:14(dim 0)!=404(尺寸0)

python numpy:ValueError:shapes(14,)和(404,14)未对齐:14(dim 0)!=404(尺寸0),python,numpy,machine-learning,scikit-learn,regression,Python,Numpy,Machine Learning,Scikit Learn,Regression,我试图实现局部加权最小二乘法,我得到了这个结果 b = np.array([np.sum(weights.T.dot(y_train.T)), np.sum(weights.T.dot(y_train.T).dot(x_train))]) ValueError: shapes (14,) and (404,14) not aligned: 14 (dim 0) != 404 (dim 0) 我试过换位,但还是不起作用 x_列为(404,14)矩阵,y具有形状(404,),测试_基准具有形状(

我试图实现局部加权最小二乘法,我得到了这个结果

 b = np.array([np.sum(weights.T.dot(y_train.T)), np.sum(weights.T.dot(y_train.T).dot(x_train))])
ValueError: shapes (14,) and (404,14) not aligned: 14 (dim 0) != 404 (dim 0)
我试过换位,但还是不起作用 x_列为(404,14)矩阵,y具有形状(404,),测试_基准具有形状(14,1)

我正在使用boston housing数据集并以这种方式加载它

from sklearn.datasets import load_boston
boston = load_boston()
x = boston['data']
N = x.shape[0]
x = np.concatenate((np.ones((506,1)),x),axis=1)  # add constant one feature - no bias needed
d = x.shape[1]
y = boston['target']

哪一行导致该错误,请包含格式为代码的回溯。当代码依赖于数据时,您还应该包含一个最小的数据示例—刚好能够重现问题。请阅读。。。在
np.点(A,B)
A
的最后一个dim必须与
B
中的第二个到最后一个匹配。
(14,)和(404,14)
数组的顺序错误。您需要查看
np.dot
文档。
from sklearn.datasets import load_boston
boston = load_boston()
x = boston['data']
N = x.shape[0]
x = np.concatenate((np.ones((506,1)),x),axis=1)  # add constant one feature - no bias needed
d = x.shape[1]
y = boston['target']