generated from LufsX/Experiment-kNN
This commit is contained in:
@@ -63,7 +63,6 @@ def classify(input_vector, dataSet, labels, k=3):
|
|||||||
predicted_label = np.bincount(nearest_labels).argmax()
|
predicted_label = np.bincount(nearest_labels).argmax()
|
||||||
return predicted_label
|
return predicted_label
|
||||||
|
|
||||||
|
|
||||||
# 这里也写自己的代码实现
|
# 这里也写自己的代码实现
|
||||||
def load_dataset(directory):
|
def load_dataset(directory):
|
||||||
"""
|
"""
|
||||||
@@ -88,7 +87,6 @@ def load_dataset(directory):
|
|||||||
data.append(vector)
|
data.append(vector)
|
||||||
return np.array(data), np.array(labels)
|
return np.array(data), np.array(labels)
|
||||||
|
|
||||||
|
|
||||||
# 这里还写自己的代码实现
|
# 这里还写自己的代码实现
|
||||||
def img_to_vector(filename):
|
def img_to_vector(filename):
|
||||||
"""
|
"""
|
||||||
@@ -126,6 +124,4 @@ if __name__ == "__main__":
|
|||||||
# 打印准确率
|
# 打印准确率
|
||||||
accuracy = correct_count / len(test_data) * 100
|
accuracy = correct_count / len(test_data) * 100
|
||||||
print(f"测试集的准确率: {accuracy:.2f}%")
|
print(f"测试集的准确率: {accuracy:.2f}%")
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user