generated from LufsX/Experiment-kNN
This commit is contained in:
+5
-2
@@ -44,7 +44,7 @@ def classify(input_vector, dataSet, labels, k=2):
|
||||
dataSet_size = dataSet.shape[0]
|
||||
# 计算马氏距离
|
||||
cov_matrix = np.cov(dataSet.T)
|
||||
inv_cov_matrix = np.linalg.pinv(cov_matrix)
|
||||
inv_cov_matrix = np.linalg.inv(cov_matrix)
|
||||
diff_mat = np.tile(input_vector, (dataSet_size, 1)) - dataSet
|
||||
distances = []
|
||||
for i in range(dataSet_size):
|
||||
@@ -101,7 +101,10 @@ def load_dataset(directory):
|
||||
label = int(file.split('_')[0])
|
||||
labels.append(label)
|
||||
data_set.append(img_to_vector(os.path.join(root, file)))
|
||||
return np.array(data_set).reshape(len(data_set), -1), np.array(labels)
|
||||
data_set = np.array(data_set).reshape(len(data_set), -1)
|
||||
scaler = StandardScaler()
|
||||
data_set = scaler.fit_transform(data_set)
|
||||
return data_set, np.array(labels)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user