diff --git a/function.py b/function.py index a6761cd..963c095 100644 --- a/function.py +++ b/function.py @@ -50,10 +50,21 @@ def train_logreg(X, y, learning_rate=0.01, iterations=1000, regularization=0.0): return weights, bias -def predict_logreg(inX, weights): +def predict_logreg(inX, weights, bias): + # 确保 inX 是一维数组 + if inX.ndim == 2 and inX.shape[1] == 1: + inX = inX.flatten() + elif inX.ndim > 1: + raise ValueError("Input data should be one-dimensional or a column vector.") + + # 计算线性输出 linear_output = np.dot(inX, weights) + bias - y_predicted = 1 if linear_output >= 0 else 0 # 简化判断条件,因为逻辑回归输出已经通过sigmoid函数处理 - return y_predicted + + # 应用sigmoid函数(如果需要的话) + # sigmoid_output = 1 / (1 + np.exp(-linear_output)) + + # 这里可以返回线性输出或sigmoid输出,取决于您的需求 + return linear_output # 这里也写自己的代码实现 def load_data(filepath):