From 495a83db7c2c12717f986f7d57538d9f38328a95 Mon Sep 17 00:00:00 2001 From: 202210423104 <1961532386@qq.com> Date: Sun, 3 Nov 2024 16:05:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/function.py b/function.py index eb0c449..7a87984 100644 --- a/function.py +++ b/function.py @@ -36,7 +36,10 @@ def train_logreg(X, y): return model # 返回训练好的模型 def predict_logreg(model, X): - X_processed = preprocess_data(X.reshape(1, -1)) # 预处理测试数据 + # 确保输入数据是一个 numpy 数组 + if len(X.shape) == 1: + X = X.reshape(1, -1) # 保持输入数据的形状为 (1, n),符合模型的输入要求 + X_processed = preprocess_data(X) # 预处理测试数据 return model.predict(X_processed)[0] # 确保 model 是训练好的模型 if __name__ == "__main__":