From aef68edb207342f1b989d425efb9128877be32db Mon Sep 17 00:00:00 2001 From: 202210423104 <1961532386@qq.com> Date: Sun, 3 Nov 2024 15:40:49 +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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/function.py b/function.py index 956ebcf..d62464f 100644 --- a/function.py +++ b/function.py @@ -30,12 +30,12 @@ def preprocess_data(X): X_poly = poly.fit_transform(X_standardized) return X_poly -def train_random_forest(X, y): +def train_logreg(X, y): model = RandomForestClassifier(n_estimators=113, max_depth=10, random_state=42) model.fit(X, y) return model -def predict(model, X): +def predict_logreg(model, X): return model.predict(X) if __name__ == "__main__": @@ -51,14 +51,14 @@ if __name__ == "__main__": X_test_processed = preprocess_data(X_test) # 训练模型 - model = train_random_forest(X_train_processed, y_train) + model = train_logreg(X_train_processed, y_train) # 交叉验证 cv_scores = cross_val_score(model, X_train_processed, y_train, cv=5) print(f"交叉验证准确率: {np.mean(cv_scores) * 100:.2f}%") # 预测 - y_pred = predict(model, X_test_processed) + y_pred = predict_logreg(model, X_test_processed) # 计算正确率 accuracy = np.mean(y_pred == y_test)