generated from LufsX/Challenge-kNN
This commit is contained in:
+8
-2
@@ -80,8 +80,14 @@ def load_data(file_path):
|
||||
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)
|
||||
features = np.array(features)
|
||||
labels = np.array(labels)
|
||||
|
||||
# 归一化特征值
|
||||
scaler = StandardScaler()
|
||||
features_scaled = scaler.fit_transform(features)
|
||||
|
||||
return features_scaled, labels, scaler # 返回归一化后的特征和缩放器对象
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user