更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 30s

This commit is contained in:
2024-11-03 16:12:19 +08:00
parent 56eb877c82
commit 3dccf5168e
+6 -3
View File
@@ -1,5 +1,4 @@
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
@@ -36,7 +35,9 @@ def train_logreg(X, y):
return model
def predict_logreg(model, X):
return model.predict(X)
# 确保传入的是训练好的模型
X_processed = preprocess_data(X.reshape(1, -1)) # 将单个样本重塑并预处理
return model.predict(X_processed)[0] # 预测并返回结果
if __name__ == "__main__":
# 加载数据
@@ -53,7 +54,9 @@ if __name__ == "__main__":
model = train_logreg(X_train_processed, y_train)
# 预测
y_pred = predict_logreg(model, X_test_processed)
y_pred = []
for sample in X_test:
y_pred.append(predict_logreg(model, sample))
# 计算正确率
accuracy = np.mean(y_pred == y_test)