From c629ff80706343e175d4960cbca54e81d8e00840 Mon Sep 17 00:00:00 2001 From: 202210423104 <1961532386@qq.com> Date: Sun, 3 Nov 2024 15:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/function.py b/function.py index 23c855a..5dbac91 100644 --- a/function.py +++ b/function.py @@ -18,7 +18,6 @@ def load_data(filepath): data = np.array(data) data = np.nan_to_num(data, nan=np.nanmean(data, axis=0)) - # 这里需要根据具体数据格式调整 X = data[:, :-1] # 特征 y = data[:, -1] # 标签 return X, y @@ -33,12 +32,12 @@ def preprocess_data(X): def train_logreg(X, y): model = RandomForestClassifier(n_estimators=113, max_depth=10, random_state=42) model.fit(X, y) - return model + return model # 返回训练好的模型 def predict_logreg(model, X): - # X 应该是一个单独的样本,确保它的形状是 (1, n_features) - return model.predict(X.reshape(1, -1))[0] + return model.predict(X.reshape(1, -1))[0] # 确保 model 是训练好的模型 if __name__ == "__main__": X, y = load_data("./data/horse-colic.data") + # 这里可能需要确保调用和处理的逻辑符合你的数据处理需求