diff --git a/function.py b/function.py index 08e4711..bc95f6b 100644 --- a/function.py +++ b/function.py @@ -78,7 +78,7 @@ def train_logreg(X, y, learning_rate=0.01, num_iterations=1000, regularization_s return weights -# 对率回归预测函数 +# 使用 0.4 阈值的对率回归预测函数 def predict_logreg(inX, weights): """ 对率回归预测函数。 @@ -91,7 +91,7 @@ def predict_logreg(inX, weights): - int: 预测的分类标签。 """ probability = 1 / (1 + np.exp(-np.dot(inX, weights))) - return 1 if probability >= 0.5 else 0 + return 1 if probability >= 0.4 else 0 if __name__ == "__main__": # 以下代码可用于测试,可自行随意修改