上传文件至 /
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 29s

This commit is contained in:
2024-11-03 15:40:49 +08:00
parent 91bd1b7c8b
commit aef68edb20
+4 -4
View File
@@ -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)