python - 如何根据python中的权重和偏差获取预测值
问题描述
我正在尝试使用 predict() 函数使用 X_trainT 和 X_testT 预测测试和训练数据的输出。我收到以下列出的错误 -
yPredTrain = predict(X_trainT, parameters)
yPredTest = predict(X_testT, parameters) # This function is throwing the error
预测功能
def predict(X, parameters):
W = parameters["W"]
b = parameters["b"]
W = W.reshape(X.shape[0], 1)
#Z = np.dot(W.T,X) + b
Z = np.dot(W.T,X) + b
Y = np.array([1 if y > 0.5 else 0 for y in sigmoid(Z[0])]).reshape(1,len(Z[0]))
#Y = np.array([1 if y > 0.5 else 0 for y in Z[0]]).reshape(1,len(Z[0]))
return Y
错误
ValueError Traceback (most recent call last)
<ipython-input-20-a5c2d40ef32d> in <module>()
1 yPredTrain = predict(X_trainT, parameters)
----> 2 yPredTest = predict(X_testT, parameters)
<ipython-input-9-dfb2f70a0c07> in predict(X, parameters)
4 W = W.reshape(X.shape[0], 1)
5 #Z = np.dot(W.T,X) + b
----> 6 Z = np.dot(W.T,X) + b
7 Y = np.array([1 if y > 0.5 else 0 for y in sigmoid(Z[0])]).reshape(1,len(Z[0]))
8 #Y = np.array([1 if y > 0.5 else 0 for y in Z[0]]).reshape(1,len(Z[0]))
ValueError: operands could not be broadcast together with shapes (1,143) (426,) ```
解决方案
推荐阅读
- azure-cognitive-search - 如何使用 Azure 认知搜索连接元数据和原始数据?
- conda - 无法使用 python 3.10 设置 conda 环境
- terraform - Terraform,创建可选的地图列表
- c++ - 使用函数创建评分系统
- postgresql - 如何从每个元素json数组postgres中删除字段?
- python - Python:最大化两个字节数组的比较性能
- javascript - JavaScript 递归 setTimeout 范围
- c# - 迁移到 .net 核心后,FromBody 值不会覆盖默认参数值
- ios - HERE SDK Lite iOS 在初始化期间进入后台后崩溃
- c++ - libcurl C++:检查网页是否已更新时要听哪些参数?