本人在构建预测网店销售额的模型的最后一步中遇到问题,查错显示value error :operands could not be broadcast together with shape (3, ) (4, ),知道原因,但不知道怎么修改,从哪里下手,还请高人为小辈指点迷津,感激不尽!
报错代码如图所示:
ValueError: operands could not be broadcast together with shapes (3,)(4,)说明在计算np.dot()的点积时,X_plan的形状(3,)与weight_history的形状(4,)不匹配。
可以考虑以下几种方法来解决这个问题:
将X_plan转换为与weight_history相同的形状,例如:
X_plan = np.array(X_plan)
X_plan = np.reshape(X_plan, (len(X_plan), 1))
将weight_history转换为与X_plan相同的形状,例如:
weight_history = np.array(weight_history)
weight_history = np.reshape(weight_history, (1, len(weight_history)))
请确保执行的操作与您的代码适合。最后,请检查其他函数(例如scaler())是否有任何影响,并进行必要的修改。
该错误是由于数组大小不同引起的,在你的代码中,数组X_train 和 X_plan 大小不同。你可以检查两个数组的大小,并确保它们具有相同的大小。您可以通过在代码中添加以下行来解决此问题;
print(X_train.shape)
print(X_plan.shape)