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

This commit is contained in:
hao
2024-11-02 17:10:06 +08:00
parent cb9c33569d
commit e2435a3313
+7 -3
View File
@@ -26,7 +26,7 @@ name = "黎世浩"
# 这里写自己的代码实现
def train_logreg(X, y, random_state="114514"):
def train_logreg(X, y, random_state=114514):
"""
对率回归训练函数。
@@ -38,6 +38,9 @@ def train_logreg(X, y, random_state="114514"):
Returns:
- numpy array: 训练得到的权重。
"""
weights = LogisticRegression(solver="liblinear", random_state=random_state)
weights.fit(X, y)
return weights
def predict_logreg(inX, weights):
@@ -51,6 +54,7 @@ def predict_logreg(inX, weights):
Returns:
- int: 预测的分类标签。
"""
return int(weights.predict([inX])[0])
# 这里也写自己的代码实现
@@ -59,13 +63,13 @@ def load_data(filepath):
从文件中加载数据,若不自行正确实现,则无法通过评测,**不记录成绩**。
Args:
- filepath (str): 数据文件路径。
- directory (str): 数据文件路径。
Returns:
- np.array: 特征数据。
- np.array: 标签数据。
"""
# 使用 np.genfromtxt 加载数据并处理缺失值 '?' 为 0
# 使用 np.genfromtxt 加载数据,处理缺失值 '?' 为 0
data = np.genfromtxt(filepath, delimiter=" ", missing_values="?", filling_values=-1)
# 分离特征标签