chore(knn): better loading of data
This commit is contained in:
+5
-11
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user