3
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 25s

This commit is contained in:
lzh
2024-11-02 20:33:20 +08:00
parent 56f1f9250b
commit 4a7ff9c815
+5 -1
View File
@@ -101,8 +101,12 @@ def predict_logreg(inX, weights):
Returns:
- int: 预测的分类标签。
"""
# 确保输入样本的特征数量与训练时一致
if inX.shape[0] != weights.shape[0] - 1:
raise ValueError("输入样本的特征数量与训练时不一致")
# 添加偏置项
inX = np.c_[np.ones((1, 1)), inX]
inX = np.insert(inX, 0, 1, axis=1) # 在特征向量的开头插入偏置项
z = np.dot(inX, weights)
y_pred = 1 / (1 + np.exp(-z))
return 1 if y_pred > 0.5 else 0