chore(knn): better loading of data

This commit is contained in:
2024-09-27 23:51:44 +08:00
parent a2c3bfaead
commit f9f17867be
+5 -11
View File
@@ -68,16 +68,10 @@ def load_data(file_path):
"""
加载 TSV 格式数据文件。
"""
features = []
labels = []
with open(file_path, "r") as file:
for line in file:
values = line.strip().split("\t")
features.append([float(x) for x in values[:-1]])
labels.append(int(values[-1]))
return np.array(features), np.array(labels)
data = np.loadtxt(file_path, delimiter="\t")
features = data[:, :-1]
labels = data[:, -1].astype(int)
return features, labels
def upload_score(name, id, score_data):
@@ -168,6 +162,6 @@ if __name__ == "__main__":
f"评测出错: {e}",
traceback.format_exc(),
"请检查代码和返回值类型是否正确!",
"本次评测无效!",
"本次评测无效,记录不做提交!",
]
print("\n".join(log_details))