From dbf4359cec55473e962f15c1f89a699f530c61d7 Mon Sep 17 00:00:00 2001 From: cy <939601402@qq.com> Date: Sun, 20 Oct 2024 14:25:33 +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 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/function.py b/function.py index 6fe9eba..d7454b6 100644 --- a/function.py +++ b/function.py @@ -1,6 +1,5 @@ import numpy as np import os -from sklearn.preprocessing import StandardScaler """ @@ -103,8 +102,14 @@ def load_dataset(directory): labels.append(label) data_set.append(img_to_vector(os.path.join(root, file))) data_set = np.array(data_set).reshape(len(data_set), - 1) - scaler = StandardScaler() - data_set = scaler.fit_transform(data_set) + + # 找到数据集中的最大值和最小值 + data_min = np.min(data_set) + data_max = np.max(data_set) + + # 归一化数据 + data_set = (data_set - data_min) / (data_max - data_min) + return data_set, np.array(labels)