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

This commit is contained in:
2024-11-03 05:28:43 +08:00
parent 869fa30e79
commit 5c774e66d3
-33
View File
@@ -26,16 +26,6 @@ name = "刘义天"
def load_data(filepath):
"""
从文件中加载数据,若不自行正确实现,则无法通过评测,**不记录成绩**
Args:
- filepath (str): 数据文件路径
Returns:
- X (numpy array): 特征数据
- y (numpy array): 标签数据
"""
data = []
with open(filepath, 'r') as file:
for line in file:
@@ -54,19 +44,6 @@ def load_data(filepath):
def train_logreg(X, y, learning_rate=0.1, n_estimators=200, max_depth=5):
"""
对率回归训练函数。
Args:
- X (numpy array): 特征数据。
- y (numpy array): 标签数据。
- learning_rate (float): 学习率。
- num_iterations (int): 迭代次数。
- regularization_strength (float): 正则化强度。
Returns:
- weights (numpy array): 训练得到的权重。
"""
scaler = StandardScaler()
X = scaler.fit_transform(X)
@@ -81,16 +58,6 @@ def train_logreg(X, y, learning_rate=0.1, n_estimators=200, max_depth=5):
def predict_logreg(inX, model, scaler):
"""
对率回归预测函数。
Args:
- inX (numpy array): 输入待分类的样本。
- weights (numpy array): 训练得到的权重。
Returns:
- int: 预测的分类标签。
"""
inX = scaler.transform([inX])
prediction = model.predict(inX)
return int(prediction[0])