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

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