From 5a49015693a7eaa539457b7780affac4fe59bc61 Mon Sep 17 00:00:00 2001 From: cy <939601402@qq.com> Date: Tue, 1 Oct 2024 20:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20function.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/function.py b/function.py index fe9aea6..6871bda 100644 --- a/function.py +++ b/function.py @@ -2,6 +2,7 @@ import numpy as np from collections import Counter from scipy.spatial import distance +from sklearn.preprocessing import StandardScaler """ 挑战说明: @@ -87,6 +88,11 @@ if __name__ == "__main__": train_data, train_labels = load_data(train_file) test_data, test_labels = load_data(test_file) + # 特征缩放 + scaler = StandardScaler() + train_data = scaler.fit_transform(train_data) + test_data = scaler.transform(test_data) + # 测试 classify0 函数 test_sample = test_data[0] # 使用测试集中的第一个样本进行测试 predicted_label = classify0(test_sample, train_data, train_labels)